Aliasing & Moiré

Sample a signal too sparsely and a high frequency disguises itself as a low one. Sample a sinusoid and find its alias, then shrink an image and see the same effect as moiré, and how blurring before subsampling prevents it.

Sampling x(t)=cos⁡(2πft+φ)x(t) = \cos(2\pi f t + \varphi) signal samples at t=n/fst = n / f_s alias through the same samples
Spectrum of the sampled signal ±f\pm f copies kfs±fk f_s \pm f the copy inside [−fs/2,fs/2][-f_s/2, f_s/2] (Hz)
Subsampling an image each result enlarged back to the original size
original

Sampling a sinusoid

Sampling a continuous signal x(t)x(t) at rate fsf_s keeps only the values x[n]=x(n/fs)x[n] = x(n / f_s). For a sinusoid of frequency ff and any integer kk, the sinusoids at f+kfsf + k f_s and at kfs−fk f_s - f pass through exactly the same samples, since

cos⁡ ⁣(2π(f+kfs)nfs+φ)=cos⁡ ⁣(2πfnfs+φ+2πkn)=cos⁡ ⁣(2πfnfs+φ)\cos\!\Big(2\pi (f + k f_s) \frac{n}{f_s} + \varphi\Big) = \cos\!\Big(2\pi f \frac{n}{f_s} + \varphi + 2\pi k n\Big) = \cos\!\Big(2\pi f \frac{n}{f_s} + \varphi\Big)

and the cosine is even, so −f-f with phase −φ-\varphi gives the same values as ff with φ\varphi. The samples cannot tell these frequencies apart. Exactly one of them lies in [0,fs/2][0, f_s / 2]: the frequency that the samples appear to have, the alias

fa=∣f−kfs∣,k=round⁡(f/fs).f_a = \big| f - k f_s \big|, \qquad k = \operatorname{round}(f / f_s).

In the spectrum, sampling turns the two lines at ±f\pm f into copies repeated at every multiple of fsf_s. Whatever copy lands inside the band [−fs/2,fs/2][-f_s/2, f_s/2] is what a reconstruction from the samples produces.

The Nyquist rate

If f<fs/2f < f_s / 2, the alias is the signal itself and nothing is lost. This is the sampling theorem: a signal that contains no frequencies above fmaxf_\text{max} is determined by its samples if

fs>2fmax.f_s > 2 f_\text{max}.

2fmax2 f_\text{max} is the Nyquist rate, and fs/2f_s / 2 the Nyquist frequency of a given sampling rate: more than two samples per period. Above the Nyquist frequency, the alias folds back: raising ff from fs/2f_s / 2 to fsf_s lowers faf_a from fs/2f_s / 2 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 12\tfrac{1}{2} cycle per pixel: a stripe pattern with a period of 2 pixels, black and white. Keeping only every kk-th pixel lowers the sampling rate by kk, and the new Nyquist frequency is 12k\tfrac{1}{2k} 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,

Gσ(x)=12π σe−x22σ2⟷∣G(f)∣=e−2π2σ2f2,G_\sigma(x) = \frac{1}{\sqrt{2\pi}\,\sigma} e^{-\frac{x^2}{2\sigma^2}} \quad \longleftrightarrow \quad |G(f)| = e^{-2\pi^2 \sigma^2 f^2},

with ff in cycles per pixel: a wider Gaussian in space is narrower in frequency. A rule of thumb for subsampling by kk is σ≈k/2\sigma \approx k / 2. A smaller σ\sigma 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