Draw a closed shape here with your mouse or finger

1. Fourier series: every periodic signal is a sum of sines

The big idea: any repeating wave, however jagged, can be built by adding plain sine waves whose frequencies are whole-number multiples of the basic repeat rate. Build mode lets you do exactly that with sliders.

A periodic signal $x(t)$ with period $T$ (fundamental frequency $f_0=1/T$, angular frequency $\omega_0=2\pi f_0$) can be written as

$$x(t)=\frac{a_0}{2}+\sum_{n=1}^{\infty}\big[a_n\cos(n\omega_0 t)+b_n\sin(n\omega_0 t)\big]$$
$$\begin{gathered}a_n=\frac{2}{T}\int_0^T x(t)\cos(n\omega_0 t)\,dt\\ b_n=\frac{2}{T}\int_0^T x(t)\sin(n\omega_0 t)\,dt\end{gathered}$$

The lab uses the equivalent amplitude–phase form $x(t)=\sum A_n\sin(n\omega_0t+\varphi_n)$ with $A_n=\sqrt{a_n^2+b_n^2}$. Each term is a phasor: a vector of length $A_n$ spinning $n$ times per period. Chaining the phasors tip to tail gives the epicycles, and the height of the last tip traces $x(t)$.

Wave (amplitude 1)CoefficientsDecay
Square$b_n=\dfrac{4}{n\pi}$ for odd $n$, 0 for even$1/n$ (jumps)
Sawtooth$b_n=\dfrac{2(-1)^{n+1}}{n\pi}$$1/n$ (jumps)
Triangle$b_n=\dfrac{8}{\pi^2}\dfrac{(-1)^{(n-1)/2}}{n^2}$ for odd $n$$1/n^2$ (corners)

The smoother the signal, the faster the coefficients decay. A jump gives $1/n$, a corner gives $1/n^2$, a smooth curve decays faster than any power.

The Gibbs phenomenon

Near a jump, the partial sums overshoot. Adding more harmonics squeezes the overshoot closer to the jump but never reduces its height: it tends to about 8.95 % of the jump (the square wave peaks near $1.179$ instead of $1$).

2. The discrete Fourier transform (DFT)

Intuition: the DFT tests the samples against a set of pure "probe" waves and reports how strongly each one matches. A big $|X_k|$ means frequency $f_k$ is strongly present.

A computer only has $N$ samples $x_0,\dots,x_{N-1}$ taken every $1/f_s$ seconds. The DFT measures how much of each frequency $f_k=k\,f_s/N$ they contain:

$$X_k=\sum_{n=0}^{N-1}x_n\,e^{-2\pi i kn/N},\qquad x_n=\frac1N\sum_{k=0}^{N-1}X_k\,e^{2\pi i kn/N}$$

The bin spacing (frequency resolution) is $\Delta f=f_s/N$. Computing the sum directly costs $O(N^2)$ operations. The Fast Fourier Transform (Cooley–Tukey) splits it into even and odd halves recursively and costs $O(N\log_2 N)$: for $N=4096$ that is about 49 000 instead of 16.8 million multiplications. This lab uses its own radix-2 FFT.

Leakage and windows. The DFT assumes the $N$ samples repeat forever. If a sine does not fit a whole number of cycles in the frame, the wrap-around creates a jump and energy leaks into neighbouring bins. Multiplying by a Hann window $w_n=\tfrac12\left(1-\cos\tfrac{2\pi n}{N-1}\right)$ tapers the ends and greatly reduces leakage.

A spectrogram repeats the FFT on short overlapping frames and stacks the spectra side by side: time runs left to right, frequency upwards, brightness shows strength.

3. Sampling and the Nyquist–Shannon theorem

A signal containing no frequencies at or above $f_s/2$ is completely determined by its samples, and can be rebuilt exactly with sinc interpolation: $$x(t)=\sum_{n}x[n]\,\mathrm{sinc}\big(f_s t-n\big),\qquad \mathrm{sinc}(u)=\frac{\sin \pi u}{\pi u}$$

$f_s/2$ is the Nyquist frequency. A sine above it produces exactly the same samples as a lower-frequency sine, its alias:

$$f_{\text{alias}}=\left|\,f-f_s\cdot\operatorname{round}\!\left(\frac{f}{f_s}\right)\right|$$

Once sampled, an alias cannot be told apart from a real tone, so real systems put an analogue anti-aliasing low-pass filter before the converter.

4. Filters

A linear time-invariant filter multiplies each frequency component by a gain $|H(f)|$ (and shifts its phase). The lab uses Butterworth magnitude responses, which are maximally flat in the pass band:

$$\begin{gathered}|H_{\text{LP}}(f)|=\frac{1}{\sqrt{1+(f/f_c)^{2n}}}\\ |H_{\text{HP}}(f)|=\frac{1}{\sqrt{1+(f_c/f)^{2n}}}\end{gathered}$$

At the cutoff the gain is $1/\sqrt2$ ($-3$ dB, i.e. half the power). Beyond it the response falls by $6n$ dB per octave (each doubling of frequency) for order $n$; every $-6$ dB roughly halves the amplitude. A band-pass is a high-pass and a low-pass in series.

Simplification: the lab filters the whole recording at once in the frequency domain (FFT, multiply by $|H|$, inverse FFT). This is a zero-phase, offline filter. A real-time analogue or IIR filter has the same magnitude response but also delays and phase-shifts the signal.

5. Fourier drawing

