Sunteți pe pagina 1din 6

Signals and Systems

Laboratory Exercise 2
Sampling and Aliasing

Objective
The objective of this Lab is to understand concepts and observe the effects of periodically sampling a continuous signal at different sampling rates, changing the sampling rate of a sampled
signal, aliasing, and anti-aliasing filters.
The prelab should be done before the lab, and the answer sheet, not longer than one page,
should be given to the demonstrator to sign before the lab starts. You will not be allowed to do
the prelab during the Lab.
(You will find Chapters 12 and 14 from Roberts, as well as your lecture notes, useful. Also
read the section introductions in this Lab script.)
Your lab report should have a title, a short description of the purpose of the lab, and include
the prelab report. For the experiments, make sure that you label the plots and signals appropriately (and refer to them if necessary), and include any relevant details for the particular question.
The text part of the lab report should also not be more than 1 page long.

Prelab
PQ.1 a) Assume you sample a 2 Hz sinusoid, at a sampling rate fs = 8Hz starting at 0 s. Is
the Nyquist criterion satisfied? Calculate values of the sampled signal during the first
second. (hint: create an appropriate vector in Matlab starting at 0 and ending at 1.
Check help for the sine function.)
b) Now assume you sample a 10 Hz sinusoid at the same sampling rate. What about
the Nyquist criterion now? Calculate the values of the sampled signal during the first
second. Compare the results with the previous calculation. What happened?
Sketch both signals during the first second, and mark the sampling instants and the samples
on your sketch.

Parts of this lab are based on the Sampling and Reconstruction lab by C. Bouman, offered at Purdue University
and Sampling and Quantization lab by Yao Wang and Xiaofeng Xu, offered at Polytechnic Institute of NY.

PQ.2 Consider the signal spectrum shown in Figure 1. What is the Nyquist rate for this signal?
Sketch the spectrum of the sampled signal if it is ideally (impulse) sampled at Nyquist
rate. Mark the relevant frequencies. How would you reconstruct the original signal?

-100

f [Hz]

100

Figure 1: baseband signal spectrum


PQ.3 The spectrum shown in Figure 2 is that of a band pass signal.

-400

-300

300

400

f [Hz]

Figure 2: band pass signal spectrum


What is its Nyquist rate? Assume that it is ideally (impulse) sampled a) at fs1 = 500Hz
and b) at fs2 = 200Hz. Is the Nyquist criterion satisfied in these two cases? Sketch the
spectra for both cases of sampled signals. Mark the relevant frequencies. Is there aliasing?
Could the original signal be reconstructed? If so, how (in the ideal case)?

1 Sampling and Aliasing


