The idea: only the dots survive
A computer cannot store a smooth curve. It samples it: it keeps the value every 1/fs seconds, where fs is the sample rate. Everything between two samples is thrown away. To play the sound or show the picture again, the computer must guess the curve from the dots.
Many sines pass through the same dots. The rebuild (a DAC with a low-pass filter, or your eye) always picks the slowest one. If that is the original tone, sampling worked. If it is a different, slower tone, you got an alias: a false frequency that was never in the input.
Nyquist: more than two samples per cycle
The Nyquist–Shannon sampling theorem says a signal with no frequency at or above fs/2 is fully determined by its samples. fs/2 is the Nyquist frequency. Put the other way round: to capture a tone f you need fs > 2f, more than two samples per cycle (Demo 1: well sampled, 5 samples per cycle).
The inequality is strict. At exactly fs = 2f there are two samples per cycle, and with the wrong phase both land on zero crossings: every sample is 0 and the tone vanishes (Demo 3: exactly 2f).
Folding: where the alias lands
A sine at f and a sine at f − k·fs take the same values at every t = n/fs, because the difference is a whole number of turns per sample. So the samples show the copy closest to zero:
The result lies between −fs/2 and fs/2. A negative fa is the same speed going backwards; for a sine it means the rebuilt wave is upside down. In the spectrum, sampling makes copies of the tone at every k·fs ± f, and the band 0 … fs/2 sees whichever copy lands in it. A tone just above fs/2 lands just below it: the spectrum folds around fs/2 like paper.
| f | fs | samples per cycle | what the samples show |
|---|---|---|---|
| 2 Hz | 10 Hz | 5 | 2 Hz ✓ |
| 5 Hz | 10 Hz | 2 | all zeros ✗ |
| 9 Hz | 10 Hz | 1.11 | 1 Hz backwards ✗ |
| 10 Hz | 10 Hz | 1 | 0 Hz, a constant ✗ |
| 11 Hz | 10 Hz | 0.91 | 1 Hz forwards ✗ |
| 25 kHz | 44.1 kHz | 1.76 | 19.1 kHz ✗ |
The wagon-wheel effect
A film camera samples motion: 24 frames a second. A wheel that turns 0.9 of a turn between frames looks as if it turned 0.1 turn backwards, because that is the smallest move that gives the same picture (Demo 2: alias). At exactly one turn per frame it seems to stand still (Demo 4). The page's wheel has one dot, so it repeats once per turn. A real wheel with 5 identical spokes looks the same after 1/5 of a turn, so it aliases at 5 times the turn rate.
The dot's height is sin(2π f t), the same sine as in the time plot. That is why the wheel and the curve always agree: "backwards" on the wheel is "upside down" on the curve.
The anti-alias filter
An alias cannot be removed after sampling: its samples are exactly those of a real tone at fa. The fix comes before the sampler. An anti-alias filter is a low-pass filter that removes everything at or above fs/2, so nothing can fold. The page's filter passes everything up to 0.45·fs and removes everything from fs/2 up, with a straight line in between; real filters are curves, but the job is the same (Demo 5: anti-alias filter). A camera's motion blur and an optical low-pass filter in front of an image sensor play the same role for pictures.
Audio at 44.1 kHz
People hear up to about 20 kHz. CD audio samples at 44.1 kHz, so Nyquist is 22.05 kHz, just above hearing. Without a filter, a 25 kHz tone (from a bat, a switching power supply or a synthesizer) folds down to 19.1 kHz, inside the audible band (Demo 6). The filter must keep 20 kHz and remove 22.05 kHz: a narrow transition band of about 2 kHz (Demo 7). That steep filter is why modern converters oversample (sample at many times 44.1 kHz with an easy filter, then filter digitally and decimate).
| sample rate | Nyquist | used for |
|---|---|---|
| 8 kHz | 4 kHz | telephone speech (300–3400 Hz) |
| 44.1 kHz | 22.05 kHz | CD audio |
| 48 kHz | 24 kHz | video, broadcast, most computers |
| 96 kHz | 48 kHz | studio recording (easier filters, headroom for processing) |
The same folding shows up wherever something is sampled: moiré patterns in photos of fine stripes, jagged edges in images (JPEG compression works on sampled pixels), and the frequency bins of the FFT, which only go up to fs/2.
What the page leaves out
The input is one pure sine with phase 0; real signals are sums of many, and each folds on its own. The rebuild is drawn as the ideal one (a perfect low-pass filter, sinc interpolation over infinitely many samples); a real DAC uses a finite filter and a sample-and-hold step. The anti-alias filter is a straight-line idealization with no phase shift or ripple. Quantization (rounding each sample to 16 or 24 bits), dithering, jitter in the sample clock and band-pass (under-)sampling are not shown.