› 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

Unique recovery of a low-pass bandlimited signal (ideal infinite sample record):

$$f_s > 2 f_{max}$$

Alias frequency:

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

Nyquist frequency: $f_N = f_s / 2$. Choose integer $n$ so that $0\leq f_{alias}\leq f_N$. For a sine, $f_{max}=f_{signal}$; square and triangle waves also contain higher harmonics.

How to Use & Worked Examples

How to Use

  1. Set signal frequency to 1–100Hz, sampling rate to 2–200Hz, and amplitude to 0.1–3.
  2. Select sine, square or triangle. Compare orange samples with finite-sample sinc interpolation, and check the harmonics warning as well as the fundamental.
  3. The time axis uses numeric seconds; the spectrum is the actual sample record's one-sided FFT amplitude. Amplitude does not change the frequency calculation.
  4. Try 60Hz/80Hz, then 20Hz/40Hz, to distinguish aliasing from the Nyquist boundary.

Worked Example

For a 60Hz sine sampled at 80Hz with amplitude 1, f_N=40Hz and the alias magnitude is |60−80|=20Hz. The first two samples are x[0]=0 and x[1]=sin(2π×60/80)=−1. A positive 20Hz sine would give +1: the sign matters. A 90Hz/120Hz pair similarly folds to a magnitude of 30Hz. At 90Hz/200Hz the fundamental is in baseband, but finite-record interpolation still has edge error.

How It Works & Model Limits

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?
🎓
Aliasing makes different continuous signals produce the same samples. A spinning wheel appearing to turn backwards is a useful analogy. Set a high signal frequency and a low sampling frequency: the orange samples follow a lower-frequency pattern. The blue curve is the original waveform; the dashed curve interpolates the actual finite sample record.
🙋
What does the Nyquist frequency result mean? Can I change it directly?
🎓
It is derived from the sampling rate, not a separate slider: $f_N=f_s/2$. Changing the sampling frequency moves the marker in the spectrum. A sine strictly below that boundary is in baseband. At equality a zero-phase sine samples to zero, and for square or triangle waves the fundamental alone does not describe the whole bandwidth. No anti-alias filter is applied here.
🙋
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 Nyquist-Shannon theorem gives unique recovery of a low-pass bandlimited signal from ideal infinite samples when its highest frequency is strictly below the Nyquist frequency. It does not guarantee exact recovery by this finite-record interpolator.

$$f_s > 2 f_{max}$$

$f_s$ is the sampling rate in Hz; $f_{max}$ is the highest signal frequency in Hz, not just the fundamental of a square or triangle wave. The Nyquist frequency is $f_N=f_s/2$.

When the criterion is violated ($f_{signal}\gt 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.

The magnitude does not encode phase reversal. A 60Hz sine sampled at 80Hz has the samples of a negative 20Hz sine. The plotted interpolation is $\hat{x}(t)=\sum_{n=0}^{N-1}x[n]\,\mathrm{sinc}(f_s t-n)$, with $\mathrm{sinc}(u)=\sin(\pi u)/(\pi u)$ and $\mathrm{sinc}(0)=1$. It passes through all observed samples and treats samples outside the record as zero. Finite-record edge error and ringing remain. Phase is fixed; square-wave discontinuities use midpoint zero.

The spectrum is an FFT of the actual samples, with a rectangular window and one-sided amplitude normalized by the observed count $N$. Bins other than DC and Nyquist are doubled. Zero-padding to a power of two makes bins closer together but does not improve the resolution of the finite observation. Leakage and bin location can make a peak differ from the input amplitude.

Check the calculation code used on this page. Theory references: Brian McFee: the sampling theorem and Julius O. Smith: sinc interpolation and finite-length approximations.

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: This one-dimensional teaching model does not simulate MRI or CT acquisition, reconstruction or clinical safety. Do not use its settings to specify an imaging protocol.

Common Misconceptions and Points to Note

Exactly twice the frequency is not a guarantee of unique recovery. Set a 20Hz sine and a 40Hz sampling rate: its zero-phase samples are approximately all zero. The original amplitude cannot be inferred uniquely. A universal 2.5× or 5–10× rule is not sufficient; choose margins using the required bandwidth, filter response and error limits.

Real anti-alias filters have a transition band and finite attenuation, so residual out-of-band content can still fold. This simulator has no added-noise or filter controls and does not assess filter performance.

Ideal square and triangle waves have unbounded harmonics. Even if only the fifth harmonic is of interest, consider how higher unwanted components will be attenuated before sampling, rather than treating the fundamental alone as the bandwidth.

Practical Notes

  1. For audio, telecommunications or vibration acquisition, assess the wanted bandwidth, filter transition band and attenuation of unwanted components together. Sampling rate alone is not a guarantee.
  2. A rotating machine's shaft speed does not by itself determine bearing fault frequencies or the full harmonic bandwidth. This simulator does not model a bearing or diagnose faults.
  3. Distinguish finite-record edge error and FFT leakage from aliasing during acquisition. Filtering, added noise and quantization are not simulated.

Frequently Asked Questions

The Nyquist frequency is 40Hz and the alias magnitude is 20Hz. For a unit-amplitude zero-phase sine, the second sample is −1: the samples match a negative 20Hz sine, not a positive one.
It does not guarantee unique recovery. A zero-phase 20Hz sine sampled at 40Hz gives samples approximately all zero. For ideal recovery of a low-pass bandlimited signal, its highest frequency must be strictly below Nyquist.
Ideal square and triangle waves contain infinitely many higher harmonics. No anti-alias filter is applied in this tool. In practice, assess the required bandwidth, filter transition band and attenuation of unwanted components together.
Interpolation uses a finite observed record and treats samples outside it as zero, leaving edge error and ringing. The spectrum is a rectangular-window FFT of the actual samples; leakage and bin location affect peaks. Zero-padding does not improve the resolution set by observation duration.