Interactive Demo of Nyquist's Sampling Theorem

Interactively demonstrates Nyquist's Sampling Theorem.
1.2K Downloads
Updated 14 Jan 2017

View License

This script demonstrates Nyquist's Sampling Theorem, by sampling a continuous-time sinusoidal signal of a frequency f = 50 Hz to 3 kHz, with a fixed sampling frequency fs = 2 kHz. Therefore, only signals with frequencies f <= fs/2 = 1 kHz can be faithfully reconstructed by their samples, while those with frequencies f > 1 kHz will exhibit aliasing effects (i.e., reconstructing the original signal will generate new components that were not part of the original signal).

The generated graph shows both the original signal (in red) and the reconstructed signal (in blue). The reconstructed signal is linearly interpolated and shown together with the samples (circle markers). The user can interactively change the original signal's frequency and phase, and observe how this affects the reconstructed signal, as the frequency approaches and crosses the fs/2 boundary.

In order to have a better appreciation of the aliasing effects on the signal being sampled, the user can listen to both the original and the reconstructed signals and compare the corresponding sounds. This is only possible on sound-capable computers.

The simulation can be interactively controlled in real-time using the following keys:

[Q] / [A] increases/decreases the original signal's frequency (coarse).
[W] / [S] increases/decreases the original signal's frequency (fine).
[E] / [D] increases/decreases the original signal's phase.
[I] plays a one-second sound of the original signal.
[O] plays a one-second sound of the reconstructed signal.
[R] resets all parameters to their initial values.
[ESC] exits the script.

Cite As

Costas Vlachos (2026). Interactive Demo of Nyquist's Sampling Theorem (https://www.mathworks.com/matlabcentral/fileexchange/61143-interactive-demo-of-nyquist-s-sampling-theorem), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2016b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Version Published Release Notes
1.50.0.0

Improved description layout.
Improved description layout.

Improved description layout.
Improved description layout.
Improved description layout.
Improved description layout.