JOVANA
Library Glossary Getting Started Three Levels Fields How it works Mission
Join the mission
All guides

Sampling, Nyquist and Aliasing: Crossing into Digital

Every song on your phone, every photo, every voice call was once a smooth continuous wiggle in the real world — and then a chip looked at it a few thousand times a second and threw the rest away. Astonishingly, you can rebuild the original perfectly from those snapshots, but only if you obey one hard rule. Break it and you get the wagon wheels that spin backwards in old movies, frozen forever in your data. This is the bridge from the analog signals you've studied to the digital world of DSP, communications and embedded systems.

Looking at a Wave Through a Strobe Light

Picture a dancer spinning in a dark club while a strobe light flashes. You don't see the smooth spin — you see a stack of frozen poses, one per flash. If the strobe is fast, the poses are close together and your brain happily fills in the motion. If it's slow, the dancer can complete most of a turn between flashes, and suddenly she appears to drift slowly the *wrong* way. That illusion is the whole story of digital signal processing in one image, and we are about to make it precise.

Sampling is exactly this strobe. An analog-to-digital converter takes a continuous voltage — a microphone's output, a sensor reading, an antenna's signal — and reads its value at evenly spaced instants, T seconds apart. The rate fₛ = 1/T is the sampling frequency. A CD samples at 44.1 kHz: 44,100 snapshots of the voltage every second. Between snapshots, the converter is blind. The deep question of this rung is: when is that blindness harmless, and when does it corrupt your data forever?

We model the strobe mathematically as multiplication by an impulse train — a row of infinitely thin, infinitely tall spikes spaced T apart, written δ_T(t) = Σ δ(t − nT). Multiplying your signal x(t) by this comb plucks out the values x(nT) and zeros everything in between. That single modeling choice is the key that unlocks the entire theory, because we already know — from the Fourier transform — exactly what multiplication does in the frequency domain.

What Sampling Does to the Spectrum

Here is the beautiful, slightly magical core. Multiplying in *time* by the impulse train is equivalent to *convolving* in *frequency* by another impulse train, this one spaced fₛ apart. The effect is that the entire spectrum of your signal — the picture the Fourier transform gives you of which frequencies are present — gets stamped out over and over, like a printing press, once at DC, once at fₛ, once at 2fₛ, at every multiple of the sampling rate. Sampling doesn't just take snapshots in time; it replicates the spectrum periodically in frequency.

Original baseband spectrum (highest frequency = B):

  |X(f)|
    /\
   /  \
 --+----+------------------------------> f
  -B    B

After sampling at fs  (spectrum replicated at every k*fs):

  |Xs(f)|
    /\        /\        /\        /\
   /  \      /  \      /  \      /  \
 --++---+--++---+--++---+--++---+--++--> f
  -B  B   fs       2fs      3fs
          ^copy    ^copy    ^copy

The gap between each copy's edge and the next is (fs - B) - B = fs - 2B.
Keep that gap positive and the copies never touch.
Sampling stamps the baseband spectrum at every multiple of fₛ. Survival depends on whether the copies overlap.

Now you can *see* the whole problem geometrically. If your signal's highest frequency is B, each copy spans from −B to +B, a width of 2B, and the copies are centered fₛ apart. As long as fₛ is comfortably bigger than 2B, the copies sit in tidy rows with clear gaps between them — and a lowpass filter can later scoop out just the central one to recover x(t) exactly. But if fₛ shrinks toward 2B, the copies slide together until their skirts overlap and fuse. Once they overlap, no filter on Earth can pull them apart again. The damage is permanent.

The Nyquist–Shannon Sampling Theorem

The geometry hands us the theorem on a plate. The copies stop overlapping exactly when each copy's right edge (at B above its center) clears the next copy's left edge (at B below the center fₛ away). That requires fₛ − B > B, i.e. fₛ > 2B. This is the Nyquist–Shannon sampling theorem: a signal containing no frequencies above B can be perfectly reconstructed from its samples if and only if it is sampled faster than 2B. The threshold 2B is the Nyquist rate, and half the sampling rate, fₛ/2, is the Nyquist frequency — the highest frequency your samples can honestly represent.

Shannon's 1949 result goes further than "the copies don't overlap." It hands you an exact reconstruction formula: thread a sinc function through each sample and add them up, and you recover the *entire* continuous waveform between the samples — not an approximation, the real thing. The samples weren't a lossy summary; for a band-limited signal they carry every last bit of information the original held. That is the claim that still feels too good to be true the first time you meet it.

