Created by Dr. V. R. Ratnaparkhe
Signals & SystemsVirtual Laboratory
Experiment 03 · Signals & Systems Lab

Sampling, Nyquist Rate & Aliasing

Sample a continuous-time signal and see aliasing appear when the sampling rate drops below the Nyquist rate.

SamplingReconstructionAudio aliasingCO 1-3

Aim

Generate a discrete-time sequence by sampling a continuous-time signal, and show that when the sampling rate is below the Nyquist rate, aliasing occurs when the signal is reconstructed.

Objectives

  • State the sampling theorem and work out the Nyquist rate of a band-limited signal.
  • Reconstruct a signal from its samples with ideal (sinc) interpolation.
  • Predict the alias frequency fa = |f₀ − k·fs| and check it by seeing and hearing the result.
  • Read the sampled spectrum as copies of the original spectrum repeated every fs.

Environment

MATLAB (signal created on a dense "continuous" grid, sampled with n/fs, and plotted with stem), or the virtual sampler on the Simulator tab. Use headphones at a low volume for the audio part.

Sampling

Sampling takes the values of x(t) at equally spaced times t = nTs: x[n] = x(nTs), where fs = 1/Ts. In the frequency domain, sampling makes copies of the spectrum at every multiple of fs:

X_s(f) = f_s · Σ_k X(f − k·f_s)

Sampling theorem (Nyquist–Shannon)

A signal band-limited to fmax can be recovered exactly from its samples if

f_s > 2·f_max (2·f_max is the Nyquist rate) x(t) = Σ_n x[n] · sinc( (t − nT_s)/T_s ) ← ideal reconstruction

If fs < 2fmax, the spectral copies overlap. A high frequency then "folds back" and looks like a lower one:

f_alias = | f₀ − k·f_s |, with k chosen so that 0 ≤ f_alias ≤ f_s/2

Visual aid — the wagon-wheel effect

A movie camera samples a spinning wheel at a fixed frame rate. When the wheel turns more than half a revolution per frame, it seems to turn slowly, or even backwards. That is aliasing.

Keep the frame rate fixed and raise the wheel speed. Watch the apparent speed drop to zero at 1 rev/frame, and run backwards just below that.
  1. In the Simulator, set the signal frequency f₀ = 500 Hz. The Nyquist rate is 1000 Hz.
  2. Set fs = 4000 Hz (well above Nyquist). The reconstruction (green) matches the original (blue). Press Play original and Play reconstructed; they sound the same.
  3. Lower fs slowly to 1200 Hz, then 1000 Hz, then 800 Hz. Watch the spectrum: the copies move toward each other and then overlap.
  4. At fs = 800 Hz, predict falias = |500 − 800| = 300 Hz. Check it on the plot and by ear.
  5. Press Record in Observations for at least 6 (f₀, fs) pairs, some above and some below Nyquist. For each one, count the cycles of the green curve in the window and type the frequency you measured.
  6. Edge case: fs = 2f₀ exactly with phase 90° (sine). Every sample is zero!
Keep the volume low. Square-ish or high-frequency tones can be tiring to listen to.

Pre-lab diagnostic

Signal & sampler

Audio
In live mode, drag fs and listen: below the Nyquist rate the pitch of the reconstruction moves the wrong way.
Time domain — x(t), samples x[n], reconstruction
x(t) originalx[n] samplessinc reconstruction
Spectrum — original lines, copies at k·fs, and the reconstruction filter band ±fs/2

Aliasing table

Record the current setting, measure the frequency of the reconstructed (green) signal, and type it in.

Analysis

Post-lab quiz

Self-evaluation

exp3_sampling.m

%% Experiment 3: Sampling and aliasing
clc; clear; close all;
f0 = 500;                       % signal frequency (Hz)
t  = 0:1e-6:6e-3;               % dense "continuous" time grid
x  = cos(2*pi*f0*t);
for fs = [4000 1000 800]          % above, at, and below Nyquist
  Ts = 1/fs;  n = 0:floor(6e-3/Ts);  xn = cos(2*pi*f0*n*Ts);
  % ideal sinc reconstruction
  xr = zeros(size(t));
  for k = 1:length(n), xr = xr + xn(k)*sinc((t - n(k)*Ts)/Ts); end
  figure; plot(t,x,'b'); hold on; stem(n*Ts,xn,'r'); plot(t,xr,'g--');
  fa = abs(f0 - fs*round(f0/fs));
  title(sprintf('fs = %d Hz, alias = %g Hz',fs,fa)); legend('x(t)','x[n]','x_r(t)');
end
% soundsc(cos(2*pi*f0*(0:1/8000:1)),8000)   % listen