TactivergeLite

Lite / Building Machines That Respond / Week 22

Sampling: how often is often enough?

In films, a fast car's wheels sometimes seem to spin backwards. What has that got to do with a temperature sensor?

About 30 min · 3 goals · Checked by automated tests · Full interactive version

Why should I care?

A digital system only knows the world at the moments it takes samples. Sample too slowly and it does not just miss detail: it sees things that are not there. Choosing a sample rate is one of the first decisions in any sensing project.

Predict

A signal goes up and down 9 times a second. You sample it 10 times a second. What wave do your samples seem to show?

  1. A 9 Hz wave, just a bit rough
  2. A slow wave of about 1 Hz
  3. A flat line
Guess first, then reveal

Each sample lands a little later in the cycle than the last, so the samples creep slowly round the wave and trace a false **1 Hz** wave (10 − 9 = 1). This is **aliasing**, the same trick that makes film wheels turn backwards.

Discover

Set the signal to 9 Hz and the sample rate to 10 Hz. Untick the real signal: what do the dots show? Now raise the sample rate until the readout stops warning you. How many samples per cycle did that take?

What the interactive shows (text version)

In the signal lab, a 9 Hz wave sampled 10 times a second gives dots that trace a slow 1 Hz wave: the readout warns that there are fewer than 2 samples per cycle. Raising the sample rate above 18 Hz removes the warning, and around 40–60 Hz the dots clearly follow the real wave's shape.

You can also open the interactive on the full site when you have a faster connection.

Watch (optional)

Watch for: Notice that the camera takes separate pictures (samples). Ask: how far does the wheel turn between two frames?

The wagon-wheel effect: a camera samples too slowly for a fast wheel, so the frames show a slow, false motion. Aliasing you have already seen.

“Why do car wheels spin backwards on video?” by Javier Mota (opens YouTube; streaming video uses a lot of data)

The video is optional. Everything you need is in this lesson's text.

Understand

Rate and period

The sample rate fs is samples per second (Hz); the sample period is the time between samples, 1 ÷ fs. A greenhouse logger sampling at 0.1 Hz takes one reading every 10 s; an audio recorder at 44,100 Hz takes one every 22.7 µs. Samples recorded = rate × duration: 50 Hz for 60 s gives 3,000 samples.

Samples per cycle

Divide the sample rate by the signal frequency to get samples per cycle. Ten or more show the wave's shape clearly. Between two and about five catch the frequency but the shape looks rough. Fewer than two per cycle cannot represent the wave at all. So a signal with frequency f needs a sample rate of more than 2f: half the sample rate is the highest frequency you can capture.

Aliasing and how to avoid it

When a signal is too fast for the sample rate, its samples line up into a slower, false wave: an alias. A 9 Hz wiggle sampled at 10 Hz pretends to be 1 Hz, and no maths afterwards can tell the difference. Engineers prevent it by sampling fast enough for every frequency present and by filtering out faster wiggles (like mains hum) before the ADC.

Explain it another way

Intuitive

Imagine photographing a spinning fan with a flash once a second. If it spins almost exactly once between flashes, each photo shows it nearly still, creeping slowly: your photos tell a lie about its speed.

Technical

The Nyquist–Shannon sampling theorem: a signal containing no frequencies at or above fs/2 can be reconstructed from its samples. Anti-aliasing filters (low-pass) remove content above fs/2 before conversion.

Mathematical

Sample period = 1/fs. Samples per cycle = fs/f; need fs/f > 2. A sine of frequency f sampled at fs appears at |f − k·fs| for the nearest whole number k: 9 Hz at 10 Hz → |9 − 10| = 1 Hz.

Applied

Music is sampled at 44.1 kHz because people hear up to about 20 kHz: 44.1 > 2 × 20. A motor vibration monitor sampling too slowly can report a slow wobble that is not really there.

Worked example 1

You want to measure 50 Hz mains hum on a sensor line. What is the slowest sample rate that could possibly capture it, and what would you actually choose?

More than 2 × 50 = 100 Hz is the bare minimum. To see the shape you might choose 1,000 Hz: 20 samples per cycle.

Worked example 2

A logger samples at 250 Hz for 30 s. How many samples?

250 × 30 = 7,500 samples.

Common mix-ups

Practice

Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.

samples

samples

ms

Hz

Practice 5. A heart-rate signal contains rhythms up to 3 Hz. Which sample rate is the smallest that could work?

Apply it

Pick sample rates for three sensors in the greenhouse: air temperature (changes over minutes), a fan's speed sensor (pulses up to 40 times a second) and a microphone listening for a failing pump bearing (sounds up to 5 kHz). Justify each with the 'more than twice' rule and a margin.

Reflect

Where have you seen aliasing in real life (screens, fans, wheels, strobe lights)? Explain it with samples per cycle.

Write your answer on paper or in your own notes. Lite never stores what you write.

← Signals: smooth waves and stored numbersADC counts, quantisation and noise →