3
我试图使这两个numpy的傅立叶之间的差异感变换:numpy的FFT稳定性
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')
在一种情况下,在信号的单一频率被清楚地检测到,并在另一个它不是。一个程序比另一个更正确吗?