我试图理解这两个 numpy 傅里叶变换之间的区别:
import numpy as np
samples = 256
# define the domain in slightly different ways
t_1 = np.linspace( 0.0, 1.0, samples )
t_2 = np.arange( 0.0, 1.0, 1.0/samples )
## The two domains are not identical, but they're close
print np.sum( (t_1 - t_2) ** 2 )
# 0.0013046364379084878
# simple sin wave
f = lambda t : 2 * np.sin( 2 * 2 * pi * t )
# signals over each domain
s_1 = f( t_1 )
s_2 = f( t_2 )
# fourier transform
fft_1 = np.fft.fft( s_1 )
fft_2 = np.fft.fft( s_2 )
freq = np.fft.fftfreq( samples )
# plot the FFT differences
plt.figure()
plt.subplot( 2,1,1 )
plt.plot( freq, fft_1, 'x' )
plt.subplot( 2,1,2 )
plt.plot( freq, fft_2, 'x' )
在一种情况下,可以清楚地检测到信号中的单一频率,而在另一种情况下则没有。一种程序是否比另一种程序更正确?