0% found this document useful (0 votes)
8 views5 pages

Lab 3

This document outlines Lab 3 for ECE 311 at the University of Illinois, focusing on sampling, convolution, LTI systems, and difference equations using MATLAB. It includes an overview of the lab objectives, detailed instructions for experiments involving continuous and discrete signals, and homework assignments related to signal processing concepts. The lab aims to enhance understanding of the effects of sampling and the analysis of linear time-invariant systems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Lab 3

This document outlines Lab 3 for ECE 311 at the University of Illinois, focusing on sampling, convolution, LTI systems, and difference equations using MATLAB. It includes an overview of the lab objectives, detailed instructions for experiments involving continuous and discrete signals, and homework assignments related to signal processing concepts. The lab aims to enhance understanding of the effects of sampling and the analysis of linear time-invariant systems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

University of Illinois at Urbana-Champaign

Department of Electrical and Computer Engineering


ECE 311: Digital Signal Processing Lab
Chandra Radhakrishnan
Peter Kairouz

LAB 3: Sampling, Convolution, LTI systems, and


Difference Equations
Summer 2011

1 Overview
In this lab we will study sampling, convolution, and analyze LTI systems using MATLAB. The objective of this lab is
to teach you the effects of sampling on continuous time signals and their spectra. We will also take a deeper look at
convolution and properties of LTI systems.

2 Sampling
The sampling theorem specifies conditions under which a bandlimited continuous-time signal can be completely rep-
resented by discrete samples. The resulting discrete-time signal x[n] = xc (nT ) contains all the information in the
continuous-time signal so long as the continuous-time signal is sufficiently bandlimited in frequency, i.e., Xc (jΩ) = 0
for |Ω ≥ π/T |. When this condition is satisfied, the original continuous-time signal can be perfectly reconstructed by
interpolating between samples of x[n].
Consider the sinusoidal signal,
x(t) = sin(Ω0 t)
If x(t) is sampled with frequency Ωs = 2π/T rad/sec, then the discrete-time signal x[n] = x(nT ) is equal to

x[n] = sin(Ω0 nT )

Assume sampling frequency is fixed at Ωs = 2π(8192) rad/sec.

1. Assume Ω0 = 2π(1000) rad/sec and define T = 1/8192. Create the vector n=[0:8191], so that t=n*T contains
8192 samples in the interval 0 ≤ t ≤ 1. Create a vector which contains the samples of x(t).

2. Display first 50 samples of x[n] versus n using stem. Display the first fifty samples of x(t) versus the sampling
time using plot.

Note: plot displays a continuous-time signal given the samples in x.


Now consider the following signal:
x(t) = a1 cos(Ω0 t) + b1 cos(Ω1 t)
We can sample this signal at a sampling rate Ωs to yield a discrete-time signal x[n]. We can now use the DFT (say
length M ) to compute the spectrum of this signal. Note the DFT samples X[k] are related to the analog frequency by

1
Ω = (2πk/M )/T where T is the sampling interval. Also the spectrum of this signal will have two periodic sincs. We
have seen earlier that to distinguish two frequencies we must have (assuming 50% overlap),

MT ≥ .
|Ω1 − Ω0 |
The larger M gives higher peaks and smaller M gives wider sidelobes. The sampling interval T must be chosen correctly
otherwise one has aliasing where the higher frequency can appear as a lower frequency.

3 Linear Time-Invariant Systems


In discrete time, linearity provides the ability to completely characterize a system in terms of its response hk [n] to signals
of the form δ[n − k] for all k. If a linear system is also time-invariant, then the responses hk [n] satisfy hk [n] = h[n − k].
The combination of linearity and time-invariance therefore allows a system to be completely described by its impulse
response h[n] since the output of the system y[n] is related to the input x[n] through the convolution sum.
n=∞
X
y[n] = h[n − m]x[m] (1)
n=−∞

The MATLAB function conv computes the convolution sum in (1) assuming that x[n] and h[n] are finite length sequences.
If x[n] is non zero only on the interval nx ≤ n ≤ nx +Nx −1 and h[n] is non-zero only on the interval nh ≤ n ≤ nh +Nh −1,
then y[n] is non-zero in nx + nh ≤ n ≤ nx + nh + Nx + Nh − 2 meaning that conv computes Nx + Nh − 1 samples.
Consider the finite length signal