Any closed curve can be treated as a complex-valued periodic signal $z(t)=x(t)+i\,y(t)$. Its DFT gives coefficients $c_k$, and the curve is redrawn as $z(t)=\sum_k c_k e^{2\pi i k t}$: a chain of circles of radius $|c_k|$ spinning at $k$ turns per cycle (negative $k$ spin clockwise). Sorting by size and keeping the biggest $N$ is the same idea as lossy compression in JPEG and MP3.

Example 1: square-wave coefficients

Let $x(t)=+1$ for $0<\omega_0t<\pi$ and $-1$ for $\pi<\omega_0t<2\pi$. Using $\theta=\omega_0 t$:

$b_n=\dfrac{1}{\pi}\left[\int_0^{\pi}\sin n\theta\,d\theta-\int_{\pi}^{2\pi}\sin n\theta\,d\theta\right]=\dfrac{2}{n\pi}\big(1-\cos n\pi\big)$

For odd $n$, $\cos n\pi=-1$ so $b_n=\tfrac{4}{n\pi}$: $b_1=1.273$, $b_3=0.424$, $b_5=0.255$, $b_7=0.182$. For even $n$, $b_n=0$. All $a_n=0$ because the wave is odd.

Press Square in Build mode: the amplitude sliders show exactly these values.

Example 2: a four-point DFT by hand

$x=[1,0,-1,0]$ (one cycle of a cosine, $N=4$). Then $X_k=\sum_n x_n e^{-i\pi kn/2}=1-e^{-i\pi k}=1-(-1)^k$.

So $X=[0,\,2,\,0,\,2]$. Bin 1 is the cosine at $f_s/4$; bin 3 is its mirror image at $-f_s/4$ (for real signals $X_{N-k}=\overline{X_k}$). Amplitude $=2|X_1|/N=1$. ✔

Example 3: frequency resolution

With $f_s=8000$ Hz and $N=1024$: $\Delta f=8000/1024=7.8125$ Hz and each frame lasts $N/f_s=128$ ms.

A 220 Hz tone lands at $k=220/7.8125=28.16$, between bins 28 and 29, which is why a window matters. Doubling $N$ halves $\Delta f$ but doubles the frame length: you trade time resolution for frequency resolution.

Example 4: aliasing

A 7 Hz sine sampled at $f_s=10$ Hz: Nyquist is 5 Hz, so it aliases. $f/f_s=0.7$ rounds to 1, giving $f_{\text{alias}}=|7-10|=3$ Hz.

A 30 Hz sine sampled at 40 Hz: $30/40=0.75\to1$, alias $=|30-40|=10$ Hz. At 20 Hz: $30/20=1.5\to2$, alias $=|30-40|=10$ Hz too.

Audio CDs use $f_s=44.1$ kHz, so the Nyquist frequency (22.05 kHz) sits just above the limit of human hearing (about 20 kHz).

Example 5: the wagon-wheel effect

A wheel with one marked spoke turns at 25 rev/s and is filmed at 24 frames per second. Between frames it turns $25/24=1.0417$ revolutions, which looks like $+0.0417$ rev per frame: it appears to creep forward at $0.0417\times24=1$ rev/s. At 23 rev/s it appears to turn backwards at 1 rev/s, since $23-24=-1$.

Example 6: designing a hum filter

Kenyan mains electricity runs at 50 Hz, and poorly shielded audio cables pick up hum at 50 Hz and its harmonics (100, 150 Hz…). To keep a 440 Hz note, use a high-pass filter with $f_c=250$ Hz and order $n=4$.

At 50 Hz: $f_c/f=5$, so $|H|=1/\sqrt{1+5^{8}}=0.0016$ ($-56$ dB). At 440 Hz: $f_c/f=0.568$, $|H|=1/\sqrt{1+0.568^8}=0.995$ ($-0.05$ dB). The hum disappears and the note is untouched.

Challenges (checked automatically)

Guided experiments

  1. Phase matters to the eye, not the ear. Build a square wave, then drag the phase of harmonic 3 to a new value. The shape changes dramatically, but press Play: it sounds almost the same. Our ears mostly hear the amplitude spectrum.
  2. Gibbs never goes away. With the Square preset, slide N from 3 to 16 and watch the overshoot readout settle near 9 % instead of shrinking.
  3. Leakage. In Spectrum mode with the built sine, turn the Hann window off. The single peak spreads into a wide skirt. Turn it on again.
  4. Aliasing in audio. In Build mode set f₀ = 880 Hz with the sawtooth. The Spectrum mode samples at 8 kHz, so its Nyquist frequency is 4 kHz: harmonics above 4 kHz (the 5th, at 4.4 kHz, and up) cannot be represented and appear folded back below 4 kHz in its display.
  5. Compression. In Fourier drawing, draw a signature. How few epicycles still make it readable? This is the principle behind keeping only the largest coefficients in JPEG and MP3.

Where Fourier analysis is used

Mobile networks. 4G and 5G use OFDM: data is spread over hundreds of closely spaced sub-carriers, created and separated with an inverse FFT and an FFT in every phone and base station.
Audio and music. MP3 and AAC keep only the frequency components the ear can hear. Equalisers on a mixing desk are filters on the spectrum.
Medicine. ECG machines notch out 50 Hz mains interference. MRI scanners record the Fourier transform of the image directly and invert it.
Earthquakes and structures. Seismologists read spectra to identify quakes; engineers check that a bridge's natural frequencies are far from footfall or wind forcing.
Images. JPEG compresses 8×8 blocks with a discrete cosine transform, a close relative of the DFT.
Radio. An FM station on 99.9 MHz occupies a narrow band; a receiver is essentially a tunable band-pass filter.