I am using the FFT function in NumPy to do some signal processing. I have array called signal
which has one data point for each hour and has a total of 576 data points. I use the following code on signal to look at its fourier transform.
t = len(signal)
ft = fft(signal,n=t)
mgft=abs(ft)
plot(mgft[0:t/2+1])
I see two peaks but I am unsure as to what the units of the x axis are i.e., how they map onto hours? Any help would be appreciated.
Given sampling rate
FSampleand transform blocksizeN, you can calculate the frequency resolutiondeltaF, sampling intervaldeltaT, and total capture timecapTusing the relationships:Keep in mind also that the FFT returns value from
0toFSample, or equivalently-FSample/2toFSample/2. In your plot, you’re already dropping the-FSample/2to0part. NumPy includes a helper function to calculate all this for you: fftfreq.For your values of
deltaT = 1 hourandN = 576, you getdeltaF = 0.001736 cycles/hour = 0.04167 cycles/day, from-0.5 cycles/hourto0.5 cycles/hour. So if you have a magnitude peak at, say, bin 48 (and bin 528), that corresponds to a frequency component at48*deltaF = 0.0833 cycles/hour = 2 cycles/day.In general, you should apply a window function to your time domain data before calculating the FFT, to reduce spectral leakage. The Hann window is almost never a bad choice. You can also use the
rfftfunction to skip the-FSample/2, 0part of the output. So then, your code would be: