Sampling a sinusoid
Sampling a continuous signal at rate keeps only the values . For a sinusoid of frequency and any integer , the sinusoids at and at pass through exactly the same samples, since
and the cosine is even, so with phase gives the same values as with . The samples cannot tell these frequencies apart. Exactly one of them lies in : the frequency that the samples appear to have, the alias
In the spectrum, sampling turns the two lines at into copies repeated at every multiple of . Whatever copy lands inside the band is what a reconstruction from the samples produces.
The Nyquist rate
If , the alias is the signal itself and nothing is lost. This is the sampling theorem: a signal that contains no frequencies above is determined by its samples if
is the Nyquist rate, and the Nyquist frequency of a given sampling rate: more than two samples per period. Above the Nyquist frequency, the alias folds back: raising from to lowers from to 0. This is why wheels in films seem to turn slowly or backwards: the frame rate samples the rotation too sparsely.
Aliasing in images
An image is a 2D signal, sampled once per pixel, so its Nyquist frequency is cycle per pixel: a stripe pattern with a period of 2 pixels, black and white. Keeping only every -th pixel lowers the sampling rate by , and the new Nyquist frequency is cycles per pixel. Every finer detail folds back into coarser patterns that are not in the scene: moiré. The zone plate shows it best, since its frequency grows steadily from the center outwards; after subsampling, new rings appear around new centers. The same happens at the fence in the landscape, and the aliased stripes of a fine pattern can even run in a different direction than the original ones.
Anti-aliasing: filter first, then subsample
Once aliasing has happened, it cannot be undone: the samples of the fine pattern and of its alias are the same. The only remedy is to remove the frequencies above the new Nyquist frequency before sampling, with a low-pass filter. The Gaussian is a good choice; its frequency response is again a Gaussian,
with in cycles per pixel: a wider Gaussian in space is narrower in frequency. A rule of thumb for subsampling by is . A smaller leaves more aliasing, a larger one blurs away detail that the smaller image could still show. Image pyramids use this “blur, then subsample” step at every level. A camera does it optically: the lens and the sensor pixel area blur the image before it is sampled (compare cell center and cell average in sampling & quantization), and many cameras add an optical low-pass filter in front of the sensor. The Gaussian itself is covered in Gaussian & separability.
Try this
- Start with Hz at Hz: the samples trace a 2 Hz sinusoid. Lower slowly to 5 Hz and watch the alias rise to meet it.
- Set Hz: one sample per period, and the samples are constant. The sinusoid has aliased to 0 Hz.
- Set Hz exactly at Hz and change the phase: at 90° all samples are 0 and the sinusoid disappears. The theorem needs , strictly.
- With Hz, change the phase: the alias moves in the opposite direction, because it comes from the mirrored copy .
- Pick the zone plate, subsample by 4 and set : outside the center, the rings turn into new ring patterns around new centers. Increase until they fade to gray.
- Look at the line groups of the test chart subsampled by 3 without a pre-filter: the finest groups show stripes with the wrong period, or none at all.
- Set with : no aliasing, but the result is blurrier than necessary. Compare the Gaussian's response at in the values panel.