AnyLearn
All lessons
Mathintermediate

Sampling and Aliasing: The Rule You Cannot Break

Turning a continuous signal into numbers is safe only above a specific rate, and below it the damage is silent and permanent. This lesson derives the Nyquist limit, shows exactly where a too-high frequency reappears, and explains why the fix has to be analogue and has to happen before the converter.

Updated · AI-authored, review-gated · how lessons are made

Not signed in: your progress and quiz score won't be saved.
Progress1 / 10

Sampling is a measurement with gaps

An analogue-to-digital converter looks at a voltage every TsT_s seconds and writes down a number. Between measurements it has no idea what happened, and it never will. The sample rate is fs=1/Tsf_s = 1/T_s: 44,100 samples per second on a CD, 48,000 in video, 16,000 in most speech models.

The question this lesson answers is when that gap costs you nothing. It has an exact answer, which is unusual and worth appreciating: under one stated condition, the samples contain everything, and the original continuous signal can be reconstructed perfectly. Outside that condition the loss is not a gentle degradation. It is a specific, predictable corruption that no later processing can undo.

Full lesson text

All 10 steps on one page, for reading, reference, and search.

Show

1. Sampling is a measurement with gaps

An analogue-to-digital converter looks at a voltage every TsT_s seconds and writes down a number. Between measurements it has no idea what happened, and it never will. The sample rate is fs=1/Tsf_s = 1/T_s: 44,100 samples per second on a CD, 48,000 in video, 16,000 in most speech models.

The question this lesson answers is when that gap costs you nothing. It has an exact answer, which is unusual and worth appreciating: under one stated condition, the samples contain everything, and the original continuous signal can be reconstructed perfectly. Outside that condition the loss is not a gentle degradation. It is a specific, predictable corruption that no later processing can undo.

2. The sampling theorem

The condition, from Nyquist's 1928 telegraph-transmission work and Shannon's 1949 formulation, is a single inequality. If a signal contains no frequency at or above BB, it is completely determined by samples taken at any rate

fs>2Bf_s > 2B

Half the sample rate, fs/2f_s/2, is the Nyquist frequency: the highest frequency the system can represent.

Definition: A signal with no energy above some frequency is called band-limited. The theorem says nothing at all about signals that are not, and no real signal ever is exactly. Band-limiting a signal is therefore something you must do to it, not something you can hope it already satisfies.

The factor of two has a simple reading: a sinusoid needs at least two samples per cycle, one for the peak and one for the trough, or you cannot tell how fast it is turning.

3. What breaking it actually does

A frequency above Nyquist does not vanish and does not distort into noise. It reappears at a different, lower frequency, and once it does, nothing distinguishes it from a real signal that was genuinely there.

Sample a sinusoid at ff with rate fsf_s and the recorded frequency is ff folded into the range [0,fs/2][0, f_s/2]: subtract multiples of fsf_s, then reflect any negative result. At the CD rate of 44,100 Hz:

Frequency actually recorded when sampling at 44,100 Hz
recorded frequency (Hz)05k10k15k20k25k5 kHz15 kHz22 kHz30 kHz40 kHz50 kHz60 kHz
Source: Computed by folding f into [0, fs/2] with fs = 44100 Hz

Up to 22,050 Hz the line is honest. Past it, it folds back down and keeps zigzagging. A 40 kHz ultrasonic component lands at 4,100 Hz, squarely in the middle of speech.

4. You have already seen this happen

Aliasing is not an audio curiosity. It is what happens whenever a periodic thing is observed at intervals.

  • Wagon wheels in film. A 24 frames-per-second camera samples a spinning wheel. Above 12 rotations per second the spoke pattern folds, and the wheel appears to slow, stop, or run backwards.
  • Moire in photographs. A fine fabric weave has a spatial frequency above the sensor's pixel Nyquist limit, and folds down into broad coloured bands that were never in the room.
  • Strobe lights. A strobe deliberately undersamples a rotating machine so that the alias sits at 0 Hz and the part appears frozen.
  • Aliased plots. Charting one point per hour from data with a strong 90-minute cycle produces a slow drift that does not exist.

Key idea: Every one of these is the same equation. The alias is real in the recording, so it cannot be removed afterwards. The wheel genuinely does turn backwards in the film.

5. The mistake that cannot be undone

Predict first

A microphone picks up a 30 kHz ultrasonic tone from a nearby sensor. You record at 44.1 kHz, well above the 20 kHz range of human hearing. Is the tone a problem?

This is the practical heart of the lesson. Aliasing is not a rendering artefact you can post-process away, it is information destroyed at the moment of capture. Two different inputs produced the same sample sequence, and no algorithm can recover which one you had.

6. The filter has to come first, and it has to be analogue

Since the damage happens during conversion, the remedy has to sit before it: an analogue low-pass filter in the signal path ahead of the converter, removing everything above Nyquist while it is still continuous. It is called an anti-alias filter, and it is the reason every serious ADC front end has one.

Gotcha: A digital filter cannot do this job. By the time the signal is a list of samples, the folding has already happened. This ordering trips people up constantly, in audio, in imaging, and in sensor pipelines, because the digital filter is the easy one to add and it looks like it should work.

The same rule applies inside a purely digital pipeline. Decimating by keeping every fourth sample lowers fsf_s by four, which lowers Nyquist by four, so anything now above the new limit will fold. scipy.signal.decimate low-pass filters before discarding samples for exactly this reason; a bare slice x[::4] does not, and quietly aliases.

7. Downsampling done correctly

import numpy as np
from scipy import signal

fs = 48000
t = np.arange(fs) / fs
x = np.sin(2*np.pi*1000*t) + np.sin(2*np.pi*9000*t)

