Meaning of the function numpy.fft.fftfreq

安稳与你 提交于 2021-02-05 05:52:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!