DSP from Scratch · Lesson 3

Why Wheels Spin Backwards on Video: Spectrum, Aliasing and Nyquist

Why a computer, like a camera, can be fooled by a fast wave, and the one rule that stops it.

  • 12 min video
  • 10 min read
  • Lab and checks
Watch on YouTube
Chapters18 parts, tap one to jump there

In one sentence

Measure at more than twice the highest frequency, or the dots will lie.

Watch first, then read. The video shows every idea moving. These notes write out each step so you can check the maths at your own pace. Press any ▶ time button to jump the video to that moment.

Have you ever watched a video of a moving car and noticed the wheels spinning backwards? The car is clearly going forwards. So what is going on?

A camera does not film smoothly. It takes separate pictures, about thirty every second. If the wheel turns almost a full circle between two pictures, it looks as if it moved back a little.

A computer measuring a signal can be fooled in exactly the same way: a fast wave can disguise itself as a slow one. That is called aliasing, and by the end of this lesson you will know how to stop it, and why the music on a CD is measured 44,100 times every second.

Quick recap

  • A digital signal is a list of measurements, taken at regular moments. The number of measurements each second is the sample rate (lesson 1).
  • A sine wave is the smooth up-and-down shape. Its amplitude is how tall it is; its frequency is how many cycles it completes each second, in hertz (Hz) (lesson 2).

Build a signal from two sine waves

Real signals rarely look like one clean sine wave. Here is a wobbly one. It looks messy, but it is hiding something simple: it is just two sine waves added together, a big slow one at 10 Hz and a small fast one at 60 Hz.

How do you add two waves? Pick a moment in time. Take the height of the slow wave, then stack the height of the fast wave on top: where it lands is the total. Do that at every moment. Where both waves are up, the total goes higher; where one is up and the other down, they partly cancel.

slow: 10 Hzfast: 60 Hzadded0 s0.2 s
At every moment, stack the height of the fast wave on top of the slow one. The messy shape is just the two added together.

Turn the fast wave down and the ripples fade away; turn it back up and they return. The slow wave never changed.

The spectrum: a list of ingredients

This suggests a completely different way to describe a signal. Instead of drawing its height over time, list its ingredients: which sine waves are inside, and how big each one is.

Each sine wave becomes a single bar. The bar’s position shows its frequency; its height shows its amplitude. The big slow wave becomes a tall bar at 10 Hz, and the small fast wave a short bar at 60 Hz. This picture is called a spectrum.

01020304050607080frequency (Hz)amp.slow wave: 1fast wave: 0.3
The same signal as a list of ingredients. The axis along the bottom is frequency, not time.

Spectra in real life

You have probably seen a spectrum before. The bouncing bars in a music app are a live spectrum of the song: bars on the left are low sounds like a bass drum, bars on the right high sounds like cymbals.

Spectra also explain why instruments sound different. A flute and a guitar can play the same note, with the same main frequency. But the guitar adds stronger extra waves at two and three times that frequency, called harmonics. Same note, different ingredients, so a different sound. Your ears are reading the spectrum all the time.

Two bars, and nothing else: a tall bar of height 2 at 50 Hz, and a short bar of height ½ at 200 Hz.

050100150200250frequency (Hz)amp.20.5

The spectrum of the practice signal: one bar per sine wave.

Measuring too slowly

Back to measuring. The computer only ever sees the dots. Measure the 60 Hz wave 360 times a second and the dots follow it closely. Now measure only 80 times a second.

0 s0.1 s
real wave: 60 Hzwhat the dots suggest: 20 Hzthe 9 measurements
Measured 80 times a second, the 60 Hz wave leaves dots that a slow 20 Hz wave also passes through. From the dots alone, the computer cannot tell which was there.

Join these dots with the smoothest curve you can, and you get a slow wave of only 20 cycles a second. The dots are telling a lie. And here is the problem: both waves pass through every single dot. Looking only at the dots, the computer cannot tell which wave was really there.

This is aliasing: a fast wave pretending to be a slower one. An alias is a false name, and that is exactly what our 60 Hz wave is using.

The spinning wheel, explained

Think of the 60 Hz wave as a wheel making 60 turns a second. Measuring 80 times a second is like a flash going off 80 times a second. Between flashes the wheel turns

6080=34 of a turn\frac{60}{80} = \frac{3}{4}\ \text{of a turn}

But three quarters of a turn forwards lands in the same place as a quarter turn backwards. So the wheel seems to creep backwards: a quarter turn per flash, 80 flashes a second, 14×80=20\frac{1}{4} \times 80 = 20 turns a second. That is why the false 20 Hz wave starts by going down instead of up: it is running backwards.

flash 1flash 2flash 3flash 4flash 5each flash: ¾ turn forwards looks like ¼ turn backwards
The wheel really turns ¾ of a turn forwards between flashes (the dotted circle is where the spoke was). The eye picks the shorter move: ¼ of a turn backwards, 20 turns a second.

