📶Sampling Theorem & Aliasing - Nyquist, Sinc Reconstruction, Wagon Wheel
This tool turns the Nyquist–Shannon sampling theorem into an experiment you can play with. Enter a few sine components and a sample rate, and the chart shows the continuous signal, the samples and the reconstruction (ideal sinc interpolation or zero-order hold). As soon as a component goes above f_s/2 the reconstruction comes out at a different frequency: that is aliasing. The spectrum tab shows the images repeating every f_s and a frequency folding diagram, and you can add a Butterworth anti-aliasing filter before sampling. Other tabs simulate the wagon-wheel effect from films, show how bits set the quantization step and the 6.02N + 1.76 dB SQNR, and play a frequency sweep so you can hear the pitch fold back.
Free · No sign-up · Runs in your browserLast updated:
How to use Sampling Theorem & Aliasing Simulator
- 1In Sample & reconstruct, enter the signal components and sample rate, or click a preset
- 2Switch between sinc and zero-order-hold reconstruction and check each component’s apparent frequency in the table
- 3In Spectrum & folding, look at the image lines and folding diagram, and turn on the anti-aliasing filter
- 4Use the Wagon-wheel, Quantization and Hear aliasing tabs to vary speed and frame rate, bits and amplitude, or the simulated sample rate
FAQ
- What does the sampling theorem say, and why more than twice the frequency?
- The Nyquist–Shannon theorem says a signal whose highest frequency is f_max can be recovered exactly from its samples, x(t) = Σ x[n]·sinc((t − nT_s)/T_s), as long as f_s > 2f_max. Intuitively you need more than two samples per cycle to pin down a sine’s frequency and phase. Exactly twice is not enough: a sine at f = f_s/2 gets exactly two samples per cycle, and with unlucky phase both land on zero crossings, so every sample is 0 and the signal vanishes. That is why f_s/2 is called the Nyquist frequency and the signal must stay strictly below it.
- How do you calculate the alias frequency?
- Sampling copies the spectrum every f_s, so a sine at f gives exactly the same samples as one at |f − k·f_s|, with k the integer nearest to f/f_s. Reconstruction only recovers the copy that falls inside 0 … f_s/2, so the apparent frequency is f_a = |f − round(f/f_s)·f_s|. With f_s = 10 Hz, 8 Hz looks like 2 Hz, 13 Hz looks like 3 Hz and 10 Hz looks like 0 Hz (DC). On the folding diagram the apparent frequency zigzags between 0 and f_s/2 every time the input crosses another multiple of f_s/2, like folding a strip of paper.
- Why do wagon wheels turn backwards in films?
- A camera takes a limited number of frames per second (24, say), which samples the wheel’s rotation. The spoke pattern repeats every 360°/N, so its frequency is N × the rotation rate. When that frequency is a little below a multiple of the frame rate, the spokes move almost one full gap between frames, which looks like a small step backwards, so the wheel appears to reverse. At an exact multiple every frame looks the same and the wheel seems to stand still. The tool gives the apparent speed [N·r − fps·round(N·r/fps)]/N and lists the speeds that look stationary.
- How are bits related to signal-to-noise ratio?
- An N-bit converter divides the full scale ±V_FS into 2^N levels with step Δ = 2V_FS/2^N. The quantization error is roughly uniform within ±Δ/2, giving noise power Δ²/12. For a full-scale sine the signal-to-quantization-noise ratio is SQNR = 6.02N + 1.76 dB, about 6 dB per bit: roughly 50 dB for 8 bits and 98 dB for 16-bit CD audio. If the signal is only part of full scale, subtract 20·log(V_FS/A), which is why recording levels should not be too low; going above full scale clips, and the distortion is far worse than quantization noise.
- Why filter before sampling, and what is zero-order hold?
- Once aliasing happens, the folded high-frequency content is indistinguishable from real low-frequency content in the samples, so it cannot be removed afterwards. An analog low-pass filter must attenuate everything above f_s/2 before sampling. Real filters are not brick walls, and higher orders give steeper transitions, which is why CDs sample 20 kHz audio at 44.1 kHz to leave a margin. Zero-order hold is what a DAC really outputs: each sample is held until the next, forming a staircase. That equals ideal reconstruction multiplied by a sinc envelope and delayed half a sample, and its high-frequency images are removed by a reconstruction filter.
Features
- Up to four sine components with the continuous signal, stem-plot samples and sinc or zero-order-hold reconstruction
- Nyquist zone, apparent frequency f_a = |f − k·f_s| and aliasing status for each component, with a warning for the f = f_s/2 phase trap
- Sampled spectrum with images at k·f_s ± f, a DFT of the samples and a frequency folding diagram
- Butterworth anti-aliasing filter with adjustable order and cutoff, including magnitude and phase shift
- Wagon-wheel animation: the real wheel beside what the camera records, with apparent speed, stationary speeds and car speed
- Quantization step, levels, theoretical and measured SQNR, ENOB and an error plot; play a sweep as original, sample-and-hold or ideal reconstruction