214. Fourier

A frequency-domain representation of a time series. Decompose the series into a sum of sines and cosines at different frequencies. Useful for finding dominant cycles that aren’t obvious in the time-domain view.

214.0.1. Discrete Fourier Transform (DFT)

For a series of length :

The output is a complex number. Its magnitude measures how much the frequency (cycles per time unit) is present in the signal. The phase tells you where the cycle peaks.

The inverse DFT recovers the original series:

214.0.2. Frequencies and periods

For a series sampled at one observation per unit time, the DFT covers frequencies for :

So you only look at the first frequencies for a real-valued series. The period corresponding to bin is .

214.0.3. FFT — the fast version

The Fast Fourier Transform (Cooley-Tukey 1965) computes the DFT in rather than the naive . It’s the standard implementation in every numerical library (NumPy fft.fft, MATLAB fft, etc.).

Use FFT in practice; conceptually it computes exactly the DFT above.

214.0.4. What you can do with the Fourier transform

214.0.4.1. 1. Find dominant cycles

Plot (the power spectrum) vs frequency. Peaks indicate dominant cycles. Example uses:

This is the core of [periodogram.typ](periodogram.typ).

214.0.4.2. 2. Filter (frequency-domain)

Remove specific frequencies:

Procedure: FFT → zero out unwanted frequency bins → inverse FFT.

214.0.4.3. 3. Forecast with Fourier features

Add sin(2 pi k t \/ m) and cos(2 pi k t \/ m) as regressors in a linear forecasting model, where is the period. A handful of harmonics () captures most of a smooth seasonal pattern.

This is how Prophet (Facebook) and many modern forecasting libraries handle seasonality without a fixed seasonal index.

214.0.4.4. 4. Spectral density estimation

Smoothed version of the periodogram → see [periodogram.typ](periodogram.typ).

214.0.5. Limitations

214.0.6. Connection to seasonality

If your series has a known seasonal period , you’d expect a peak in the spectrum at . Conversely, unknown periodicities are discovered via the spectrum — perhaps weekly + monthly + yearly all show up in the same series. Fourier analysis is the natural tool for this.

Example: Fourier analysis of monthly retail sales

Given: months of sales data (5 years).

Step 1 — apply FFT

import numpy as np
Y = np.fft.fft(y)
power = np.abs(Y[:N//2])**2  # only first half (positive frequencies)
freq = np.arange(N//2) / N    # cycles per month
period = 1 / np.where(freq > 0, freq, np.inf)  # months per cycle

Step 2 — find peaks

Suppose the power spectrum shows large peaks at:

  • → frequency → period 12 (monthly cycle = annual)
  • → frequency → period 6 (semi-annual)
  • → frequency → period 60 (long-term trend)

Step 3 — interpret

  • The annual peak at is the dominant seasonality.
  • The semi-annual peak might be a back-to-school spike on top of the holiday spike.
  • at the lowest frequency captures the multi-year trend.

Step 4 — use

Pick a few harmonics (, possibly 15) and use them as Fourier features in a regression: forecast = trend + linear combination of and . The Fourier representation lets you smoothly interpolate seasonal effects between cycles.