Professional Documents
Culture Documents
Assigment Signal and System
Assigment Signal and System
3. For two discrete-time signals x[n] and h[n] that are both of finite length, you
can implement the convolution operation y[n] = x[n] * h[n] in Matlab using the
command conv.The resulting Matlab array that holds the values of y[n] will
have a length equal to the length of x[n] plus the length of h[n] minus one.
and
The signal x[n] “goes” from n = 0 to n = 6, so the shifted signal x[n − 3] “goes”
from n = 0 to n = 9. This means that we need a Matlab array with 10 elements
to hold the values of x[n − 3] (for n = 0, 1, . . . , 9). To make the plotting easy,
we will store both x[n] and x[n − 3] in 10- element Matlab arrays. Since h[n]
“goes” from n = 0 to n = 8, we will need a nine-element Matlab array to hold
the values of h[n]. Each convolution result will have a length of 10 + 9 − 1 =
18, corresponding to the “times” n = 0, 1, . . . , 17.
Here is sample Matlab code to compute the two convolutions and plot them
both in the same figure using the subplot command:
n = -8:8;
h1n = [zeros(1,8),1 1 -1 -1 zeros(1,5)];
for i=1:length(n)
%populating h1[n]
if n(i)>=-3 && n(i)<3
h2n(i) = (1/2)^n(i);
else
h2n(i) = 0;
end
%populating x[n]
if n(i)>0 && n(i)<6
xn(i) = (1/4)^n(i);
else
xn(i) = 0;
end
end
%plotting for part a
figure(1);
subplot(3,1,1);
stem(n,h1n);
subplot(3,1,2);
stem(n,h2n);
subplot(3,1,3);
stem(n,xn);
%part b
vn = conv(xn,h1n);
yn =conv(vn,h2n);
%plotting for part b
(b) Consider a system H formed from the series connection of H1 and H2,
where x[n] is input to H1, the output v[n] of H1 is input to H2, and the output of
H2 is y[n]. Use the conv function to find v[n] and y[n]. Plot v[n] and y[n] using
the subplot function.
subplot(211);
stem(-8:24,vn);
subplot(212);
stem(-8:40,yn);
%part c
vn = conv(xn,h2n);
yn =conv(vn,h1n);
%plotting for part c
(c) Now assume that the order of the systems is reversed, so that x[n] is input
to H2, the output v[n] of H2 is input to H1, and y[n] is the output of H1. Plot
v[n] and y[n]. Briefly explain why v[n] is different in parts (b) and (c), whereas
y[n] is the same in both parts.
subplot(211);
stem(-8:24,vn);
subplot(212);
stem(-8:40,yn);