Reputation: 539
After watching a video on FFT and frequencies, I tried to recreate the example code (as show below), however something went wrong. In the plot you can see that the peak is of by 0.0025 Hz. I don't understand why. The signal is 2*sin(pi*x/8) == 0.0625Hz. However the plot shows 0.0600 Hz.
N = 100
f = lambda x : 2 * np.sin(np.pi * x/8)
X = range(N)
y = [f(x) for x in X]
fft = np.fft.fft(y)
fft_abs = 2*np.abs(fft/N)
freq = np.fft.fftfreq(N)
mask = freq > 0
plot.figure(1)
plot.plot(y)
plot.show()
plot.figure(2)
plot.plot(freq[mask],fft_abs[mask])
plot.show()
Upvotes: 0
Views: 118
Reputation: 11075
This is a simple problem of not enough resolution. With N
of 100, you have time steps of .01, so 0.0625 gets rounded to the nearest hundredth (0.06). If you use a higher number N
(1000 maybe) the time step will be smaller and the better you can calculate the answer. Technically you can pick any even multiple of 16, and it will happen to give the exact value because 1/16 = 0.0625.
Upvotes: 3