问题
Some days ago I came across this answer about the usage of the FFT
In the answer there's a piece of code like this:
w = np.fft.fft(data)
freqs = np.fft.fftfreq(len(w))
I read about the function fftfreq in the numpy documentation (here) and i found that it returns an array with the following content:
f = [0, 1, ..., n/2-1, -n/2, ..., -1] / (d*n) if n is even
f = [0, 1, ..., (n-1)/2, -(n-1)/2, ..., -1] / (d*n) if n is odd
In my case, the d var is equal to 1 and n is an even number.
So my question is: what is exactly the aim of fftfreq?
I was wondering if it was a sort of a triangular window function.
回答1:
The returned float array f contains the frequency bin centers in cycles per unit of the sample spacing (with zero at the start). For instance, if the sample spacing is in seconds, then the frequency unit is cycles/second.
fftfreq gives the range of possible frequencies of Fourier Transform.
回答2:
np.fft.fftfreq
try to map the frequency range (y) to a kind of "index" range (x) as the following figure. Note that blue line
-> positive frequency, orange line
-> negative frequency.
来源:https://stackoverflow.com/questions/44758739/meaning-of-the-function-numpy-fft-fftfreq