Worked numbers — human hearing tops out near 20 kHz:

  highest frequency B  = 20 kHz
  Nyquist rate  2B     = 40 kHz   <- must sample FASTER than this
  CD audio fs          = 44.1 kHz  -> 44.1 > 40  : safe, 2.05 kHz of guard band
  Telephone band B     = 3.4 kHz
  Telephone fs         = 8 kHz     -> 8 > 6.8     : safe

Why 44.1 and not exactly 40? The extra ~4 kHz is 'guard band' --
room for a real anti-aliasing filter to roll off (it can't be a
perfect brick wall), plus margin so nothing near 20 kHz folds back.
Real systems sample a bit above 2B to leave room for a non-ideal anti-aliasing filter.

Aliasing: The Wagon Wheel That Spins Backwards

Break the rule — sample too slowly — and the spectral copies overlap. A high frequency that *should* live at, say, 0.9·fₛ folds down and lands on top of a low frequency, masquerading as something it isn't. This impostor is an alias, and the failure mode is aliasing. The wagon wheels in old Westerns are the everyday demonstration: the film camera samples the spinning spokes 24 times a second, and when a spoke nearly completes a gap between frames, the wheel appears to creep slowly backwards. The true fast rotation has aliased into a slow, wrong one.

A 7 kHz tone sampled at fs = 8 kHz. Nyquist freq = 4 kHz.
Any f above 4 kHz folds: f_alias = |f - fs| = |7 - 8| = 1 kHz.

True 7 kHz signal:   /\  /\  /\  /\  /\  /\  /\
                    /  \/  \/  \/  \/  \/  \/  \

Sample instants (every 0.125 ms):  x   x   x   x   x

The sampler can't tell these apart -- both pass through the dots:

  the real 7 kHz tone   ........ and a fake 1 kHz tone
       \          /
        *--------*  <- both curves hit EVERY sample point

Your DSP swears it heard 1 kHz. The 7 kHz is gone, replaced by a lie.
Undersampling: a 7 kHz tone reappears as a 1 kHz impostor. No later processing can undo it.

The folding rule is mechanical and worth internalizing: frequencies reflect about the Nyquist frequency fₛ/2 like light off a mirror, then about fₛ, and so on, zig-zagging back into the baseband. A component at fₛ/2 + Δ shows up at fₛ/2 − Δ. This is why a too-cheap audio recorder turns an out-of-band whistle into an in-band warble you can never scrub out — and why aliasing in a camera sensor produces those shimmering rainbow moiré patterns on a striped shirt or a brick wall.

The Anti-Aliasing Filter and the Real ADC

If aliasing can't be fixed afterward, the cure must come first: an analog anti-aliasing filter sitting right in front of the sampler, before the analog-to-digital converter. It is a lowpass filter — pure frequency response engineering — tuned to pass everything below the Nyquist frequency and crush everything above it, so that no out-of-band energy survives to fold back. On a CD recorder it lets 20 kHz through and stamps out the ultrasonic hiss that would otherwise alias into the music.

  1. Anti-alias filter — an analog lowpass removes everything above fₛ/2 so nothing can fold back. Real filters roll off gradually, which is exactly why fₛ is set a little above 2B (the guard band).
  2. Sample-and-hold — a switch and capacitor freeze the voltage at the sampling instant and hold it steady while the converter does its work.
  3. Quantize — the held voltage is mapped to the nearest of 2ᴺ levels for an N-bit converter. This is quantization, and it introduces a small, unavoidable rounding error.
  4. Encode — the chosen level is written out as an N-bit binary code: now it's data, ready for DSP, storage or transmission.

That third step, quantization, is the second clock we promised. Sampling discretizes *time*; quantization discretizes *amplitude*. Rounding each sample to the nearest level injects a tiny error, modeled as added noise, and it sets a ceiling on the dynamic range. The famous rule of thumb is roughly 6 dB of signal-to-noise ratio per bit: 16-bit CD audio buys about 96 dB, enough to put the quietest pianissimo well above the hiss. More bits, finer ruler, quieter noise floor.

Put it together and you have the whole gateway. A continuous signal enters the ADC, passes the anti-alias filter, is sampled above its Nyquist rate, gets quantized to N bits, and emerges as a stream of numbers. From that instant on, everything is arithmetic: a CPU can filter it, compress it, demodulate it, recognize speech in it. The sampling theorem is the guarantee that this stream still *is* the signal — and aliasing is what you get when you take that guarantee for granted.