FFTPeriodicityDetector#
- class pyriodicity.FFTPeriodicityDetector#
Fast Fourier Transform (FFT) based periodicity detector.
Find the periods in a given signal or series using FFT [1].
See also
pyriodicity.OnlineFFTPeriodicityDetectorOnline Fast Fourier Transform (FFT) based periodicity detector.
References
[1]Hyndman, R.J., & Athanasopoulos, G. (2021) Forecasting: principles and practice, 3rd edition, OTexts: Melbourne, Australia. https://OTexts.com/fpp3/useful-predictors.html#fourier-series. Accessed on 09-15-2024.
Examples
Start by loading Mauna Loa Weekly Atmospheric CO2 Data from statsmodels and downsampling its data to a monthly frequency.
>>> from statsmodels.datasets import co2 >>> data = co2.load().data >>> data = data.resample("ME").mean().ffill()
Use
FFTPeriodicityDetectorto find the list of periods using FFT, ordered by corresponding frequency amplitudes in a descending order.>>> from pyriodicity import FFTPeriodicityDetector >>> FFTPeriodicityDetector.detect(data) array([ 12, 6, 175, 44, 132, 88, 11, 13, 105, 58, 66, 75, 14, 25, 18, 48, 10, 31, 4, 9, 7, 19, 23, 8, 38, 35, 40, 28, 20, 3, 5, 15, 29, 22, 2, 24, 53, 33, 26, 16, 17, 21])
FFTPeriodicityDetectortends to be quite sensitive to noise and can find many false period lengths. Depending on your data, you can choose to apply a window function to get different results. You can also limit the number returned period length values to the 3 most signficant ones.>>> FFTPeriodicityDetector.detect(window_func="blackman", max_period_count=3) array([12, 13, 11])
As you can see, results are concentrated around the period length value 12, indicating a yearly periodicity.
Methods
detect(data[, window_func, detrend_func, ...])Find periods in the given series.