Fourier terms

Also known as: Fourier features

On this page 7

Fourier terms are pairs of sine and cosine functions of time, added as input features so that a model can represent periodic seasonal patterns with a small number of parameters. In time series & forecasting, they are also called Fourier features, and they serve as a compact alternative to dummy variables for every hour, weekday or week of the year.

The idea comes from Fourier analysis: any reasonably smooth periodic pattern can be approximated by a sum of sinusoids at the base frequency and its integer multiples. A forecaster chooses the seasonal period and the number of harmonics, and the model learns how strongly each sinusoid contributes.

How Fourier terms encode seasonality

For a seasonal period m and harmonic k, the two features at time t are sin(2πkt/m) and cos(2πkt/m). Using harmonics k = 1 to K produces 2K features per seasonal period. The first harmonic captures one smooth wave per cycle; higher harmonics add sharper shapes, such as a morning peak and an evening peak within one day.

The model, typically a linear regression or the regression part of a dynamic model, estimates one coefficient per feature. The weighted sum of sines and cosines becomes the estimated seasonal profile. Because sine and cosine at the same frequency combine into a single wave with any phase, the model does not need to know when the peak occurs in advance.

Harmonics (K)Features addedShape the model can representRisk
K = 12Single smooth waveUnderfitting sharp peaks
K = 3 to 56 to 10Asymmetric peaks and plateausUsually balanced
K = 10 to 2020 to 40Detailed, spiky profilesOverfitting noise
K = m/2About mAny pattern, like indicatorsNo parameter saving
Effect of the number of harmonics on the seasonal shape

Choosing the period and the number of harmonics

The period m follows from the data frequency and the cycle of interest. It does not need to be an integer, which is one of the main advantages of Fourier terms: yearly seasonality in weekly data has a period of about 52.18 weeks, and dummy variables cannot express that cleanly.

Data frequencyCyclePeriod mTypical K range
HourlyDaily243 to 10
HourlyWeekly1683 to 10
DailyWeekly71 to 3
DailyYearly365.255 to 15
WeeklyYearly52.183 to 12
Half-hourlyDaily485 to 15
Common seasonal periods by data frequency

The number of harmonics is a model-selection choice. A standard approach is to fit models with increasing K and pick the one with the lowest AICc or the best time series cross-validation error. The upper limit is K = m/2, at which point the Fourier basis spans the same space as a full set of seasonal indicator variables.

Fourier terms compared with other seasonal representations

Fourier terms are one of several ways to give a model information about the seasonal cycle. The best option depends on period length, the number of cycles and whether the seasonal shape changes over time.

ApproachParametersHandles long periodsHandles changing shape
Fourier terms2K per periodYesOnly with extra mechanisms
Seasonal dummy variablesm minus 1PoorlyNo
Seasonal ARIMAFew seasonal lagsPoorly above about 24Partly
STL decompositionNonparametricYesYes
Calendar features in treesOne categorical columnYesYes, with enough data
Seasonal representations compared

Seasonal ARIMA estimation becomes slow and unstable for long periods such as 365 days or 168 hours, which is why dynamic harmonic regression, regression with Fourier terms plus ARIMA errors, is a standard remedy. Forecasting libraries such as Prophet model yearly and weekly seasonality with Fourier series by default, and TBATS uses a trigonometric representation of the same idea.

Using Fourier features in machine learning forecasters

In machine learning pipelines, Fourier features are deterministic covariates: their future values are known exactly, so they can be computed for the whole forecast horizon without leakage. This makes them convenient inputs for gradient-boosted trees, global forecasting models and neural forecasters.

  • Linear and generalized linear models benefit most, because they cannot learn periodic shapes from a raw time index.
  • Gradient-boosted trees can use them, but often perform similarly with plain calendar features and lag features.
  • Neural forecasters use sinusoidal encodings as smooth, bounded time inputs that avoid the jump between day 365 and day 1.
  • Multiple seasonality is handled by simply concatenating Fourier sets for each period.

A practical rule is to compute the time index consistently across training and prediction, measured from a fixed origin in the same units. Mismatched origins shift the phase and silently move the seasonal peak.

Limitations and common mistakes

With fixed coefficients, Fourier terms assume a stable seasonal shape. If the pattern evolves, for example as summer demand grows faster than winter demand, the model needs time-varying coefficients, interactions with a trend, or a method such as STL that updates the seasonal component.

SymptomLikely causeFix
Smoothed-out holiday spikesShort events need many harmonicsAdd explicit holiday indicators
Wiggly seasonal profileK set too highLower K, select by AICc
Peak in the wrong weekInconsistent time originUse one fixed time index
Residual seasonalityMissing second periodAdd a Fourier set per cycle
Frequent problems with Fourier terms and their fixes

Fourier terms also handle abrupt, irregular events poorly. Holidays, promotions and moving feasts are better modeled with dedicated indicator variables alongside the smooth seasonal basis.

Stripped to the essentials

Many things repeat in cycles. Electricity use rises every evening. Ice cream sales rise every summer. A forecasting model needs a way to know where it is in the cycle.

Fourier terms give it that sense of position. They are smooth waves that repeat at the same rhythm as the cycle. One slow wave describes a simple rise and fall. Adding faster waves lets the model draw more detailed shapes, such as two peaks in one day. The model then decides how much of each wave it needs. The result is a compact description of the season that uses only a few numbers.

Where it is applied

A regional grid operator forecasts half-hourly electricity load one day ahead. The data shows a daily cycle of 48 periods, a weekly cycle of 336 periods and a yearly cycle of about 17,532 periods. Seasonal ARIMA cannot handle the yearly period, and dummy variables for every half-hour of the year would add thousands of parameters.

The analysts build a dynamic harmonic regression with 10 harmonics for the daily cycle, 5 for the weekly cycle and 8 for the yearly cycle, plus temperature and holiday indicators as exogenous covariates. The model uses 46 seasonal features instead of thousands, trains in minutes, and selecting K by cross-validation reduces day-ahead error compared with a model that uses only half-hour indicator variables.