Frequency units when using FFT in NumPy

I use the FFT function in NumPy to do some signal processing. I have an array called signal that has one data point for every hour and has a total of 576 data points. I use the following code on signal to see 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'm not sure what the units of the x axis are, i.e. How do they display the clock? Any help would be appreciated.

+7
source share
3 answers

Given the sampling rate of FSample and convert blockize N , you can calculate the frequency resolution deltaF , the sampling interval deltaT and the total capture time capT using the ratios:

 deltaT = 1/FSample = capT/N deltaF = 1/capT = FSample/N 

Keep in mind that FFT returns a value from 0 to FSample or equivalently -FSample/2 to FSample/2 . In your plot, you are already dropping the -FSample/2 part to 0 . NumPy includes a helper function to calculate all this for you: fftfreq .

For your deltaT = 1 hour and N = 576 you get deltaF = 0.001736 cycles/hour = 0.04167 cycles/day , from -0.5 cycles/hour to 0.5 cycles/hour . Therefore, if you have a peak in amplitude, for example, in bin 48 (and in hopper 528), which corresponds to the frequency component of 48*deltaF = 0.0833 cycles/hour = 2 cycles/day.

In general, you should apply the window function to the data of your temporary domain before calculating the FFT to reduce spectral leakage . Hannah’s window is almost never a bad choice. You can also use the rfft function to skip the output part of -FSample/2, 0 . So your code will look like this:

 ft = np.fft.rfft(signal*np.hanning(len(signal))) mgft = abs(ft) xVals = np.fft.fftfreq(len(signal), d=1.0) # in hours, or d=1.0/24 in days plot(xVals[:len(mgft)], mgft) 
+11
source

The result of the fft conversion is not displayed on HOURS, but on the frequencies contained in your dataset. It would be helpful to have a transformed graph so that we can see where the peaks are.

You may experience a splash at the beginning of the converted buffer since you did not make any window.

0
source

In general, the dimensional units of the frequency from the FFT are the same as the dimensional units of the sampling rate attributed to the data submitted to the FFT, for example: per meter for each radian per second or, in your case, per hour.

The scaled frequency units by the FFT result index are N / theSampleRate with the same dimensional units as above, where N is the length of the full FFT (you can only make up half this length in the case of strictly real data).

Note that each bit of the peak of the FFT result is a filter with a non-zero bandwidth, so you can add some uncertainty or error margins to the points of the results that you display on the frequency values. Or even use the interpolation estimation method, if necessary and suitable for the source data.

0
source

All Articles