The Discrete-Time Fourier Transform
The spectrum of a sequence, its period of 2π, normalised frequency, FIR frequency responses, moving averages and the DTFT of samples
2020 — the weekend effect
In 2020 millions of people check COVID-19 dashboards every day, and the daily numbers misbehave. Reported cases sag at every weekend and surge after it; in the United States new cases tend to peak on Fridays and deaths on Tuesdays or Wednesdays, and similar weekly cycles appear in many other countries. The virus keeps no calendar — testing sites, laboratories and reporting offices do (Dear Pandemic).
The standard advice is a 7-day rolling average, and the weekly wobble vanishes as if it had never been there. It is not luck. A 7-point moving average is a filter, and its frequency response is exactly zero at one cycle per week and at every harmonic of it.
This lesson builds the tool that shows why: the Fourier transform of a sequence.
A sequence has no time axis in seconds, only an index. Its frequencies are measured in radians per sample, written : the sequence advances its phase by from one sample to the next. The discrete-time Fourier transform (DTFT) says how much of each a sequence contains.
The DTFT and its inverse. The sum makes a continuous, 2π-periodic function of Ω from a list of numbers; the integral over one period rebuilds the list.
💡A period of 2π, and normalised frequency
Because is an integer, : the DTFT repeats every . Only carries information, and for a real sequence only . The fastest oscillation a sequence can show is , at .
For samples taken at rate , — normalised frequency. is the Nyquist frequency, and the -periodicity is aliasing (Lesson 5-2) seen from the sequence's side. Indeed, if ,
the periodic spectrum of Lesson 5-1 with its frequency axis divided by .
💡The frequency response of an FIR filter
A filter that forms each output from the current and past inputs, , has the impulse response and the frequency response
Feed it and out comes : the same sequence, scaled and shifted in phase — the eigenfunction property of Lesson 3-1, for sequences.
scipy.signal.freqz evaluates on any grid of frequencies.Derivation
The moving average
An -point moving average has . Summing the geometric series,
Take out of the numerator and out of the denominator:
The magnitude is zero wherever is a multiple of but is not: at for . The phase, , is linear: every frequency is delayed by the same samples (Lesson 4-2).
📐Seven days
For daily data and , the zeros fall at , and radians per day: periods of 7, 3.5 and 2.33 days. A weekly reporting pattern, whatever its shape, is a sum of exactly these frequencies, so the average removes it completely.
Slow changes pass almost untouched: a 30-day wave keeps 91 % of its amplitude, a yearly one 99.9 %. The price is time. A trailing average — each day with the six before it — lags the trend by days. A centred average has no lag, but it needs three days of the future, so the last three days of any centred curve are always missing or provisional.
You see, but you do not observe.
🕰A meteorologist's smoothing
The Hann window of Lesson 6-3 is named after the Austrian meteorologist Julius von Hann, who smoothed weather records with a three-term weighted average (Hann function). The weights give : unit gain for slow changes, and a zero at that wipes out day-to-day alternation.
⚠Every causal smoother lags
A filter that uses only the past cannot respond to a change before it happens. The 7-day trailing average delays everything by three days; heavier smoothing delays more. When a smoothed curve turns, the real turn happened earlier — a fact worth remembering whenever a dashboard, a stock chart or a flight instrument shows filtered data.
💡Where you will use this
Sampling the DTFT at frequencies is the DFT of Lesson 6-2. FIR filter design (Lesson 9-1) is the art of shaping , and the z-transform (Unit 8) generalises the DTFT as the Laplace transform generalises Fourier's. Moving averages are everywhere: sensor smoothing, economic indicators, and the decimation filters of Lesson 5-3.
📚Further reading
- Oppenheim and Willsky, Signals and Systems, sections 5.1–5.4 — the discrete-time Fourier transform and its properties.
- Alan V. Oppenheim and Ronald W. Schafer, Discrete-Time Signal Processing (3rd ed., Pearson, 2010), chapter 2.
- Why are COVID-19 numbers lower on the weekends? — the weekly reporting cycle, explained.
↓But there is a problem
The DTFT is a continuous function of frequency, but a computer can evaluate only a finite list of frequencies — and done the obvious way, frequencies of an -sample record cost multiplications. For a million samples, that is a trillion.
In 1963, at a meeting of President Kennedy's science advisers about detecting Soviet nuclear tests, a statistician started sketching a way around it.