The rule, and the Nyquist frequency

So how fast must we measure? Raise the sample rate slowly and see what the dots say. At 80 measurements a second they say 20 Hz; at 100 they say 40 Hz, still wrong. Only once we pass 120 a second do the dots finally show the true 60 Hz. And 120 is exactly twice 60.

That is the rule. To capture a wave properly you need more than two measurements in every cycle, so

fs>2 Fmax⁡f_s > 2\,F_{\max}

where fsf_s is the sample rate and Fmax⁡F_{\max} is the highest frequency in the signal.

Half the sample rate has a special name, the Nyquist frequency, after the engineer Harry Nyquist:

Nyquist frequency=fs2\text{Nyquist frequency} = \frac{f_s}{2}

Frequencies below it are captured safely. Anything above it turns into an alias: it folds back like a mirror image. At 80 measurements a second the Nyquist frequency is 40 Hz. Our 60 Hz bar is 20 Hz above the line, so it folds back and lands 20 Hz below it, at 20 Hz: exactly the false wave we saw.

above Nyquist: folds backsafeNyquist = 80 ÷ 2 = 40 Hz01020304050607080real: 60 Hzalias: 20 Hz
60 Hz is 20 Hz above the Nyquist frequency, so it folds back like a mirror image and lands 20 Hz below it: at 20 Hz.

For a frequency between the Nyquist frequency and the sample rate, the alias is simply fs−Ff_s - F. Here, 80−60=2080 - 60 = 20 Hz.

Why exactly twice is not enough

Why more than twice, and not exactly twice? Measure our 60 Hz wave exactly 120 times a second and you might catch it only as it crosses zero: every dot is zero, and the wave vanishes. Shift the timing a little and you would catch the peaks instead. At exactly twice, the result depends on luck, which is why engineers always leave extra room.

Unlucky timing

Every dot lands on a zero crossing. The wave vanishes.

Lucky timing

Shift the timing a little and the dots catch the peaks.

The same 60 Hz wave, measured exactly twice per cycle. Whether the dots show it at all depends on when the measuring starts.

Anti-aliasing filters

There is one more danger. Real signals can carry fast ingredients you never wanted, like hiss or electrical interference. If they are above the Nyquist frequency, they fold back and land right among the frequencies you care about. Once that happens it cannot be undone: the measurements are already mixed up, and no later calculation can separate them.

So the signal first goes through an anti-aliasing filter. A filter is a circuit that lets some frequencies through and blocks others; this one removes anything too fast before the measurements are taken.

Real life: CDs and phone calls

Now we can answer the question from the start. Human hearing goes up to about 20,000 Hz. Twice that is 40,000 measurements a second.

Sample rateNyquist frequencyHighest sound needed
Music on a CD44,100 a second22,050 Hzabout 20,000 Hz (hearing)
Traditional phone calls8,000 a second4,000 Hzabout 3,400 Hz (clear speech)

In both cases the Nyquist frequency sits a little above the highest sound needed. The gap in between gives the filter room to work.

More than 2×8,000=16,0002 \times 8{,}000 = 16{,}000 measurements a second. In practice, use a bit more, with an anti-aliasing filter in front.

Three common mistakes

Recap

  • Any signal can be built from sine waves.
  • A spectrum lists those ingredients: frequency along the bottom, amplitude as the height of each bar.
  • Measure too slowly and a fast ingredient takes a false name: aliasing.
  • The Nyquist frequency is half the sample rate; anything above it folds back.
  • To prevent aliasing, measure at more than twice the highest frequency, and filter out anything faster first.

Say the main idea aloud once: measure at more than twice the highest frequency, or the dots will lie.

Interactive lab

Fool the computer

Choose how fast a wave really wiggles and how often you measure it. Watch the dots tell the truth, then lie, and see a wheel lit by the same flashes turn the wrong way.

Sign in to open the lab

It is free. Signing in with Google also keeps your progress and your scores.

Sign in with Google

Lesson 1 of every course is open without signing in.

Check yourself

Did it stick?

Work each one out on paper first. Every question has a full worked answer.

  1. 1

    A spectrum has three bars, at 50, 150 and 250 Hz. How many sine waves are in the signal?

  2. 2

    A recorder takes 48,000 samples a second. What is its Nyquist frequency?

  3. 3

    Is 500 samples a second enough to capture a 300 Hz wave?

    Question 3: pick one answer

  4. 4

    A 70 Hz wave is measured 100 times a second. What frequency do the dots suggest?

  5. 5

    You want to record sounds up to 12,000 Hz. Which plan works?

    Question 5: pick one answer

Sign in to open the checks

It is free. Signing in with Google also keeps your progress and your scores.

Sign in with Google

Lesson 1 of every course is open without signing in.

Free weekly email

Get the next lesson by email.

The week's new lessons, the daily facts in one place, one thing to try in the lab and one puzzle. Free.

No spam. One click to leave.