Lite / Intelligent Robotic Systems / Week 22
Sampling and the Nyquist rate
A computer can't watch a signal continuously; it takes snapshots. How many snapshots a second are enough to catch a 50 Hz hum?
Why should I care?
Every digital sensor reading is a sample. Choosing how often to sample is a real design decision: too slow and the data lies about what happened; too fast and you waste power, memory and processor time. The Nyquist rate is where that decision starts.
- Describe sampling as measuring a signal at regular intervals 1/fs apart.
- State the Nyquist rate (2 × the highest frequency) and why sampling must exceed it.
- Choose a practical sample rate with a margin above the Nyquist rate.
Predict
You sample a 10 Hz sine wave at exactly 10 Hz. What do the samples look like?
- A perfect 10 Hz wave
- A constant value: the wave seems to have vanished
- A 20 Hz wave
Guess first, then reveal
Sampling once per cycle catches the wave at the same point every time, so every sample is identical: a flat line. You need more than two samples per cycle to see a wave at all.
Discover
Turn on sampling. Set f = 4 Hz and slowly lower fs from 40 Hz. Watch the dashed curve that fits the samples. At what fs does it stop matching the true wave? Repeat for f = 7 Hz. What is the rule?
What the interactive shows (text version)
The signal scope samples a sine wave at a chosen rate. For f = 4 Hz, sample rates above 8 Hz give orange dots that follow the wave, and the dashed best-fit curve matches it. Below 8 Hz the dashed curve becomes a slower, different wave: at fs = 6 Hz the samples look like a 2 Hz wave.
Understand
Samples, not signals
A sampler measures the signal every Tₛ = 1/fₛ seconds, where fₛ is the sample rate in hertz. Between samples the computer knows nothing. Any two signals that agree at every sample instant are indistinguishable afterwards, however different they were in between.
The Nyquist rate
To capture a sine wave of frequency f, you need more than two samples per cycle: fₛ > 2f. For a signal whose highest frequency is f_max, the Nyquist rate is 2·f_max. Equivalently, a given fₛ can faithfully represent frequencies only up to fₛ/2, called the Nyquist frequency.
Margins in practice
Exactly 2f is a knife edge: sampled at the wrong phase, a wave right at the limit can vanish. Engineers sample with a comfortable margin, often 5–10 times the highest frequency of interest for control and monitoring, and use an analogue filter to remove anything above fₛ/2 before sampling.
Explain it another way
Intuitive
Photographing a spinning fan once per turn makes it look still. Photograph it a few times per turn and you can see which way it spins.
Technical
Sampling x(t) gives x[k] = x(k/fₛ). The Nyquist–Shannon sampling theorem: a signal containing no frequencies at or above fₛ/2 is completely determined by its samples and can be reconstructed exactly in principle.
Mathematical
sin(2πf·k/fₛ) depends only on f/fₛ modulo 1 (and its sign), so frequencies f and f ± m·fₛ give identical samples. Only the band 0 ≤ f < fₛ/2 is unambiguous.
Applied
Audio CDs sample at 44.1 kHz because human hearing reaches about 20 kHz; 2 × 20 kHz = 40 kHz, plus a margin for a practical filter.
Worked example 1
A wheel encoder produces pulses at up to 300 Hz. What is the Nyquist rate, and what would you choose?
Nyquist rate = 2 × 300 = 600 Hz. A sensible choice is around 3–6 kHz so each pulse is seen several times and timing is precise.
Common mix-ups
Sampling at exactly twice the frequency is enough.
✓ You need more than twice; at exactly 2f a wave can vanish if sampled at its zero crossings.Sampling faster always gives better data.
✓ Above a comfortable margin it mostly adds cost, and noise above the band of interest still needs filtering.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
A walking robot's leg sensors should capture gait (about 2 Hz) and foot impacts (energy up to 80 Hz). Pick a sample rate, justify it from the Nyquist rate with a margin, and estimate how many bytes per minute you'd log for six 16-bit sensors.
Reflect
Describe something in everyday life that is 'sampled' (photos, register at school, a weekly weigh-in) and what it could miss.
Write your answer on paper or in your own notes. Lite never stores what you write.