You are on page 1of 4

Communication Systems Lab

Lab 6: To Study the Sampling Theorem Using


Matlab

Introduction
The theory of sampling is provides a clear mathematical understanding of the interface between
our analog world and the discrete world of digital computers, portable audio player and a number
of everyday use devices. The purpose of this lab is to expose us to the practical side of this theory
by presenting some simple examples in MATLAB.

Sampling of elementary signals


In this first part of the lab we will focus on a couple of simple examples. Assuming that one has
already been exposed to the basic theory of sampling the execution of this part of the lab is going
to help us digest the concepts of sampling, reconstruction and aliasing. We will now construct a
sinusoid and we will sample it using various sampling rates.

Generate an analog sinusoid and sample it. Notice that our initial signal which we create using
the provided function makecos() is already sampled but at a very high sampling rate. We consider
this a virtually analog signal since we don't want to use symbolic variables in order to create
continuous-time signals.

% Make our initial, "analog" signal


% (frequency 20 Hz)
[m,t] = makecos(20);

Now we will sample this signal with an adequate sampling frequency. We know that our initial
signal is a cosine with frequency 20 Hz. This means that the Nyquist rate for this signal is
2*20=40Hz. In the first sampling scenario we use a sampling rate of 50Hz which is more than
enough for perfect reconstruction. This is the case of oversampling. So we have:

% Let's make an impulse train for sampling our signal


% (sampling frequency 50 Hz)
[it1,ts1] = makeimp(50);

% Now sample our original signal


ms1 = sampleit1(t,m,ts1);

% Plot all the signals to visualize the sampling process


c1 = 'r'; % color for the first case
smpl_plot(t,m,ts1,it1,ms1,c1);

Page 1 of 4
Notice that the discrete plots featuring arrows denote the integral of the Dirac delta function.
Now we will sample the same analog signal but with a sampling rate less than the Nyquist rate.
This is the case of undersampling and we choose 30Hz.

% Now make a second impulse train


% (sampling frequency 30 Hz less than nyquist)
[it2,ts2] = makeimp(30);

% Now sample our original signal with the new sampling rate
ms2 = sampleit1(t,m,ts2);

% Plot all the signals to visualize the sampling process


c2 = 'g'; % color for the second case
smpl_plot(t,m,ts2,it2,ms2,c2);

According to the theory using the first sampled signal ms1 we should be able to reconstruct the
original whereas using the second ms2 aliasing should occur. Let's now reconstruct using the
function interpsinc() that we provide you with and plot the waveforms in both time and frequency
in order to verify the sampling theory.

% Now we reconstruct from the two sampled versions


mr1 = interpsinc(ms1,ts1,t);
mr2 = interpsinc(ms2,ts2,t);

% Plot original and reconstructed to compare


recon_plot(t,m,ts1,ms1,mr1,c1);
recon_plot(t,m,ts2,ms2,mr2,c2);

Notice how the first reconstructed cosine has the same frequency as the original while the second
has a different frequency. Clearly in the second reconstructed signal we don't have perfect
reconstruction.

% Now lets look at the spectrum to examine the aliasing


% Make the frequency index for plotting
f = (-5000/2):(1/2):(5000/2);

% Use the functions we wrote in lab3 to calculate spectra


M = am_spectrum(m);
MR1 = am_spectrum(mr1);
MR2 = am_spectrum(mr2);

% Plot the spectra to compare


am_plot(f,M,MR1,MR2,0.02);

Verify the frequency of the original and the two reconstructed signals, notice the aliasing.

Page 2 of 4
Result of Experiment # 6 (Each student has to write his/her own
conclusion)

Page 3 of 4
Page 4 of 4

You might also like