import matplotlib
if not hasattr(matplotlib.RcParams, "_get"):
matplotlib.RcParams._get = dict.get
7.2 Aliasing#
What happens when we sample too slowly? Return to the sinusoids that shared identical samples, now adding a third at 4 Hz. Sampled at \(f_s = 1\) Hz, all three still land on their zero crossings, so they remain indistinguishable:
Fig. 37 The same picture with a third sinusoid at 4 Hz. At \(f_s = 1\) Hz, the 1, 2, and 4 Hz tones share identical (all-zero) samples, so from the samples alone we cannot tell them apart.#
From the samples alone, a 1 Hz signal and a 4 Hz signal are indistinguishable. When we undersample, high frequencies masquerade as lower ones. This phenomenon is called aliasing, and the impostor frequencies are called aliases.
When sampling by \(f_s\), every frequency has infinitely many aliases, spaced \(f_s\) apart. For a frequency \(f\), its aliases are the set
all the frequencies that differ from \(f\) by an integer multiple of the sampling rate. This is exactly the copied-spectrum picture: each true frequency shows up again at every multiple of \(f_s\). These aliases are not merely hard to tell apart, they are mathematically identical: a tone at \(f\) and a tone at any of its aliases produce the exact same samples. So when the samples are reconstructed, the signal necessarily comes back at the single alias that falls within the Nyquist band \([0, f_s/2]\). We can compute that apparent frequency directly:
Definition 21 (Aliased frequency)
When a frequency \(f\) is sampled at rate \(f_s\), its apparent (aliased) frequency is
which always lies in \([0, f_s/2]\). If \(f\) is already in \([0, f_s/2]\), then \(f_{\text{alias}} = f\) and no aliasing occurs. Otherwise \(f_{\text{alias}} \neq f\).
Aliasing in practice#
Aliasing is a very real, audible phenomenon, not just a theoretical construct. To hear it, we can synthesize a tone whose frequency slowly sweeps up from 220 Hz to 880 Hz and back, at a few different sample rates. The following clips were each synthesized directly at the given \(f_s\) (then resampled purely for playback), so any aliasing is baked into the sound:
The same 220-to-880 Hz frequency sweep synthesized at three sample rates. At \(f_s = 2000\) Hz the sweep is clean. As \(f_s\) drops, the upper part of the sweep exceeds the Nyquist frequency and folds back down, so the perceived frequency audibly reverses direction.
The figure below plots what is happening. The true frequency (blue) rises above the Nyquist frequency (red) once \(f_s\) is small enough, and the frequency we actually hear (orange) folds back below it:
Fig. 38 The frequency sweep at three sample rates. When the true frequency (blue) crosses the Nyquist frequency \(f_s/2\) (red), the heard frequency (orange) reflects back downward. The full sonification code is available as an interactive example below.#
For frequencies just above the Nyquist frequency, in the range \([f_s/2, f_s]\), this reflection is colloquially called foldover, because the aliased frequencies mirror back across the Nyquist frequency as if it were a crease in a folded sheet of paper.
The widget below samples a single tone at a rate of your choosing. The true tone and its alias pass through exactly the same samples, which is why nothing downstream can tell them apart.
Drag the two sliders. On the left, the gray curve is the true tone, the red dots are the samples taken at \(f_s\), and the gold curve is the alias that runs through the very same dots. On the right, the gold line maps every true frequency to the one you actually hear. The audio card plays the current setting.
You can explore this yourself. The interactive example below lets you set the sample rate and the frequency contour, then synthesizes and plays the result so you can hear aliasing emerge as you lower \(f_s\):
# Edit the sample rate and the frequency contour, then run to see and hear aliasing.
# Each control point is (time in seconds, frequency in Hz).
f_s = 500 # sampling rate (Hz): lower it to force aliasing
freq_contour = [
(0.0, 220.0),
(1.0, 220.0),
(6.0, 880.0),
(7.0, 880.0),
(12.0, 220.0),
(13.0, 220.0),
]
show_aliasing(f_s, freq_contour)
Aliasing beyond audio#
Aliasing is not unique to digital audio. It arises whenever any signal is sampled too slowly, including the sampling of light that our eyes and cameras perform. A classic example is the wagon-wheel effect, in which the spoked wheels of a moving vehicle appear to slow down, stop, or even spin backwards on film. A camera captures frames at a fixed rate (its sampling rate). When a wheel rotates by nearly a full spoke-spacing between frames, its true rotation aliases to a much slower apparent rotation, and when it rotates by slightly more than a spoke-spacing, the alias runs backwards (a negative frequency):
You may have experienced the same effect at a concert with a strobe light. The strobe flashes at a fixed rate, sampling the motion of the dancers, and this can make movements appear frozen, slowed, or reversed. The figure below shows a dancer bobbing up and down once per second (a 1 Hz motion). The leftmost panel is the continuous motion, and the other four “sample” it by holding whichever frame was most recently caught by a strobe at the labeled rate, while a shared clock advances:
Fig. 39 The same 1 Hz dance, continuous (left) and sampled at four rates. At \(f_s = 4\) Hz the motion still looks correct (oversampled). At \(f_s = 2\) Hz it collapses to just two alternating poses (critical sampling). At \(f_s = 1\) Hz the dancer is caught at the same phase every time and appears frozen, aliased all the way to 0 Hz. At \(f_s = \tfrac{4}{3}\) Hz the dancer appears to dance more slowly, the same foldover we saw with sound.#
Critical sampling#
The sampling theorem demands \(f_s > 2 f_{\max}\), a strict inequality. What happens right at the boundary, when \(f_s = 2 f_{\max}\)? This edge case is called critical sampling, and it turns out to be genuinely ambiguous.
Consider a cosine at exactly the Nyquist frequency, \(x(t) = \cos(2\pi t)\) with \(f_{\max} = 1\) Hz, sampled at \(f_s = 2\) Hz. The samples are
a perfectly reasonable representation of a 1 Hz tone. But now consider a sine at the same frequency, \(x(t) = \sin(2\pi t)\), sampled at the same rate. Its samples are
Every sample lands exactly on a zero crossing, so the sine vanishes completely. Those all-zero samples could equally well represent silence, a signal at 0 Hz. At critical sampling, then, a component at exactly \(f_s/2\) may or may not survive, depending on its phase. This is precisely why the theorem requires a strict inequality: at the boundary, reconstruction is no longer guaranteed.