From a smooth wave to a row of dots
The whole sensors rung worked to hand you one thing: a clean analog voltage — a transducer's reading, conditioned and amplified into a smooth wave that glides between the supply rails. But a microcontroller cannot hold a smooth wave. It deals only in numbers, taken one at a time. Sampling is the act of bridging that gap: you measure the voltage at regular instants and write down each value as a number. Picture a movie camera freezing continuous motion into 24 still frames every second — sampling does exactly that to a voltage, turning a flowing curve into a row of dots.
Two numbers describe how you sample. The sample rate fs is how many samples you take per second (in hertz, or samples/second); its inverse is the sample period Ts = 1/fs, the time gap between consecutive dots. Sample at fs = 1000 Hz and you grab one value every Ts = 1 ms. Crank fs up and the dots crowd closer, hugging the curve tightly; let fs sag and the dots spread out, until between them the wave can do anything and you would never know. The central question of this whole rung is hiding right there: how many dots do you actually need?
How often is often enough? Nyquist's answer
Start with the simplest signal, a pure sine wave. To pin down its frequency you need to catch at least its rise and its fall — at least two samples per cycle. One sample per cycle could land on the same point of the wave every time and report a flat line; you would miss the oscillation entirely. This intuition is exactly the Nyquist-Shannon sampling theorem: to capture a signal faithfully, your sample rate must be more than twice the highest frequency present, fs > 2 times fmax. The dividing line fs/2 has its own name, the Nyquist frequency — the highest frequency your chosen rate can honestly represent.
Real numbers make it concrete. Human hearing tops out near 20 kHz, so to record audio you must sample above 40 kHz — which is why the CD standard chose 44.1 kHz, putting the Nyquist frequency at 22.05 kHz with a little headroom above 20 kHz. A telephone only needs to carry speech up to about 3.4 kHz, so 8 kHz sampling (Nyquist 4 kHz) is plenty and saves bandwidth. The pattern is always the same: decide the highest frequency you genuinely care about, then sample comfortably more than twice that.
system sample rate fs Nyquist fs/2 honestly captures up to ------------------------------------------------------------------------------- telephone voice 8 kHz 4 kHz ~3.4 kHz speech CD audio 44.1 kHz 22.05 kHz 20 kHz (limit of hearing) studio audio 96 kHz 48 kHz extra filter headroom hobby MCU ADC ~10 kHz ~5 kHz slow sensor signals rule: fs > 2 x fmax Nyquist frequency = fs / 2
Be honest about the fine print. The theorem says strictly greater than twice, not equal: sample a sine at exactly 2 times its frequency and your dots can land on its zero crossings every time, reporting a dead flat zero. The theorem also assumes the signal is perfectly band-limited (contains nothing above fmax) and that reconstruction uses an ideal mathematical filter — both are ideals we only approach in practice. That gap between the clean theorem and the messy world is exactly why the next two ideas, aliasing and the anti-alias filter, exist.
Break the rule and the wheel spins backwards
You have seen what happens when you violate Nyquist, even if you did not know its name: the stagecoach wheel in an old western that appears to spin slowly backwards. The film samples the spokes only 24 times a second; the wheel turns faster than that, so each frame catches the spokes a little before where the eye expects, and the brain reads a slow reverse rotation that is not really there. Sample a signal too slowly and a high frequency disguises itself as a low one. This impostor is called aliasing — a frequency above Nyquist folds back and shows up as a phantom below it.
Put numbers on it. Sample at fs = 44.1 kHz, whose Nyquist is 22.05 kHz, and feed in a 30 kHz tone — above the line. It folds down to fs - fin = 44.1 - 30 = 14.1 kHz and appears as a clean, audible 14.1 kHz tone sitting right in the middle of your music. Here is the part that makes Nyquist non-negotiable: once that 30 kHz tone has aliased to 14.1 kHz, it is bit-for-bit identical to a real 14.1 kHz tone. No filter, no clever math, no later processing can ever separate them again. The damage is done at the instant of sampling.
Freezing a moving target: the sample-and-hold
There is a practical wrinkle the clean theorem skips. A real analog-to-digital converter does not measure instantly — it takes time to compare the voltage and settle on a number. If the input keeps moving during that conversion, which value did it actually capture? The answer is a smear. The fix is a sample-and-hold circuit sitting in front of the converter: it grabs the voltage at one clean instant and freezes it stock-still while the ADC does its work on a target that no longer moves.
The mechanism is beautifully simple, and you already understand its heart. A switch connects the input to a small capacitor — that tiny rechargeable bucket that resists sudden changes in voltage. While the switch is closed (the track phase) the bucket fills until its voltage matches the input. Then the switch snaps open (the hold phase) and, with nowhere for its charge to go, the bucket sits there holding that exact voltage steady for the ADC to read at leisure. A buffer on each side keeps the bucket from loading the source or sagging into the converter.
- Track: close the switch so the hold capacitor charges to follow the input. Allow enough acquisition time for the bucket to fill fully — too short and you freeze a value that never caught up.
- Hold: open the switch at the chosen sampling instant. The capacitor now holds that voltage; the smaller the aperture (the time the switch takes to actually open), the more precisely you pinned the moment in time.
- Convert: while the value sits frozen, the ADC compares and digitizes it into a number. The held voltage must droop only negligibly over this whole interval.
- Repeat: close the switch again for the next sample, one full cycle every sample period Ts = 1/fs. The cadence of these cycles is your sample rate.
The round trip: sampling in, reconstruction out
Sampling is only half the journey. Once the numbers have been processed, you often want an analog signal back out — audio to a speaker, a control voltage to a motor. That is the job of the digital-to-analog converter: it turns each number back into a voltage, producing a blocky staircase that holds each level for one sample period. A final reconstruction filter — another low-pass, the mirror image of the anti-alias filter — smooths that staircase back into the gentle curve it came from. Filter, sample, process, convert, filter: the round trip is symmetric on both ends.
Keep this guide's scope honest. We have only fixed the time axis — when to take each sample, and the unbreakable rule that governs it. We have said nothing yet about the voltage axis: how finely each captured value is measured, how many distinct levels the converter can tell apart. That is quantization and resolution, the subject of the third guide in this rung. The two axes are independent — you can sample fast yet measure coarsely, or slowly yet finely — and a real converter is rated on both.
One last piece of designer's judgment to carry forward. In theory fs just over 2 times fmax suffices, but no real anti-alias filter falls off the cliff instantly — a sharper filter costs ripple and phase distortion, and gentle ones need room to roll off. So practitioners sample at 2.5 to 4 times fmax (or far higher), buying the filter breathing space. Deliberately sampling well above the minimum is called oversampling, and it does more than ease the filter — it can be traded for better noise performance, the clever heart of the sigma-delta converter you will meet at the end of this rung. For now, the foundation is set: sample fast enough, filter before you do, and freeze each value before you read it.