Sampling is a process of acquiring values of a continuous-time signal at discrete time instants,
and is a fundamental concept in digital signal processing (DSP). Signal values are acquired at
discrete time instants, which enables them to be processed in a computer or any DSP unit.
Another process necessary for DSP is quantisation. We will look at quantisation in a different
Lab.
In the spectral domain, sampling produces a periodic spectrum, with images of the original
spectrum centered around multiples of the sampling frequency (aliases):
)=
S(f

+
X

S(f kfs )

(1)

k=

where S is the sampled signal spectrum, and S is the original signal spectrum. (More details
on sampling and reconstruction can be found in your lecture notes and in chapters 12 and 14
of Roberts.) If the signal is sampled properly, it is possible to reconstruct it perfectly from the
discrete values. The simplest way of reconstruction in the case of the ideal impulse sampling
is by using a brick wall filter that eliminates all the aliases of the baseband spectrum. This is
equivalent to a sinc function interpolation (more details in Chapter 12 of the Roberts textbook,
section on ideal impulse sampling). Sampling frequencies that are too low lead to aliasing frequencies from the aliases of the original spectrum will appear in the original band, and the nature
2

of the spectrum is changed. If the sampling frequency is too low, some harmonic components
can end up being aliased into the negative frequency range. These components fold back around
zero frequency and appear in the original band as low frequency components.
In this part of the lab you will build Simulink models that simulate sampling and observe the
effects of sampling a continuous signal at different rates in both time and spectral domain. All
required blocks can be found either in the samplinglab blocks model that is in your working
directory, and in standard Simulink blocksets.
LQ1.1. Before you start, copy the files from the Lab 3 - Sampling and Aliasing folder on W
drive to your working directory. Construct the model shown in Figure 3. Save it in the
same directory. Before running the model, make sure that Matlab is set to the same
directory. Signal Generator and Scope blocks can be found in the Sources and Sinks
blocks, respectively.

Figure 3: sampling
Set the parameters for the Signal Generator as follows:
(a) waveform: sine
(b) amplitude: 1
(c) frequency: 1 Hz
Set the parameters for the Impulse Generator as follows:
(a) sampling period: 0.25 (What is the sampling frequency?)
(b) sample width: 0.001
Set the simulation time to 120, solver to ode45, type to variable step and maximum
step size to 0.05. Leave other parameters unchanged. Run the simulation and observe
the results in the scope window and in the Matlab generated figure. Identify the original
3

signal component in the sampled signal spectrum, and identify the aliases (frequency
pairs). Show the relationship between the sampling frequency and the aliases in the
sampled signal spectrum (mark all the relevant frequencies in the plots) and explain.
LQ1.2. Repeat the above for sampling periods of 0.2, 0.1, and 0.8. Compare the results to those
you obtained in the previous task. How do the results change? Particularly pay attention
to the case with sampling period 0.8. What happened here? Identify any aliased low
frequency components in the spectrum plot. Can you guess the aliased frequency value
from the scope plot of the sampled signal? Explain.
LQ1.3. Repeat the procedure for a sawtooth wave with frequency set to 0.25, and sampling
periods set to 0.1 and 0.2. Comment on the spectrum structure. Describe the differences
from the case with a sinusoid, particularly with aliasing in view (remember, a sawtooth
wave has an infinite spectrum).
LQ1.4. To reduce the effects of aliasing, anti-aliasing filters can be used. They limit the bandwidth of the signal so that sampling introduces no or very little aliasing. If the sampling
rate is fs , what should be the cutoff frequency of the anti-aliasing filter? Why?
Modify your model by inserting the Analog Butterworth LP Filter before the Impulse
Generator. Adjust the model so that you can see plots from the Signal Generator, filter
output, and the sampled signal on the scope.
Re-run the simulation for the sawtooth with frequency set to 0.25 and sampling period
to 0.1. Set the filter cutoff frequency first to 5 Hz, and then to 2 Hz. (note that the filter
requires input in rad/s, so be careful what you type in). What can you say about spectra
and aliasing in this case? What was the price that had to be paid to reduce aliasing? How
does the filter bandwidth affect the results?

Reconstruction

In order to reconstruct the signal from the series of discrete values we need to eliminate the
periodicity of the sampled signal spectrum. The simplest way to do this is by low-pass filtering.
From the time-domain point of view, reconstruction can be seen as filling in the missing values
between the samples, i.e. interpolation. There are many ways of interpolation, and this topic is
out of the scope of this course. However, all interpolators can be seen as specific types of filters.
LQ2.1. Build the model from Figure 4. Set the Gain value to 100. Run the simulation for a
sinewave with frequency 1 Hz, sampling period 0.25, sample width 0.001 and the lowpass filter cutoff frequency of 1.2 Hz. Observe the results.
Change the sampling period to 0.8, and repeat the simulation. Comment on how the
results have changed in both spectral and time domains.
LQ2.2. Repeat the above procedure for a square wave with frequency 0.5 Hz, sampling period
0.1, sample width 0.001 and low pass filter cutoff frequency 1.2 Hz. Now change the
4

Figure 4: Sampling and reconstruction


cutoff frequency to 5 Hz and compare the results. How close does the reconstructed
signal match the original one in these two cases? How does the filter bandwidth influence
the reconstruction?
Change the sampling period to 0.8, and re-run the simulation. Comment on the results.

Downsampling and Upsampling

It is sometimes necessary to change the sampling rate of signals. The reasons for this could
be reducing the storage requirements, or transmission speed, or sometimes a move between two
processing or transmission systems with different data rates. Sometimes it is necessary to convert
data from one format to another, and that can involve changing the sampling rate. Two basic
operations are downsampling (or decimation) and upsampling (or interpolation). The theory
that covers these topics is out of the scope of this course and this lab, but we will nevertheless
investigate the effects that changing the sampling rate can have on the signals and how certain
adverse effects can be mitigated.
You will find Matlab scripts down6up6 NF and down6up6 F in the directory downsample upsample. We will use these scripts to demonstrate the effects of downsampling and upsampling audio files. The first one reads an audio file and then downsamples and upsamples
it without using filters and uses the simplest interpolation (repeating the given sample value M
times). The second one does the same but filters the signal before downsampling and uses a
5

special interpolation filter to upsample the signal. To see how to use these scripts, type help
filename. The sound file is provided in the same directory.
LQ3.1. Run down6up6 NF with the sound file, and comment on the subjective differences
between the original sound and its downsampled and upsampled versions. Note the
differences between the time-series and spectra for these three cases.
Run down6up6 F with the sound file, and comment on the subjective differences between the original sound and its downsampled and upsampled versions. Note the differences between the time-series and spectra for these three cases.
The upsampled audio files have been saved to your working directory. Play them and
comment on the subjective quality.
Comment on the differences between the spectra and time-series of two different upsampled versions of the sound. How did the use of the filters in the second case affect the
result?

Report
Prelab
In no more than one page, answer the following questions:
PQ.1 Answer the questions. Include tables of values for both a) and b). Attach the sketch of the
signals with samples marked.
PQ.2 and PQ.3 Answer the questions and attach the sketches for both.

Lab Exercise
In no more than one page, answer the questions in all sections. Attach the plots.
75% of the grade will be awarded for correct answers, and up to 25% will be awarded for the
quality of answers.