TactivergeLite

Lite / Textbooks / Signals and Systems / Chapter 3

3. Aliasing: when samples lie

Version 1 · Technically checked (automated checks only) · 4 source lessons · Full interactive version

Introduction

Sample too slowly and a fast signal does not disappear; it disguises itself as a slow one. Wagon wheels in films turn backwards for the same reason. The alias frequency can be predicted exactly by folding the true frequency around multiples of the sample rate. Once aliased, no software can separate the impostor from a real signal, so the cure is an analogue low-pass filter before the sampler.

Figure 3.1. Same dots, two different waves (described in words)

A 900 Hz cosine (thin line) sampled at 1000 Hz. The samples, shown as dots, lie exactly on a 100 Hz cosine (thick line): the 900 Hz signal looks like 100 Hz.

Explanation

Built from 4 School lessons. Each part is the lesson's own explanation.

3.1 Aliasing: when samples tell lies

In films, car wheels sometimes spin backwards while the car speeds forwards. The camera isn't broken. What is it doing?

Aliasing in one sentence

When a signal contains frequencies above fₛ/2, sampling folds them down into the range 0 to fₛ/2, where they look exactly like genuine low-frequency signals. After sampling, nothing can tell them apart: the information is gone.

The wagon-wheel effect

A spoked wheel looks identical after turning by one spoke gap. If, between frames, it turns almost exactly one gap, it looks almost still; slightly less than a gap, it seems to creep backwards. Films at 24 fps, strobe lights and LED lighting that flickers at a fixed rate all create this illusion with real machines.

Preventing aliasing

Prevent it before sampling: an analogue anti-aliasing filter removes frequencies above fₛ/2, or you raise fₛ above twice the highest frequency present. A digital filter after sampling is too late: the alias is already mixed into the band you care about.

Derivation: Where the alias frequency comes from
  1. Sample x(t) = sin(2πft) at instants t = k/fₛ: the samples are x[k] = sin(2πf·k/fₛ).

  2. Add any whole number m of sample rates to the frequency: sin(2π(f + m·fₛ)·k/fₛ) = sin(2πf·k/fₛ + 2πmk). Since mk is a whole number, the extra 2πmk changes nothing.

  3. So f, f ± fₛ, f ± 2fₛ, … all give identical samples: they are aliases of each other.

  4. Also sin(−θ) = −sin(θ), so a frequency −a gives the same samples as +a with the phase flipped. Frequencies are indistinguishable from their mirror images too.

  5. The sampler shows the alias closest to zero: f_alias = |f − k·fₛ|, where k·fₛ is the whole multiple of fₛ nearest to f. It always lies between 0 and fₛ/2.

  6. Example: f = 23 Hz, fₛ = 10 Hz. The nearest multiple is 20 Hz, so f_alias = |23 − 20| = 3 Hz.

  7. Wagon wheel: N identical spokes at r rev/s make a pattern repeating at N·r Hz. Filmed at F fps, it appears to turn at (signed alias of N·r at F) ÷ N rev/s. A negative alias means it seems to turn backwards.

Common mix-ups

Open the Lite lesson: Aliasing: when samples tell lies

3.2 Predicting the impostor

A 900 Hz whistle is recorded at 1 kHz. Play it back and you hear a low hum instead. Exactly what pitch, and why?

Folding

Picture the frequency axis folded like a paper fan at every multiple of fs/2. Any frequency lands somewhere in the first panel, 0 to fs/2. That landing place is the alias. With fs = 100 Hz: 30, 70, 130 and 170 Hz all land on 30 Hz.

Negative aliases and backwards wheels

A film camera at 24 frames/s filming a wheel turning 23 times per second sees it advance 23/24 of a turn per frame: indistinguishable from going back 1/24 of a turn. f − fs = −1 Hz: the wheel seems to turn backwards once per second. For a rotation the sign matters; for a cosine on a graph it does not.

Using the formula as a detective

If a log shows a mystery 30 Hz wobble and you sample at 100 Hz, candidates are 30, 70, 130, 170 Hz… Check the machine for anything at those frequencies, like a motor at 4200 rpm (70 Hz). If you find one, you have caught an alias, and the fix is filtering before sampling or sampling faster.

