I'm looking for how to turn the frequency axis in a fft (taken via scipy.fftpack.fftfreq) into a frequency in Hertz, rather than bins or fractional bins.
I tried to code below to test out the FFT:
t = scipy.linspace(0,120,4000) acc = lambda t: 10*scipy.sin(2*pi*2.0*t) + 5*scipy.sin(2*pi*8.0*t) + 2*scipy.random.random(len(t)) signal = acc(t) FFT = abs(scipy.fft(signal)) FFT = scipy.fftpack.fftshift(FFT) freqs = scipy.fftpack.fftfreq(signal.size) pylab.plot(freqs,FFT,'x') pylab.show()
The sampling rate should be 4000 samples / 120 seconds = 33.34 samples/sec.
The signal has a 2.0 Hz signal, a 8.0 Hz signal, and some random noise.
I take the FFT, grab the frequencies, and plot it. The numbers are pretty nonsensical. If I multiply the frequencies by 33.34 (the sampling frequency), then I get peaks at about 8 Hz and 15 Hz, which seems wrong (also, the frequencies should be a factor of 4 apart, not 2!).
Any thoughts on what I'm doing wrong here?