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$
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.
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$
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.
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.
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.