Derivation: The exact alias formula
  1. Samples of x(t) = cos(2πft) are x[n] = cos(2π·(f/fs)·n).

  2. Adding a whole number of cycles per sample changes nothing: cos(2π(f − k·fs)n/fs) = cos(2πfn/fs − 2πkn) = x[n] for every integer k.

  3. Cosine is even, so a negative frequency gives the same samples as its magnitude: cos(−θ) = cos θ.

  4. Choose k = round(f/fs) so that f − k·fs lies between −fs/2 and +fs/2.

  5. Therefore f_alias = |f − round(f/fs)·fs|, always between 0 and fs/2. (For sine waves the sign of f − k·fs also flips the phase: that is the 'backwards' wheel.)

Common mix-ups

Open the Lite lesson: Predicting the impostor

3.3 Stopping aliases before they start

Every audio interface and many sensor boards put a filter in front of the ADC. If the ADC is digital, why does it need an analog guard?

Filter first, sample second

An anti-aliasing filter is a low-pass filter before the ADC that shrinks everything above fs/2 enough that its aliases are buried below the noise floor. Digital filtering after sampling cannot help: by then the alias sits at an allowed frequency and looks exactly like real signal.

The RC low-pass

A resistor in series and a capacitor to ground form the simplest low-pass. Its cut-off fc = 1/(2πRC) is where the output falls to 1/√2 (−3 dB). Above fc the gain falls roughly as fc/f: −20 dB per decade. With R = 1.6 kΩ and C = 100 nF, fc ≈ 995 Hz.

Oversample, then decimate

Real filters roll off gradually. A common trick: sample much faster than needed (oversample), so a gentle analog filter suffices, then use a sharp digital low-pass and keep every Mth sample (decimation). Delta-sigma audio ADCs work this way internally.

Common mix-ups

Open the Lite lesson: Stopping aliases before they start

3.4 Choosing a sample rate for a real robot

Sampling at 10 kHz is safe but drains the battery. Sampling at 20 Hz is cheap but might lie. How do you pick?

Start from the frequencies

List what the signal contains: the frequencies you want (the tilt, the heartbeat, the wall getting closer) and the ones you don't (motor vibration, mains hum at 50 or 60 Hz, switching noise). The sample rate must exceed twice the highest frequency that reaches the sampler, wanted or not.

Filter, then sample

An analogue low-pass filter in front of the converter cuts unwanted high frequencies so they can't alias. A common digital pattern is oversample, filter, decimate: sample fast, low-pass filter digitally, then keep every Mth sample. The filter must run on the fast samples, before you throw any away.

Count the cost

Data rate = channels × sample rate × bytes per sample. Six 16-bit channels at 1 kHz is 12 kB/s, about 43 MB an hour. Processing cost scales the same way. Control loops also need the delay between sample and action to be small compared with the system's response time.

Common mix-ups

Open the Lite lesson: Choosing a sample rate for a real robot

Worked examples

Aliasing: when samples tell lies: example 1

A 130 Hz vibration is sampled at 100 Hz. What frequency appears?

Solution

Nearest multiple of 100 Hz to 130 Hz is 100 Hz; |130 − 100| = 30 Hz. The log shows a convincing 30 Hz vibration that does not exist.

Aliasing: when samples tell lies: example 2

A 5-spoke wheel turns at 4.6 rev/s, filmed at 24 fps. What do you see?

Solution

Pattern frequency 5 × 4.6 = 23 Hz. Signed alias: 23 − 24 = −1 Hz. Apparent speed −1 ÷ 5 = −0.2 rev/s: slowly backwards.

Predicting the impostor: example 1

A 4200 rpm fan is sampled by a 100 Hz sensor. What vibration frequency appears in the data?

Solution

4200 rpm = 70 Hz. k = round(70/100) = 1, f_alias = |70 − 100| = 30 Hz.

Stopping aliases before they start: example 1

Choose C for an RC anti-aliasing filter with R = 10 kΩ and fc ≈ 160 Hz.

Solution

C = 1/(2π·R·fc) = 1/(2π × 10⁴ × 160) ≈ 99.5 nF, so a standard 100 nF part.

Choosing a sample rate for a real robot: example 1

Mains hum at 50 Hz leaks into a sensor sampled at 52 Hz. What appears?

Solution

