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
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) | Coefficients | Decay |
|---|---|---|
| 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:
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
$f_s/2$ is the Nyquist frequency. A sine above it produces exactly the same samples as a lower-frequency sine, its alias:
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:
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.
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
- 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.
- 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.
- 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.
- 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.
- 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.