# WRONG: 9 kHz is above the new Nyquist of 4 kHz, so it folds to 3 kHz
naive = x[::6]

# RIGHT: filter to below 4 kHz first, then keep every 6th sample
safe = signal.decimate(x, 6, ftype="fir")

After the naive slice the new sample rate is 8 kHz, Nyquist is 4 kHz, and the 9 kHz component folds to 90008000=1000|9000 - 8000| = 1000 Hz, landing exactly on top of the tone you wanted to keep. The correct version removes it beforehand, so it is simply gone rather than disguised.

8. Why sample rates are higher than the theorem requires

Human hearing tops out around 20 kHz, so the theorem asks for anything above 40,000 samples per second. The CD standard chose 44,100. The extra is not a safety margin against the mathematics, which is exact; it is room for the filter.

Sample rateNyquistTransition band above 20 kHzFilter demanded
40 kHz20 kHz0 Hzimpossible
44.1 kHz22.05 kHz2,050 Hzvery steep
96 kHz48 kHz28,000 Hzgentle

An ideal filter that passes 20 kHz untouched and blocks 20,001 Hz entirely does not exist in analogue components. Real filters roll off over a finite width, so you buy that width by sampling faster than the minimum. That, rather than any audible content above 20 kHz, is the honest engineering argument for high-rate recording.

9. Getting the signal back out

Reconstruction is the other half of the theorem, and it is not "join the dots". The exact formula sums a scaled sinc function centred on every sample:

x(t)=n=x[n]sinc ⁣(tnTsTs)x(t) = \sum_{n=-\infty}^{\infty} x[n] \, \mathrm{sinc}\!\left(\frac{t - nT_s}{T_s}\right)

Each sinc is 1 at its own sample and exactly 0 at every other sample instant, so the sum passes through all the measured points while filling the gaps with the unique band-limited curve that fits them.

In practice: A real digital-to-analogue converter cannot use an infinitely wide sinc, so it holds each sample for one period, a zero-order hold that produces a staircase, and then smooths it with a reconstruction filter. The staircase you sometimes see drawn as "what digital audio looks like" is an intermediate stage inside the converter, not the output.

10. The checklist

Everything in this lesson reduces to four questions you can ask of any pipeline that turns a continuous quantity into numbers.

  1. What is the highest frequency present in the source? Not the highest you care about, the highest that exists. Ultrasonic sensors, switching power supplies and fluorescent lighting all inject content people forget about.
  2. Is there an analogue filter before the converter? If not, everything above Nyquist is folding in right now.
  3. Does any stage change the rate? Every decimation is a new Nyquist limit and needs its own filter first.
  4. Does the sample rate leave room for a realisable filter? The theorem's bound is a floor, not a target.

Aliasing is unusual among engineering failures in that it is entirely predictable, completely preventable, and utterly unfixable once committed.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. A 30 kHz tone is sampled at 44.1 kHz. What frequency appears in the recording?
    • 30 kHz, correctly recorded
    • 22.05 kHz, clipped at Nyquist
    • 14.1 kHz
    • Nothing: it is above Nyquist and is discarded
  2. Why must an anti-alias filter be analogue and sit before the ADC?
    • Digital filters cannot implement a low-pass response
    • Analogue filters have better numerical precision
    • The ADC needs a smoothed input to avoid quantisation noise
    • Once sampling has happened the folding is already baked into the samples and cannot be reversed
  3. You take a 48 kHz signal and keep every 6th sample with x[::6]. What is the new Nyquist frequency?
    • 4 kHz
    • 24 kHz
    • 8 kHz
    • 48 kHz
  4. Why did the CD standard pick 44.1 kHz rather than the 40 kHz the theorem requires for 20 kHz audio?
    • Because the sampling theorem is only approximate in practice
    • To leave a transition band in which a realisable analogue filter can roll off
    • Because human hearing actually extends to 22 kHz
    • To improve frequency resolution in the resulting spectrum
  5. A wheel filmed at 24 fps appears to rotate slowly backwards. What is happening?
    • Motion blur is confusing the eye rather than the camera
    • The camera shutter is out of phase with the wheel's illumination
    • The frame rate is too low, so the rotation frequency folds and appears as a lower, negative-going one
    • The film is being played back at the wrong speed

Related lessons

Math
intermediate

Reading a Spectrum Without Fooling Yourself

A spectrum shows you artefacts of the analysis alongside the signal, and telling them apart is a learnable skill. This lesson covers spectral leakage, what windows buy and what they cost, why zero-padding does not add resolution, and the hard trade a spectrogram forces between knowing when and knowing what.

10 steps·~15 min
Math
intermediate

Convolution and Filters: Shaping a Signal

A filter is fully described by what it does to a single impulse, and applying it is a convolution. This lesson builds that idea, shows why the frequency domain turns convolution into plain multiplication, and works through the trade-offs that make real filters ring, lag, or cost more than they need to.

10 steps·~15 min
Math
intermediate

The Frequency Domain: Why Everything Is Sinusoids

The same signal can be written as a function of time or as a recipe of frequencies. This lesson explains why sinusoids in particular get that job, builds the discrete Fourier transform, and shows how the FFT turned a quadratic computation into one you can run on a million samples in a fraction of a second.

10 steps·~15 min
Programming
intermediate

How Profilers Work, and How to Read a Flame Graph

A profiler is not a neutral observer: sampling and instrumentation see different things, distort the program in different ways, and answer different questions. This lesson covers how each works, why CPU time and wall-clock time give opposite answers, and how to read a flame graph correctly, including the axis that means nothing and is misread constantly.

7 steps·~11 min