Find the most probable periodicity for a time series with numpy Fourier Transform?

Suppose I have a time series t with one hundred measurements, each record represents a measured value for each day. I assume that there is a periodicity in the signal - it can be repeated daily, weekly or monthly.

Translating time series into Fourier domains can help find such periodicity?

How can I use the numpy fft module to find the most likely period for my time series?

+3


source to share


2 answers


I will try to answer my own question. You can correct me where needed.

In our case, time series t t = [2,1,0,1,2,3,2,1,0,1,2,3,2,1,0,1,2,3]

with 18 dimensions. A fairly simple example: it seems likely that a period is six time units long.

Taking these time series into the frequency domain gives us:

    w = numpy.fft.fft(t)
    print numpy.absolute(w)
    array([27.000000, 0.000000, 0.000000, 12.000000, 0.000000, 0.000000,
   0.000000, 0.000000, 0.000000, 3.000000, 0.000000, 0.000000,
   0.000000, 0.000000, 0.000000, 12.000000, 0.000000, 0.000000])

      



We ignore frequency 0 and observe that the value is highest for index 3 - this indicates that in our time series t, the signal is repeated 3 times. Therefore, the signal length - the period - would be 18/3 = 6. And indeed:

numpy.fft.fftfreq(18)
array([ 0.      ,  0.055556,  0.111111,  0.166667,  0.222222,  0.277778,
    0.333333,  0.388889,  0.444444, -0.5     , -0.444444, -0.388889,
   -0.333333, -0.277778, -0.222222, -0.166667, -0.111111, -0.055556])

      

The frequency in index 3 is exactly 1/6, that is, the frequency for a unit of time is 1/6, that is, the signal takes six units of time for a full period.

Please let me know if my understanding is correct.

+2


source


Note that the FFT detects a sine decomposition that is different from the periodicity estimate (since any fundamental period may be completely absent from the signal's periodic frequency spectrum. See fundamental meaning missing )



So you will need to post-process your FFT result with something like a cepstrum (using complex cepstral analysis, etc.), or perhaps use an estimate of the spectrum of harmonic products.

0


source







All Articles