Move the sliders to change the tone frequency f and the sample rate fs. When f reaches fs/2 (the Nyquist frequency), the same samples also fit a lower tone: that is aliasing.
original tone samples alias the samples also fit
What to try
- Set f = 30 Hz and fs = 40 Hz: the samples look like a 10 Hz tone (|30 − 40| = 10).
- Raise fs above 60 Hz: the alias disappears.
- Set f = fs: every sample is the same, so the tone looks like DC (0 Hz).
- Set f = 45 Hz and fs = 40 Hz: the samples fit a 5 Hz tone.
How the demo works
The demo samples a cosine at times n/fs, giving \(x[n] = \cos(2\pi f n / f_s)\). Now add any whole multiple of the sample rate to the frequency:
Because \(2\pi k n\) is a whole number of turns, the samples are identical. Every frequency f + k·fs (and, for a real cosine, its mirror −f + k·fs) produces the same numbers. The frequency you actually “see” is the one closest to zero:
The demo uses exactly this formula. Some worked values:
| Tone f | Sample rate fs | k | Alias fa |
|---|---|---|---|
| 30 Hz | 40 Hz | 1 | 10 Hz |
| 45 Hz | 40 Hz | 1 | 5 Hz |
| 7 kHz | 10 kHz | 1 | 3 kHz |
| 40 Hz | 40 Hz | 1 | 0 Hz (DC) |
Why it matters
After sampling, a 7 kHz tone recorded at 10 kHz is indistinguishable from a real 3 kHz tone. No later processing can tell them apart. That is why an analog anti-aliasing filter sits in front of every ADC: it removes content above fs/2 before the signal is sampled. Many converters also oversample (sample much faster than needed) so that this analog filter can be simple, then filter and decimate digitally.
Common mistakes
- “Sampling at exactly 2f is enough.” Not quite. At fs = 2f the samples can land on the zero crossings of a sine and read all zeros. The sampling theorem needs fs strictly greater than twice the highest frequency, and real systems leave a margin for the filter.
- Mixing up Nyquist frequency and Nyquist rate. The Nyquist frequency is fs/2, a property of the sampler. The Nyquist rate is twice the signal’s highest frequency, a property of the signal.
- Thinking only tones above fs alias. Anything above fs/2 folds back, including tones between fs/2 and fs.
FAQ
What is the Nyquist frequency?
It is half the sample rate. For CD audio at 44.1 kHz it is 22.05 kHz. Content below it is represented correctly; content above it folds back as an alias.
Can aliasing be removed after sampling?
In general, no. Once a tone has folded onto a lower frequency, its samples are identical to a real tone at that frequency. The exception is when you know in advance which band the signal occupies, as in deliberate band-pass (under-) sampling.
Why does a tone at exactly the sample rate look like DC?
Each sample is taken after exactly one full cycle, so every sample lands at the same point of the wave and has the same value. A constant sequence is a 0 Hz signal.
Why do wheels sometimes look like they spin backwards in videos?
It is the same effect with the camera’s frame rate as the sample rate. If the wheel turns a little less than one spoke spacing between frames, the samples fit a slow backwards rotation better than the real fast forward one.
Learn the theory step by step in What is aliasing?, which includes tested Python code.
References
- Oppenheim, A. V. & Schafer, R. W., Discrete-Time Signal Processing, 3rd ed., Pearson, 2010, chapter on sampling of continuous-time signals.
- Lyons, R. G., Understanding Digital Signal Processing, 3rd ed., Prentice Hall, 2011, chapter on periodic sampling.