jakevdp / nfft

Lightweight non-uniform Fast Fourier Transform in Python
MIT License
201 stars 29 forks source link

How to get dominating frequency of the signal #11

Closed cygerts closed 5 years ago

cygerts commented 5 years ago

So my question is how can we get dominating frequency / frequencies from the signal?

That is sth I can achieve with scipy.FFTPACK using code like that: import scipy.fftpack as syfp X = syfp.fft(signal) freqs = syfp.fftfreq(len(signal)) * SamplesPerSecond dominatingFreqId= np.argsort(np.abs(X))[-1] freq = freqs[dominatingFreqId]

How can I achieve that with NFFT, but of course on not equally spaced samples? I.e. it would be nice if I can get the frequency using code sample by jakevdp from this thread: https://github.com/jakevdp/nfft/issues/7

jakevdp commented 5 years ago

You should look into the Lomb-Scargle Periodogram.

jakevdp commented 5 years ago

http://docs.astropy.org/en/stable/stats/lombscargle.html

cygerts commented 5 years ago

Great, many thx. Just wondering, do you have any recommendation what should I use when the signal is evenly spaced? Maybe what I am using (scipy.fftpack) is not optimal in that case?

jakevdp commented 5 years ago

For evenly-spaced signals, a PSD computed with the FFT is the best approach. It's mathematically provable that you cannot do better.

cygerts commented 5 years ago

Great, many thanks. This follow up link may be an useful start to many readers - how to calculate frequency between bins https://stackoverflow.com/questions/41783512/fft-calculating-exact-frequency-between-frequency-bins