我试图弄清楚这两个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' )

在一种情况下,信号中的单一频率被清楚地检测到,而在另一种情况下,信号中的单一频率没有被检测到。一个过程比另一个更正确吗?
发布于 2012-12-12 04:01:29
这两个图比你意识到的更相似。请记住,fft返回一个复数组。输入函数的移位也会导致“k-空间”中的相移。因为2*sin(a*pi*x) == i*(exp(i*a*pi*x) - exp(-i*a*pi*x)),s_2的所有功率都在k空间的虚部(注意y轴大约是1e-12的数量级),所以s_1稍微移动了一点,所以你可以在k空间的实部看到一点信号,但大部分功率仍然在虚部。看看当我绘制幅度abs(k空间)而不是只绘制实部时会发生什么(这就是matplotlib在给定复数时似乎所做的事情)。
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, np.abs(fft_1.imag), 'x' )
plt.subplot( 2,1,2 )
plt.plot( freq, np.abs(fft_2.imag), 'x' )

https://stackoverflow.com/questions/13823768
复制相似问题