Sampling Theorem & Aliasing Back
Signal Processing

Sampling Theorem & Aliasing Visualizer

Interactively visualize the Nyquist-Shannon sampling theorem. See in real time how aliasing occurs when f_s < 2f_signal and what the alias frequency looks like.

Parameters
Signal frequency fsignal
Hz
Sampling frequency fs
Hz
Amplitude A
Signal type
Aliasing: None
Results
20
f_signal [Hz]
80
f_s [Hz]
40
f_N = f_s/2 [Hz]
f_alias [Hz]
OK
Aliasing
Time Domain — Continuous Signal · Samples · Reconstructed
Frequency Domain — Spectrum
Theory & Key Formulas

Theory

Nyquist criterion:

$$f_s \geq 2 f_{signal}$$

Alias frequency:

$$f_{alias}= |f_{signal} - n \cdot f_s|$$

Nyquist frequency: $f_N = f_s / 2$

What is the Sampling Theorem & Aliasing?

🙋
What exactly is "aliasing"? I see the term in the simulator title, but what does it look like in practice?
🎓
Basically, aliasing is when a high-frequency signal gets misrepresented as a low-frequency one because you're not taking enough samples. In practice, it's like a spinning wheel in a movie appearing to turn backwards. Try the simulator: set a high "Signal frequency" but a low "Sampling frequency". You'll see the blue dots (samples) create a pattern that looks like a much slower, wobbly wave—that's the alias!
🙋
Wait, really? So there's a specific rule to avoid this? What's the "Nyquist frequency" slider showing me?
🎓
Exactly! The rule is the Nyquist-Shannon sampling theorem. The Nyquist frequency is half your sampling rate. It's the highest frequency you can correctly capture. If your signal's frequency is above this line, aliasing occurs. Move the "Sampling frequency" slider up and down—watch how the red "Nyquist frequency" line moves. Keep your blue signal frequency below that red line to stay safe.
🙋
So if aliasing happens, can we predict what the fake low frequency will be? The formula looks a bit abstract.
🎓
Great question! Yes, we can calculate the "alias frequency." For instance, if your signal is at 60 Hz but you sample at 50 Hz, the alias will appear at 10 Hz. The simulator does this math for you. Try setting `f_signal = 7 Hz` and `f_sampling = 10 Hz`. The sampled dots will trace out a 3 Hz wave, because |7 - 10| = 3. That's the deceptive signal you'd actually record!

Physical Model & Key Equations

The fundamental rule to prevent aliasing is the Nyquist-Shannon criterion. To perfectly reconstruct a signal, you must sample at least twice as fast as its highest frequency component.

$$f_s \geq 2 f_{signal}$$

$f_s$: Sampling frequency (Hz). $f_{signal}$: The highest frequency present in the original signal (Hz). The critical threshold, $f_N = f_s / 2$, is called the Nyquist frequency.

When the criterion is violated ($f_{signal}> f_N$), the sampled data points create a false lower-frequency signal. This alias frequency can be calculated by "folding" the original frequency around multiples of the sampling frequency.

$$f_{alias}= |f_{signal}- n \cdot f_s|$$

$f_{alias}$: The observed false frequency (Hz). $n$: An integer chosen so that $f_{alias}$ lies between 0 and $f_N$. This equation shows how high frequencies "reflect" or "fold" down into the lower spectrum.

Real-World Applications

Vibration & Modal Testing: When measuring vibrations of a car chassis or an aircraft wing, accelerometers sample data. If the sampling rate is too low for high-frequency modes, aliasing creates fake low-frequency vibrations in the data, leading to completely incorrect models of the structure's behavior.

Digital Audio Recording: The standard CD sampling rate is 44.1 kHz. This sets the Nyquist frequency at 22.05 kHz, just above human hearing (~20 kHz). Before sampling, an anti-aliasing filter aggressively removes any ultrasonic content to prevent it from aliasing down into the audible range as noise or distortion.

Computer Graphics & Rendering: Aliasing appears as jagged "stair-step" edges on diagonal lines (a spatial alias). Anti-aliasing techniques in video games involve supersampling (taking more samples per pixel) or using filters to smooth out these artifacts, following the same core theorem.

Medical Imaging (MRI & CT Scans): The spatial encoding in MRI involves sampling frequency data (k-space). Undersampling can cause aliasing artifacts in the final image, like body parts "wrapping around" to the opposite side. Advanced sampling patterns are used to accelerate scans while managing these artifacts.

Common Misconceptions and Points to Note

First, the idea that "a sampling frequency exactly twice the signal frequency is sufficient" is a dangerous misconception. The theoretical minimum condition is $f_s = 2 f_{max}$, but this only holds for the ideal case of a perfect sine wave with perfectly aligned phase. In practice, it's standard to set a sampling frequency of at least 2.5 times, and 5 to 10 times for precise analysis, to capture signal rise times and noise. For example, if you want to analyze vibrations up to 1kHz, you should set your sampling frequency to 2.5kHz or higher.

Next, do you think the "anti-aliasing filter is a panacea"? This filter sharply attenuates components above the Nyquist frequency ($f_s/2$), but it cannot reduce them to zero. The "residual part that isn't fully attenuated" folds back and becomes noise. That's why you set the filter's cutoff frequency slightly below $f_s/2$ or use a technique called oversampling. If you create a signal with added high-frequency noise in this simulator, you can experience firsthand the importance of the filter.

Finally, consider handling "non-sinusoidal" waves like square or triangular waves. These waveforms contain infinitely many high-frequency harmonics. As you can try in the simulator, just adhering to the fundamental frequency won't reproduce the jagged edges. In practice, you must adopt the pragmatic approach of "considering $f_{max}$ to be up to the harmonic order you want to analyze." For instance, if you want to see up to the 5th harmonic in motor vibration, you sample at more than twice that 5th harmonic frequency.