1, 0 ≤ n ≤ 5
x[n] =
0, otherwise,
Use conv to compute y[n] = x[n] ∗ x[n]. Store the result in y. Plot y using stem command. Note conv does not return
an index vector. Index vector ny must be constructed such that ny(i) = y[nyi]. ny(1) must be nx + ny .
A LTI system can also be represented as a difference equation as shown below:
K
X M
X
ak y[n − k] = bm x[n − m] (2)
k=0 m=0

where x[n] is the system input and y[n] is the system output. If x is a MATLAB vector containing the input x[n] on the
interval nx ≤ n ≤ nx + Nx − 1 and the vectors a and b contain the coefficients ak and bm then filter(b,a,x) returns
the output of the causal LTI system satisfying
K
X M
X
a[k + 1]y[n − k] = b[m + 1]x[n − m]
k=0 m=0

Note that a[k + 1] = ak and b[m + 1] = bm , since MATLAB requires all vectors to begin at one. For example, to specify
the system described by the difference equation
y[n] + 2y[n − 1] = x[n] − 3x[n − 1],
you would define a = [1 2] and b = [1 -3].
Also note that the output of filter contains samples of y[n] in the same interval as the samples of x. Also, filter need
samples in the interval nx − M ≤ n ≤ nx − 1 in order to compute the first output sample of y[n]. If they are not
provided, filter assumes these samples are zero.
Define a1 and b1 to describe the causal LTI system shown below:
y[n] = 0.5x[n] + x[n − 1] + 2x[n − 2]

2
x = [1 2 3 4];
a1 = [1];
b1 = [0.5 1 2];
y1 = filter(b1,a1,x)

Use filter to compute response y[n] to input x[n] = nu[n]: Try the following system:

y[n] = 0.8y[n − 1] + 2x[n]

x = [1 2 3 4];
a1 = [1 -0.8];
b1 = [2];
y1 = filter(b1,a1,x)

4 Homework - Due 07/05/2011 at 5:00 PM


1. Consider a continuous sinusoidal signal xa (t) = cos(2πf1 t) + cos(2πf2 t), where f1 = 1kHz and f2 = 1.4kHz. This
signal is sampled at Ωs = 2π104 rad/s.

(a) What is the discrete sequence x[n]?


(b) Generate N = 5000 samples of x[n] and compute the N -point DFT X[k] of x[n], n = 0, 1, . . . , N − 1 in
MATLAB. Plot the magnitude of sampled version of Xa (Ω) using the DFT sequence X[k]. Keep in mind
that the magnitude is in dB-scale and x-scale should have a physical meaning (Hz). Can you identify f1 and
f2 from the plot? Hint: use the following routine:
% T: sampling period
% x: input sequence
XF = fft(x,N);
XF = [XF(N/2+1:N) XF(1:N/2)];
fq = [-N/2:N/2-1]/N*(1/T);
plot(fq,10*log10(abs(XF)));
axis([-1/T/2 1/T/2 -inf inf]);
xlabel(’Frequency (Hz)’);
ylabel(’Magnitude (dB)’);
grid;
(c) Repeat the same steps as in (b) for N = 100 and N = 20.
(d) Provide the theoretical value of N over which the main-lobes of two cosines do not overlap. Does this match
with your empirical results in (a) and (b)?

2. Let xa (t) = cos(2πt) + 0.8cos((14/15)πt). In this exercise, you will investigate how the choice for the number of
samples of xa (t), N , and the sampling period, T , affect the analysis of the spectrum. A 256-point DFT will be
used to get fine sampling of Xd (ω) for each choice of N and T . In order to conveniently vary N and T , create the
file test.m to generate N samples of xa (t) at intervals of T . The following code can be used to serve this purpose:

function x = test(N,T)
x = zeros(1,256);
n = 0:N-1;
x(1:N) = cos(2*pi*(n)*T) + 0.8*cos((14/15)*pi*(n)*T);

3
Note: the returned vector is zero-padded to length 256, so that a 256-point DFT can always be used. Given this
new function, the magnitude of the 256-point DFT for N = 64 and T = 1/30 can be obtained by typing:

x = test(64, 1/30);
X = fft(x);
k = 0:255;
plot(k, abs(X)), xlim([-2 257]);
title(’N=64, T=1/30’); xlabel(’k’); ylabel(’ | X(k)|’);

