Sampling & Aliasing
How do we turn a continuous, real-world signal into numbers a computer can process? And what goes wrong when we don't sample fast enough? This lesson answers both questions.
What Is Sampling?
Sampling is the process of measuring a continuous signal at regular intervals to produce a discrete sequence of numbers. Each measurement is a sample, and the number of samples taken per second is the sampling rate f_s, measured in Hertz (Hz).
Common sampling rates you'll encounter:
- 8,000 Hz — telephone audio
- 44,100 Hz — CD-quality audio
- 48,000 Hz — professional video/audio
- 96,000 Hz — high-resolution audio
The time between samples is T_s = 1 / f_s. At 44,100 Hz, that's about 22.7 microseconds between each measurement.
The Nyquist–Shannon Sampling Theorem
The most important result in digital signal processing is the sampling theorem, stated independently by Nyquist and Shannon:
Sampling Theorem
A continuous signal can be perfectly reconstructed from its samples if and only if the sampling rate is at least twice the highest frequency present in the signal:
The frequency f_{\max} is the highest frequency component in the signal. Half the sampling rate, f_s / 2, is called the Nyquist frequency — it's the absolute upper limit of what your digital system can represent.
For example, CD audio at 44,100 Hz can faithfully capture frequencies up to 22,050 Hz. Since human hearing tops out around 20,000 Hz, this is (just barely) sufficient.
What Is Aliasing?
Aliasing is what happens when you violate the sampling theorem — when the signal contains frequencies above f_s / 2.
Here's an intuitive way to think about it: imagine filming a car wheel spinning. If the camera's frame rate is too slow relative to the wheel's rotation speed, the wheel appears to spin backwards or at the wrong speed. The true motion has "aliased" into a false, lower-frequency motion that the camera can represent.
The same thing happens with audio and any other sampled signal. A frequency f that is above the Nyquist limit gets "folded" back into the representable range. Specifically, it appears at the alias frequency:
where k is the nearest integer that brings the result into the range [0,\; f_s/2].
For example, if you sample at f_s = 1000 Hz and your signal contains a 700 Hz tone, that tone aliases to |700 - 1000| = 300 Hz. In the resulting data, a 300 Hz tone appears — the 700 Hz original is indistinguishable from 300 Hz. The information is permanently lost.
Generate and listen to aliased signals in our Signal Generator to hear this effect firsthand.
Anti-Aliasing Filters
Since aliasing is caused by frequencies above f_s / 2 being present before sampling, the solution is straightforward: remove those frequencies before you sample.
This is done with an anti-aliasing filter — a low-pass filter applied to the continuous (analog) signal before the analog-to-digital converter (ADC) takes its samples. The filter's cutoff frequency is set at or just below f_s / 2.
Every microphone input, sound card, and digital oscilloscope has an anti-aliasing filter built in. Without it, any energy above the Nyquist frequency would fold back in and permanently corrupt the recording.
You can experiment with filtering in Lesson 4, or try our Spectrogram to visualize how a signal's frequency content relates to the sampling rate.
The Sampling Trade-Off
Higher sampling rates capture more bandwidth but generate more data. Here's the trade-off at a glance:
| Sampling Rate | Max Frequency | Typical Use |
|---|---|---|
| 8 kHz | 4 kHz | Telephone speech |
| 44.1 kHz | 22.05 kHz | CD audio |
| 96 kHz | 48 kHz | Studio / ultrasonic capture |
| 2 MHz | 1 MHz | Oscilloscope / radio |
Always choose a sampling rate that's at least 2× your highest frequency of interest — and in practice, a bit more than 2× to give the anti-aliasing filter room to roll off.
Key Takeaways
- Sampling converts a continuous signal to discrete values at rate f_s.
- The sampling theorem requires f_s \geq 2 f_{\max} for perfect reconstruction.
- The Nyquist frequency f_s / 2 is the highest frequency a digital system can represent.
- Aliasing folds frequencies above the Nyquist limit back into the representable range, creating false tones.
- Anti-aliasing filters remove high frequencies before sampling to prevent aliasing.
Signal Generator
Create tones at different frequencies and sampling rates. See and hear what aliasing sounds like.
Open Generator →Spectrogram
Visualize frequency content over time. Record from your microphone or load a file.
Open Spectrogram →