Sampling Theorem / Nyquist, Aliasing
Sample at least twice the fastest wiggle and the original wave rebuilds exactly. Sample slower and a false slow wave appears that was never there.
Why Does This Exist?
Every sensor chooses a rate: audio at 44100 Hz, images at one sample per pixel, logs once per minute. Choose too low and high frequencies do not just blur, they reappear as confident low frequencies that were never in the world. A 5 Hz wobble sampled at 6 Hz returns as a clean 1 Hz wave, and no downstream model can tell the lie from truth.
The sampling theorem draws the line. If the highest frequency present is , sampling at preserves everything, and sinc interpolation rebuilds the continuous wave exactly. Below , frequencies fold: masquerades as . This page proves the rule with one 5 Hz tone carried through every section. Frequency language lives in Fourier transform and convolution theorem, fast spectra in discrete Fourier transform and FFT, and localized wiggles in wavelets.
The one idea you need first
A frequency counts cycles per second in Hz. A 5 Hz tone completes 5 cycles each second, period s. Sampling records the height at spacing . With Hz you keep 4 heights per 5 Hz cycle; with Hz you keep only heights per cycle, below the 2 needed to see up from down.
Think of It Like This
A wagon wheel under a strobe
A wagon wheel spins forward fast while a strobe flashes. Flash twice per spoke pass and you see each spoke advance: true motion. Flash slower than twice per pass and a spoke from the next gap arrives where you expected the old one, so the wheel crawls backward or stands still on film.
Samples are flashes, spokes are wave peaks. The Nyquist rate is twice per pass: fewer flashes invent direction. Where the analogy stops: strobes alias rotation, while sampling aliases any fast wiggle into a slow tone, and the false tone is mathematically exact, not a trick of the eye.
How It Actually Works
Bandlimit the signal to , sample at , keep tones below . The Nyquist rate is : the minimum that works. At or above it, the samples determine exactly one bandlimited wave, rebuilt by summing shifted sincs. Below it, true and alias share identical samples for integer , so the rebuild picks the low one.
In plain words: 2 samples per cycle is the break-even where up and down stay distinguishable. At samples per cycle, two different waves thread the same dots, and reconstruction chooses the slower impostor.
Worked example
Take a 5 Hz tone, amplitude 1. Nyquist rate is Hz.
Adequate: Hz. Samples per cycle are . The dots trace peak, zero, trough, zero, and sinc rebuilding returns the 5 Hz tone. True equals rebuilt.
Too slow: Hz. Samples per cycle are , below 2. The nearest fold is : alias is Hz. The dots that the 5 Hz wave leaves at 6 Hz sampling are exactly the dots a 1 Hz wave leaves, so the rebuild reports a slow 1 Hz wobble at full height. Same dots, wrong wave, no warning flag.
Code
Compute the fold for the worked tone with no libraries beyond the standard one.
f_true = 5.0for fs in (20.0, 6.0): k = round(f_true / fs) # nearest fold alias = abs(f_true - k * fs) print(fs, alias) # -> 20.0 5.0 and 6.0 1.0At 20 Hz the fold stays 5 Hz: no alias. At 6 Hz it folds to 1 Hz: the dashed impostor in the diagram. The printout reads 5.0 and 1.0 against the hand computation above.
Watch Out For
Sampling at exactly twice with no margin or filter
The theorem assumes a perfectly bandlimited signal and ideal sinc rebuilding. Real sensors carry noise above and real filters roll off gently, so sampling audio at exactly kHz folds the 21 kHz hiss into 19 kHz whine. Oversample to times or higher and put a low-pass anti-alias filter before the sampler, not after.
Downsampling without low-passing first
Taking every fourth pixel or every tenth log row without filtering folds the dropped high frequencies into the kept band: brick walls become rainbow moire, fast spikes become slow drifts. Filter to the new Nyquist or first, then drop. If moire appears after a resize, the filter was missing, not the pixels.
The Quick Version
- Signals below half the sampling rate rebuild exactly; that half rate is the Nyquist frequency.
- The Nyquist rate is twice the highest frequency present: 10 Hz for a 5 Hz tone.
- At 20 Hz a 5 Hz tone keeps 4 samples per cycle and rebuilds true.
- At 6 Hz the same tone keeps 1.2 samples per cycle and returns as a false 1 Hz wave.
- Filter before sampling and before downsampling, or high frequencies fold into low ones.