lab_06.docx
lab_06.docx
EEE-223
Lab Report#06
Name
SHALIZA AAMIR
Class 4-D
Instructor’s Name
SIR. KHURRAM SHEHZAD
1|Page 58
Lab 06- Analysis of Discrete LTI Systems using
Convolution Sum
In-Lab Tasks:
Task 01
Compute and plot the convolution y[ n] x[n]* h[ n] by any of the two procedures, where
n
1
x[n] u[ n 1]
3 and h[n] u[n 1]
Method 01:
n = -5:5
u = (n<=1)
x = 0.3.^-n.*u
subplot(3,1,1)
stem(n,x,'LineWidth',3)
title('x[n]')
h=zeros(1,11)
h(7:11)=1
subplot(3,1,2)
stem(n,h,'LineWidth',3)
title('h[n]')
y =conv(h,x)
subplot(3,1,3)
stem(-5:15,y,'LineWidth',3)
title('y[n]')
2|Page 58
Method #02:
n=-2:2
u=(n<=1)
x=((0.3).^-n).*u
subplot(2,1,1)
stem(n,x,'linewidth',3)
title('x(n)')
h=(n>=1)
subplot(2,1,2)
stem(n,h,'linewidth',3)
title('h(n)')
3|Page 58
%taking the signal from n =>k axis
k=-2:2
u=(n<=1)
x=((0.3).^-k).*u
subplot(4,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
h=(k>=1)
subplot(4,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
a=-1
subplot(4,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
n=0
subplot(4,1,4)
stem(((1/a)*k)+n,h,'linewidth',3)
4|Page 58
title('h(-k+0)')
%original signal
k=-2:2
u=(k<=1)
x=((0.3).^-k).*u
subplot(4,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
a=-1
subplot(4,1,2)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
5|Page 58
%original signal
k=-2:2
u=(k<=1)
x=((0.3).^-k).*u
subplot(4,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
a=-1
subplot(4,1,2)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
6|Page 58
%original signal
k=-2:2
u=(k<=1)
x=((0.3).^-k).*u
subplot(4,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
a=-1
subplot(4,1,2)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
7|Page 58
Task 02
Compute and plot the convolution of following signals (by both procedures)
1 0 n 4
x[n]
0 elsewhere
and
1.5n 0 n 6
h[ n]
0 elsewhere
Method 01
%signal x(n)
n = -5:10;
x = [0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0];
subplot(3,1,1)
stem(n,x,'LineWidth',3)
title('x[n]')
%signal h(n)
subplot(3,1,2)
a1 = (n>=0)&(n<=6);
a2 = 1.5.^n;
8|Page 58
h = a1.*a2;
stem(n,h,'LineWidth',3)
title('h[n]')
%convolution
y = conv(x,h);
subplot(3,1,3)
stem(-1:29,y,'LineWidth',3)
title('y[n]')
Method #02
n=-1:7
x=(n>=0)&(n<=4)
subplot(3,1,1)
stem(n,x)
title('signal of x(n)')
a1=(1.5).^n
a2=(n>=0)&(n<=6)
h=a1.*a2
subplot(3,1,2)
stem(n,h)
title('signal of h(n)')
9|Page 58
%first of all take the reflection of h(n)
b=-1
subplot(3,1,3)
stem((1/b)*n,h)
title('signal of h(-n)')
k=-1:7
x=(k>=0)&(k<=4)
subplot(4,1,1)
stem(k,x)
title('x(k)')
10 | P a g e 5 8
stem((1/c)*k,h)
title('h(-k)')
n=0
subplot(4,1,3)
stem(((1/c)*k)+n,h)
title('h(-k+0)')
n=1
subplot(4,1,4)
stem(((1/c)*k)+n,h)
title('h(-k+1)')
%original signal
k=-1:7
x=(k>=0)&(k<=4)
subplot(4,1,1)
stem(k,x)
title('x(k)')
%fliping of orignal signal
a1=(1.5).^k
a2=(k>=0)&(k<=6)
h=a1.*a2
11 | P a g e 5 8
c=-1
subplot(4,1,2)
stem((1/c)*k,h)
title('h(-k)')
% shifting the x(-k) at n=2
n=2
subplot(4,1,3)
stem(((1/c)*k)+n,h)
title('h(-k+2)')
n=3
subplot(4,1,4)
stem(((1/c)*k)+n,h)
title('h(-k+3)')
%original signal
k=-1:7
x=(k>=0)&(k<=4)
subplot(4,1,1)
stem(k,x)
title('x(k)')
12 | P a g e 5 8
%fliping the h(k) direct
a1=(1.5).^k
a2=(k>=0)&(k<=6)
h=a1.*a2
c=-1
subplot(4,1,2)
stem((1/c)*k,h)
title('h(-k)')
%original signal
k=-1:7
x=(k>=0)&(k<=4)
subplot(4,1,1)
13 | P a g e 5 8
stem(k,x)
title('x(k)')
14 | P a g e 5 8
%original signal x(k)
k=-1:7
x=(k>=0)&(k<=4)
subplot(4,1,1)
stem(k,x)
title('x(k)')
a1=(1.5).^k
a2=(k>=0)&(k<=6)
h=a1.*a2
c=-1
subplot(4,1,2)
stem((1/c)*k,h)
title('h(-k)')
n=8
subplot(4,1,3)
stem(((1/c)*k)+n,h)
title('h(-k+8)')
n=9
subplot(4,1,4)
stem(((1/c)*k)+n,h)
title('h(-k+9)')
15 | P a g e 5 8
% original signal x(k)
k=-1:7
x=(k>=0)&(k<=4)
subplot(3,1,1)
stem(k,x)
title('x(k)')
a1=(1.5).^k
a2=(k>=0)&(k<=6)
h=a1.*a2
c=-1
subplot(3,1,2)
stem((1/c)*k,h)
title('h(-k)')
n=10
subplot(3,1,3)
stem(((1/c)*k)+n,h)
title('h(-k+10)')
16 | P a g e 5 8
Task 03
Consider and LTI system with input x[n] and unit impulse response h[n] specified as
x[n] 2n u[ n]
h[ n] u[ n]
Compute the response of the system (by both methods) where we have 6 n 6 .
Method 01
%signal x(n)
n = -6:6
h = [0 0 0 0 0 0 1 1 1 1 1 1 1]
x = 2.^n.*(n<=0)
subplot(3,1,1)
stem(n,x,'LineWidth',3)
title('x(n)')
%signal h(n)
17 | P a g e 5 8
subplot(3,1,2)
stem(n,h,'LineWidth',3)
title('h(n)')
%signal y(n)
y = conv(h,x);
yn = -12:12;
subplot(3,1,3)
stem(yn,y,'LineWidth',3)
title('y[n]')
Method #02
n=-6:6
u=(n<=0)
x=(2.^n).*u
subplot(2,1,1)
stem(n,x,'linewidth',3)
title('x(n)')
%signal h(n)
18 | P a g e 5 8
v=(n>=0)
h=v
subplot(2,1,2)
stem(n,h,'linewidth',3)
title('h(n)')
%signal h(k)
v=(k>=0)
h=v
subplot(3,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
19 | P a g e 5 8
subplot(3,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
20 | P a g e 5 8
n=1
subplot(5,1,4)
stem(((1/a)*k)+n,h,'linewidth',3)
title('h(-k+1)')
n=2
subplot(5,1,5)
stem(((1/a)*k)+n,h,'linewidth',3)
title('h(-k+2)')
21 | P a g e 5 8
v=(k>=0)
h=v
subplot(5,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
n=3
subplot(5,1,4)
stem(((1/a)*k)+n,h,'linewidth',3)
title('h(-k+3)')
n=4
subplot(5,1,5)
stem(((1/a)*k)+n,h,'linewidth',3)
title('h(-k+4)')
22 | P a g e 5 8
%the original signal x(k)
k=-6:6
u=(k<=0)
x=(2.^k).*u
subplot(5,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
n=5
23 | P a g e 5 8
subplot(5,1,4)
stem(((1/a)*k)+n,h,'linewidth',3)
title('h(-k+5)')
n=6
subplot(5,1,5)
stem(((1/a)*k)+n,h,'linewidth',3)
title('h(-k+6)')
24 | P a g e 5 8
stem(k,h,'linewidth',3)
title('h(k)')
n=-1
subplot(5,1,4)
stem(((1/a)*k)+n,h,'linewidth',3)
title('h(-k-1)')
n=-2
subplot(5,1,5)
stem(((1/a)*k)+n,h,'linewidth',3)
title('h(-k-2)')
25 | P a g e 5 8
%the original signal x(k)
k=-6:6
u=(k<=0)
x=(2.^k).*u
subplot(5,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
n=-3
subplot(5,1,4)
stem(((1/a)*k)+n,h,'linewidth',3)
title('h(-k-3)')
n=-4
subplot(5,1,5)
stem(((1/a)*k)+n,h,'linewidth',3)
title('h(-k-4)')
26 | P a g e 5 8
Task 04
Compute (by both procedures) and graph the convolution y[ n] x[n]* h[n] , where
x[n] u[n] u[n 4] and h[n] [n] [ n 2] .
Method #01:
%signal x(n)
n = 0:6;
h = [1 0 -1 0 0 0 0];
x = [1 1 1 1 0 0 0];
subplot(3,1,1)
stem(n,x,'LineWidth',3)
title('x[n]')
%signal h(n)
subplot(3,1,2)
stem(n,h,'LineWidth',3)
title('h[n]')
27 | P a g e 5 8
%convolution
y = conv(x,h);
subplot(3,1,3)
stem(0:12,y,'LineWidth',3)
title('y[n]')
Method #02
%signal x(n)
n=-5:5
u=(n>=0)
v=(n>4)
x=u-v
subplot(2,1,1)
stem(n,x,'linewidth',3)
title('x(n)')
%signal h(n)
w=[0 0 0 0 0 1 0 0 0 0 0]
y=[0 0 0 0 0 0 0 1 0 0 0]
h=w-y
subplot(2,1,2)
stem(n,h,'linewidth',3)
title('h(n)')
28 | P a g e 5 8
% changing the signal axis from n => k axis
% signal x(k)
k=-5:5
u=(k>=0)
v=(k>4)
x=u-v
subplot(3,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
% signal h(k)
w=[0 0 0 0 0 1 0 0 0 0 0]
y=[0 0 0 0 0 0 0 1 0 0 0]
h=w-y
subplot(3,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
a=-1
subplot(3,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
29 | P a g e 5 8
% signal x(k)
k=-5:5
u=(k>=0)
v=(k>4)
x=u-v
subplot(5,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
% signal h(k)
w=[0 0 0 0 0 1 0 0 0 0 0]
y=[0 0 0 0 0 0 0 1 0 0 0]
h=w-y
subplot(5,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
a=-1
subplot(5,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
%shifting the h(-k) for +ve value of n because from the fig.very clear that
%the output will b zero for negative n
30 | P a g e 5 8
%shifting the signal for n=0
n=0
subplot(5,1,4)
stem(((1/a)*k)+n,h,'linewidth',3)
title('h(-k+0)')
% signal x(k)
k=-5:5
u=(k>=0)
v=(k>4)
x=u-v
subplot(5,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
% signal h(k)
w=[0 0 0 0 0 1 0 0 0 0 0]
31 | P a g e 5 8
y=[0 0 0 0 0 0 0 1 0 0 0]
h=w-y
subplot(5,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
a=-1
subplot(5,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
%shifting the h(-k) for +ve value of n because from the fig.very clear that
%the output will b zero for negative n
32 | P a g e 5 8
% signal x(k)
k=-5:5
u=(k>=0)
v=(k>4)
x=u-v
subplot(5,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
% signal h(k)
w=[0 0 0 0 0 1 0 0 0 0 0]
y=[0 0 0 0 0 0 0 1 0 0 0]
h=w-y
subplot(5,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
a=-1
subplot(5,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
33 | P a g e 5 8
%shifting the h(-k) for +ve value of n because from the fig.very clear that
%the output will b zero for negative n
% signal x(k)
k=-5:5
u=(k>=0)
v=(k>4)
x=u-v
subplot(4,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
34 | P a g e 5 8
% signal h(k)
w=[0 0 0 0 0 1 0 0 0 0 0]
y=[0 0 0 0 0 0 0 1 0 0 0]
h=w-y
subplot(4,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
a=-1
subplot(4,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
%shifting the h(-k) for +ve value of n because from the fig.very clear that
%the output will b zero for negative n
35 | P a g e 5 8
Task 05
Compute (by both procedures) and graph the convolution y[n] , where
(a) y[n] u[ n]* u[n], 0 n 6
Method #01
n = 0:6;
u = ones(size(n));
subplot(2,1,1)
stem(n,u,'linewidth',2)
title('u[n]')
y = conv(u,u);
subplot(2,1,2)
stem(0:12,y,'lineWidth',3)
title('y[n]')
Method 02
36 | P a g e 5 8
%signal x(n)
n=0:6
u=(n>=0)
x=u
subplot(2,1,1)
stem(n,x,'linewidth',3)
title('x(n)')
%signal h(n)
h=u
subplot(2,1,2)
stem(n,h,'linewidth',3)
title('h(n)')
%signal h(k)
h=u
37 | P a g e 5 8
subplot(3,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
a=-1
subplot(3,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
%signal h(k)
h=u
subplot(5,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
38 | P a g e 5 8
% now flip the signal h(k)
a=-1
subplot(5,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
39 | P a g e 5 8
%original signal x(k)
k=0:6
u=(k>=0)
x=u
subplot(5,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
%signal h(k)
h=u
subplot(5,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
a=-1
subplot(5,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
40 | P a g e 5 8
% shifting the signal
%signal h(k)
h=u
subplot(5,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
a=-1
subplot(5,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
41 | P a g e 5 8
n=5
subplot(5,1,5)
stem(((1/a)*k)+n,h,'linewidth',3)
title('h(-k+5)')
%signal h(k)
h=u
subplot(5,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
a=-1
subplot(5,1,3)
stem((1/a)*k,h,'linewidth',3)
42 | P a g e 5 8
title('h(-k)')
%signal h(k)
43 | P a g e 5 8
h=u
subplot(5,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
a=-1
subplot(5,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
44 | P a g e 5 8
%original signal x(k)
k=0:6
u=(k>=0)
x=u
subplot(5,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
%signal h(k)
h=u
subplot(5,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
a=-1
subplot(5,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
45 | P a g e 5 8
% shifting the signal
%signal h(k)
h=u
subplot(4,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
a=-1
subplot(4,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
46 | P a g e 5 8
n=12
subplot(4,1,4)
stem(((1/a)*k)+n,h,'linewidth',3)
title('h(-k+12)')
Task 05
B. Compute (by both procedures) and graph the convolution y[n] , where
y[n] 3 [n 4]*(3 4) n u[ n],0 n 5
47 | P a g e 5 8
Method #01
%signal x(n)
n = 0:5;
h = (3./4).^n.*(n>=0);
x = [0 0 0 0 3 0];
subplot(3,1,1)
stem(n,x,'LineWidth',3)
title('x[n]')
%signal h(n)
subplot(3,1,2)
stem(n,h,'LineWidth',3)
title('h[n]')
% convolution
y = conv(x,h);
subplot(3,1,3)
stem(0:10,y,'LineWidth',3)
title('y(n)')
48 | P a g e 5 8
Method #02
% signal x(n)
n=0:5
x=[0 0 0 0 3 0]
subplot(2,1,1)
stem(n,x,'linewidth',3)
title('x(n)')
% signal h(n)
u=(n>=0)
h=((3./4).^n).*u
subplot(2,1,2)
stem(n,h,'linewidth',3)
title('h(n)')
49 | P a g e 5 8
% changing the axis from n => k axis
% signal x(k)
k=0:5
x=[0 0 0 0 3 0]
subplot(3,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
% signal h(k)
u=(k>=0)
h=((3./4).^k).*u
subplot(3,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
a=-1
subplot(3,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
% now shifting the h(-k) for different values of n in this case there is no
50 | P a g e 5 8
% overlap until the value of n reaches at n= 4 so we start or shifting from
% n =4
% signal x(k)
k=0:5
x=[0 0 0 0 3 0]
subplot(5,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
% signal h(k)
u=(k>=0)
h=((3./4).^k).*u
subplot(5,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
a=-1
subplot(5,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
51 | P a g e 5 8
% signal x(k)
k=0:5
x=[0 0 0 0 3 0]
subplot(5,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
% signal h(k)
u=(k>=0)
h=((3./4).^k).*u
subplot(5,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
a=-1
subplot(5,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
52 | P a g e 5 8
title('h(-k+6)')
% signal x(k)
k=0:5
x=[0 0 0 0 3 0]
subplot(5,1,1)
stem(k,x,'linewidth',3)
title('x(k)')
% signal h(k)
u=(k>=0)
h=((3./4).^k).*u
subplot(5,1,2)
stem(k,h,'linewidth',3)
title('h(k)')
53 | P a g e 5 8
a=-1
subplot(5,1,3)
stem((1/a)*k,h,'linewidth',3)
title('h(-k)')
Conclusion:
In this lab we learnt about the convolution sum .we took analysis of discrete LTI systems using
convolution sum .in this lab we learnt two methods for finding the convolution sum of the discrete
signals. In one method we apply directly the CONV command in the MATLAB. In second method we use
the basic method in which we flip a signal then we shift the flipped signal with respect to the other signal
.Also we apply these methods on MATLAB and analyze the signal.
54 | P a g e 5 8