Sensors & Signal Processing
What is aliasing, and what is the Nyquist rate?
Aliasing happens when a signal is sampled too slowly: a fast change shows up in the samples as a slower one, or even one going backwards. The Nyquist rule says to capture a signal truly you must sample at more than twice its highest frequency. Sample a wheel turning 9 times a second at 10 samples a second and it seems to turn once a second, backwards.
The backwards wheel
Watch a wheel turning 9 times a second, but only glance at it 10 times a second. Between glances it turns 0.9 of a turn, which looks exactly like 0.1 of a turn backwards. Glance after glance it creeps back a tenth of a turn: 1 turn a second, backwards. Glance exactly 9 times a second and it's in the same place every time: it seems to stand still. That's how a strobe light freezes a fan, and why wagon wheels spin backwards in films.
Live experiment
The backwards wheel
A wheel turns 9 times a second and the program samples it at a rate you pick. Every 100 ms the samples show it creeping round backwards once a second; every 111 ms it stands still; every 20 or 10 ms you see the true 9 turns a second.
“The backwards wheel” is lesson 1 of 6 in Alias Atoll, Sensors & Signal Processing World 3. Free with an account. Lessons unlock in order, so you’ll do the 13 before it first.
The rule
A sampler can only tell apart frequencies below half its sample rate, the Nyquist frequency. Anything faster folds back and lands on a lower frequency, its alias:
where fs is the sample rate and n is the whole number that makes the answer smallest. For the 9 Hz wheel at 10 samples a second, that's |9 − 10| = 1 Hz. Turned round, the rule says how fast to sample:
To see the 9 Hz wheel truly, sample more than 18 times a second. In practice go well past that, 50 or 100, so each turn gets several samples.
Preventing it
Two things, together. Sample fast enough for the highest frequency you care about. And put an anti-aliasing filter, a low-pass filter, in front of the sampler, so nothing above half the sample rate reaches it: mains hum, motor noise or a vibration you didn't know was there. Many sensor chips build one in.
Where you'll meet it
A music CD stores 44,100 samples a second, so it can hold sounds up to 22,050 Hz, just above the 20,000 Hz that young ears hear. An Arduino reading a vibrating sensor with delay(15) between reads samples about 67 times a second, so anything above about 33 Hz will alias. Control loops follow the same rule of thumb from the other side: run the controller many times faster than the fastest wobble it has to stop, often ten times.
Free lesson
Now build it yourself
Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.
“The backwards wheel” is lesson 1 of 6 in Alias Atoll, Sensors & Signal Processing World 3. Free with an account. Lessons unlock in order, so you’ll do the 13 before it first.
Or start from the very first lesson, no account neededPractice questions
Three quick questions from the lessons. Pick an answer to check it.
Show the answer
Answer: Standing still: each sample catches it in the same place. One sample per turn finds the spoke in the same spot every time. That's how a strobe light makes a fan look frozen.
- Why not “Going backwards fast”? Going backwards needs each sample to land slightly short of a whole turn. Exactly one turn per sample looks still.
- Why not “Turning 10 times a second”? Each sample catches the wheel in the same place, so the samples hold no sign of movement at all.
- Why not “Turning 20 times a second”? Samples can't show more turns than happen between them; one sample per turn makes it look frozen.
Show the answer
Answer: 30 a second. 30 is less than twice 20. The others are all over 40.
- Why not “50 a second”? 50 a second is more than twice 20, so it captures the wheel truly.
- Why not “100 a second”? 100 a second is five times 20, comfortably above the Nyquist rate.
- Why not “200 a second”? 200 a second is ten times 20, far above the 40 needed.
Show the answer
Answer: Several times faster than the fastest wobble it has to stop. Ten times faster is a common target. Run too slowly and every correction arrives late, just like a lagging sensor.
- Why not “Slower than the wobble”? Slower than the wobble, the samples can't see it properly, and every correction arrives late.
- Why not “Once a second”? Once a second is far too slow for most systems; the right rate depends on how fast things change.
- Why not “Exactly as fast as the wobble”? Sampling at exactly the wobble's rate catches it at the same point each time, so it looks frozen.
“The backwards wheel” is lesson 1 of 6 in Alias Atoll, Sensors & Signal Processing World 3. Free with an account. Lessons unlock in order, so you’ll do the 13 before it first.
Questions people ask
What is the Nyquist rate?
Twice the highest frequency in a signal. To capture the signal without aliasing, you must sample faster than that. A signal with nothing above 9 Hz needs more than 18 samples a second; audio up to 20 kHz needs more than 40,000.
What is the difference between the Nyquist rate and the Nyquist frequency?
The Nyquist rate is a property of the signal: twice its highest frequency, the slowest safe sample rate. The Nyquist frequency is a property of the sampler: half its sample rate, the highest frequency it can capture.
How do you prevent aliasing?
Sample well above twice the highest frequency present, and put a low-pass anti-aliasing filter before the sampler to remove anything faster than half the sample rate. Once a signal has aliased, no processing afterwards can undo it.
Why do wheels look like they spin backwards on video?
A camera samples the scene, often 24 to 60 times a second. If a wheel turns slightly less than a whole spoke-gap between frames, each frame catches the spokes a little further back, so they seem to creep backwards. That's aliasing.
Related topics
- Low-pass filter explainedA resistor and a capacitor that pass the bass and fade the treble, and where the cutoff sits.
- How a moving average filter smooths a noisy sensorAverage 16 readings for a quarter of the noise, and know what it costs.
- How Arduino analogRead worksHow analogRead turns 0–5 V into 0–1023, and how to scale it for analogWrite.
- How an exponential moving average filter worksNudge a running value a fraction of the way toward each reading.