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')
在一種情況下,在信號的單一頻率被清楚地檢測到,並在另一個它不是。一個程序比另一個更正確嗎?