(a) Compute and plot the magnitude (in MATLAB) the 256-point DFT X[k]255
k=0 for each of the following cases:

(i) N=64, T=1/240 (ii) N=64,T=1/30


(iii) N=64,T=1/5 (iv) N=32,T = 1/120
(v) N=32, T=1/30 (vi) N=32, T=1/15

(b) For each of the above cases, determine the analog frequencies corresponding to X[73] and X[173].
(c) Use the expression for the DFT of a single truncated sinusoid to explain the effect of the number of samples
N and the sampling interval T on the resulting plots.
(d) Given a 2 second long segment of xa (t), how would you choose the sampling interval T to avoid problems
that occur from not sampling at or above the Nyquist rate. The problems that occur are called aliasing.
(e) Given xa (t) for −∞ < t < ∞, and that only N = 128 samples are to be acquired, how would you choose T
to best resolve the sinusoidal components?
(f) Given that T = 1/30, use the previous reasoning to give an estimate of the minimum number Nmin of samples
required to resolve the sinusoids. Also determine Nmin experimentally (i.e., using test (N, 1/30); how small
can N be before you cannot tell that there are two sinusoids?). Demonstrate the experimentally determined
Nmin using plots generated by test(N,1/30) for N = Nmin − 1, Nmin , and Nmin + 1.

3. Consider the following x[n] and h[n]:



1, 0 ≤ n ≤ 5
x[n] =
0, otherwise,

n, 0 ≤ n ≤ 5
h[n] =
0, otherwise,

(a) Analytically compute y[n] = h[n] ∗ x[n].


(b) Compute the convolution of x[n] and h[n] using conv command. Store the result in y and plot y using stem.
(c) Now compute the convolution y[n] = h[n + 5] ∗ x[n]. Store the result in y1 and plot y1 using stem. How does
this result compare with the result in part (b).

4. Consider two causal systems defined by the following linear difference equations:
3
System 1: y1 [n] = y1 [n − 1] + x[n]
5 
3 n

System 2: y2 [n] = y2 [n − 1] + x[n].
5

Each system satisfies initial rest conditions, which state that if x[n] = 0 for n ≤ n0 then y[n] = 0 for n ≤ n0 .
Define h1 [n] and h2 [n] to be the responses of the System 1 and 2, respectively, to the signal δ[n].

4
(a) Calculate h1 [n] and h2 [n] on the interval 0 ≤ n ≤ 19, and store these responses in h1 and h2. Plot each
response using stem. Hint: The filter function can be used to calculate h1. However, System 2 is described
by a difference equation with non-constant coefficients; therefore, you must either determine h2 analytically
or use a for loop rather than filter to calculate h2.
(b) For each system, calculate the unit step response on the interval 0 ≤ n ≤ 19, and store the response in s1 and
s2. Again, filter can be used only to calculate the step response of System 1. Use for loop to calculate s2.
(c) Note that h1 [n] and h2 [n] are zero for n ≥ 20 for all practical purposes. Thus h1 and h2 contain all we need to
know about the response of each system to the unit impulse. Define z1 [n] = h1 [n]∗u[n] and z2 [n] = h2 [n]∗u[n],
where u[n] is the unit step function. Use conv to calculate z1 [n] and z2 [n] and store it in vectors z1 and z2.
You must first define a vector containing u[n] over an appropriate interval, and then select the subset of the
samples produced by conv(h1,u) and conv(h2,u) that represent the interval 0 ≤ n ≤ 19. Since you have
truncated two infinite-length signals, only a portion of the outputs of conv will contain valid sequence values.
(d) Plot s1 and z1 on the same set of axes. If the two signals are identical, explain why you could have anticipated
this similarity. Otherwise, explain any difference between the two signals. On a different set, plot s2 and z2.
Again, explain how you might have anticipated any differences or similarities between these two signals.

Deliverables
• Email your code, figures, calculation and answers as a .pdf or .doc file to [email protected]. Be sure
to name your document in the form- ECE311Lab3 firstname lastname.doc/pdf.

• Late reports will reduce the grade by 20% per day.

• Make sure to present a clear and concise report having figures labeled and centered.

• Reminder: Homework is due on 07/05/2011

You might also like