|50 − 52| = 2 Hz: a slow, convincing 2 Hz wobble. Either filter the hum out before sampling, sample far faster (e.g. 1 kHz) and filter digitally, or choose fₛ so the hum is easy to spot and remove.

Interactive figures, in words

Figure 3.2 from Aliasing: when samples tell lies

Set 6 spokes at 24 fps. Find a wheel speed where the wheel seems to stand still, one where it creeps forwards and one where it creeps backwards. Step frame by frame. Then use the readout to predict the next 'stand still' speed before you find it.

The wagon-wheel explorer shows six consecutive film frames of a spoked wheel. With 6 spokes at 24 fps: at 4 rev/s every frame looks identical (stand-still); at 3.8 rev/s the spokes step slightly backwards each frame; at 1 rev/s they step forwards by 15 degrees per frame. The readout gives the pattern frequency, the alias and the apparent speed.

Figure 3.3 from Predicting the impostor

Fix fs = 10 Hz. Step f through 3, 7, 13 and 17 Hz and write down the alias each time. What pattern do you see? Predict f = 23 Hz before you try it.

With fs = 10 Hz in the sampler: 3 Hz shows as 3 Hz, 7 Hz as 3 Hz, 13 Hz as 3 Hz and 17 Hz as 3 Hz, because each is 3 Hz away from a multiple of 10 Hz. 23 Hz also shows as 3 Hz.

The interactive versions are in the full chapter.

Laboratory

These run in a browser on the full site (they need a faster connection). Simulations are simplified educational models.

Practice

Each question links to its Lite lesson, where your answer is checked on our server and a wrong answer gets a hint. Answers are never sent to your device.

  1. A 70 Hz signal is sampled at 50 Hz. What is the alias frequency, in Hz?
    Answer it in “Aliasing: when samples tell lies”
  2. An 8-spoke wheel is filmed at 24 fps. What is the slowest non-zero speed at which it appears perfectly still, in rev/s?
    Answer it in “Aliasing: when samples tell lies”
  3. Your logged vibration shows a 30 Hz peak you suspect is an alias. What is the most convincing test?
    Answer it in “Aliasing: when samples tell lies”
  4. A 900 Hz whistle is sampled at 1 kHz. What alias frequency, in Hz, appears?
    Answer it in “Predicting the impostor”
  5. Sampled at fs = 100 Hz, which frequency gives exactly the same samples as a 20 Hz cosine?
    Answer it in “Predicting the impostor”
  6. An RC low-pass has R = 1.6 kΩ and C = 100 nF. What is fc = 1/(2πRC), in Hz (nearest 5 Hz)?
    Answer it in “Stopping aliases before they start”
  7. Why can't a digital filter after the ADC remove aliases?
    Answer it in “Stopping aliases before they start”
  8. Mains hum at 50 Hz is sampled at 45 Hz. At what frequency does it appear, in Hz?
    Answer it in “Choosing a sample rate for a real robot”

Engineering applications

Rolling shutters

Phone cameras read the image row by row, so fast propellers and guitar strings appear bent or frozen. It is aliasing in space and time, and no editing afterwards can recover the true motion.

Anti-aliasing filters

Data acquisition boards put an analogue low-pass filter in front of every ADC. It removes frequencies the sampler cannot represent before they can fold down and pollute the measurement.

Watch (optional)

Streaming video uses a lot of data. Everything you need is in the text.

Summary

Glossary

Sampling and aliasing
Sampling measures a signal at regular intervals. Any frequency above half the sample rate, the Nyquist frequency, is indistinguishable from a lower 'alias' frequency. Field Guide
Low-pass filter (moving average and EMA)
A low-pass filter lets slow changes through and attenuates fast ones. In firmware the simplest are the moving average and the exponential moving average. Field Guide
Frequency and period
Frequency is how many cycles happen per second; the period is the time for one cycle. Each is the reciprocal of the other. Field Guide

Project: Catch an alias

Simulate a vibration sensor that sees a 120 Hz motor whine but samples at only 100 Hz. Predict the alias, show it in a plot of the samples, then design the cheapest fix: a filter cut-off, a new sample rate or both. Justify your choice with numbers.

Deliverables

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

References

← 2. Sampling and the Nyquist rate4. Quantisation and resolution →