0% found this document useful (0 votes)
169 views

In-Lab Tasks: Task 01: Compute and Plot The Convolution by Any of The Two Procedures, Where and

The document describes computing and plotting the convolution of two signals. It provides MATLAB code to: 1) Compute and plot the convolution of signals x[n] and h[n], where x[n] is a unit sample and h[n] is a rectangle function. 2) Compute and plot the convolution of signals x[k], a unit pulse, and h[k], a ramp function, using both the conv command and analytical method of sliding and multiplying the signals. 3) Plot the resulting convolution y[n].

Uploaded by

ShahzebKhurshid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
169 views

In-Lab Tasks: Task 01: Compute and Plot The Convolution by Any of The Two Procedures, Where and

The document describes computing and plotting the convolution of two signals. It provides MATLAB code to: 1) Compute and plot the convolution of signals x[n] and h[n], where x[n] is a unit sample and h[n] is a rectangle function. 2) Compute and plot the convolution of signals x[k], a unit pulse, and h[k], a ramp function, using both the conv command and analytical method of sliding and multiplying the signals. 3) Plot the resulting convolution y[n].

Uploaded by

ShahzebKhurshid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

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] And h[n] u[n 1]
3

MATLAB CODE:
hn=-6:6;
xn=-6:6;
k=-xn;
s=(1/3).^k;
x=s.*(xn<=-1);
h=[0 0 0 0 0 0 0 1 1 1 1 1 1];

subplot(3,1,1)
stem(xn,x,'fill','linewidth',2),grid on
legend('x[n]')
axis([-7 7 -0.2 1])

subplot(3,1,2)
stem(hn,h,'fill','linewidth',2),grid on
legend('h[n]')
axis([-7 7 -0.2 1])

y=conv(h,x);
subplot(3,1,3)
stem(-12:12,y,'fill','linewidth',2),grid on
legend('y[n]=[n]*h[n]')
axis([-7 7 -0.2 1])
1
x[n]
0.5

0
-6 -4 -2 0 2 4 6
1
h[n]
0.5

-6 -4 -2 0 2 4 6
1
y[n]=[n]*h[n]
0.5

-6 -4 -2 0 2 4 6

Task 02: Compute and plot the convolution of following signals (by both procedures)
1 0 n 4
x[n]
0 elsewhere

and

1.5n 0n6
h[n]
0 elsewhere
USING CONV COMMAND

xn=-4:10;
hn=-4:10;

x=[0 0 0 0 1 1 1 1 1 0 0 0 0 0 0];

k=(1.5.^hn);
l=(hn>=0)&(hn<=6);
h=k.*l;

subplot(3,1,1)
stem(xn,x,'fill','linewidth',2),grid on
legend('x[n]')

subplot(3,1,2)
stem(hn,h,'fill','linewidth',2),grid on
legend('h[n]')

y=conv(h,x);
subplot(3,1,3)
stem(-8:20,y,'fill','linewidth',2),grid on
legend('y[n]=[n]*h[n]') axis([-4 10 0 30])

1
x[n]
0.5

0
-4 -2 0 2 4 6 8 10
15
h[n]
10

0
-4 -2 0 2 4 6 8 10
30
y[n]=[n]*h[n]
20

10

0
-4 -2 0 2 4 6 8 10
Analytical Method:
%Step 1:
kx=-4:10;
kh=-4:10;

x=[0 0 0 0 1 1 1 1 1 0 0 0 0 0 0];

k=(1.5.^kh);
l=(kh>=0)&(kh<=6);
h=k.*l;

subplot(3,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-4 10])

subplot(3,1,2)
stem(kh,h,'fill','linewidth',2),grid on
legend('h[k]')
xlim([-4 10])

%Step 2:
subplot(3,1,3)
stem(-kh,h,'fill','linewidth',2),grid on
legend('h[-k]')
1
x[k]
0.5

0
-4 -2 0 2 4 6 8 10
15
h[k]
10

0
-4 -2 0 2 4 6 8 10
15
h[-k]
10

0
-10 -8 -6 -4 -2 0 2 4

close all
figure();
kx=-4:10;
x=[0 0 0 0 1 1 1 1 1 0 0 0 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=0;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[0-k]')
xlim([-10 12])

figure();
kx=-4:10;
x=[0 0 0 0 1 1 1 1 1 0 0 0 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=1;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[1-k]')
xlim([-10 12])

figure();
kx=-4:10;
x=[0 0 0 0 1 1 1 1 1 0 0 0 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=2;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[2-k]')
xlim([-10 12])

figure();
kx=-4:10;
x=[0 0 0 0 1 1 1 1 1 0 0 0 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=3;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[3-k]')
xlim([-10 12])

figure();
kx=-4:10;
x=[0 0 0 0 1 1 1 1 1 0 0 0 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=4;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[4-k]')
xlim([-10 12])

figure();
kx=-4:10;
x=[0 0 0 0 1 1 1 1 1 0 0 0 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=5;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[5-k]')
xlim([-10 12])

figure();
kx=-4:10;
x=[0 0 0 0 1 1 1 1 1 0 0 0 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=6;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[6-k]')
xlim([-10 12])

figure();
kx=-4:10;
x=[0 0 0 0 1 1 1 1 1 0 0 0 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=7;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[7-k]')
xlim([-10 12])

figure();
kx=-4:10;
x=[0 0 0 0 1 1 1 1 1 0 0 0 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=8;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[8-k]')
xlim([-10 12])

figure();
kx=-4:10;
x=[0 0 0 0 1 1 1 1 1 0 0 0 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=9;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[9-k]')
xlim([-10 12])

figure();
kx=-4:10;
x=[0 0 0 0 1 1 1 1 1 0 0 0 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=10;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[10-k]')
xlim([-10 12])

figure();
kx=-4:10;
x=[0 0 0 0 1 1 1 1 1 0 0 0 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=11;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[11-k]')
xlim([-10 12])

%----------------------------------------------------------------
%CONVULUTION:
figure();
y=[12.5 2.75 6.12 11.18 19.77 29.66 27.41 24.04 18.98 11.39];
yn=0:10;
stem(yn,y,'fill','linewidth',2),grid on
legend('y[n]')
1 1
x[k] x[k]
0.8 0.8

0.6 0.6

0.4 0.4

0.2 0.2

0 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12

15 15
h[0-k] h[1-k]

10 10

5 5

0 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12

1 1
x[k] x[k]
0.8 0.8

0.6 0.6

0.4 0.4

0.2 0.2

0 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12

15 15
h[2-k] h[3-k]

10 10

5 5

0 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12

1 1
x[k] x[k]
0.8 0.8

0.6
0.6
0.4
0.4
0.2
0.2 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12
0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12
15
h[5-k]
15 10
h[4-k]
5
10

0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12
5

0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12
1
x[k]
0.8

0.6
1
x[k] 0.4
0.8

0.6 0.2
0.4
0
0.2 -10 -8 -6 -4 -2 0 2 4 6 8 10 12

0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12
15
h[7-k]
15
h[6-k] 10
10

5
5

0
0 -10 -8 -6 -4 -2 0 2 4 6 8 10 12
-10 -8 -6 -4 -2 0 2 4 6 8 10 12

1
x[k] 1
0.8
x[k]
0.8
0.6
0.6
0.4
0.4
0.2
0.2
0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12

15
15
h[8-k]
h[9-k]
10
10

5 5

0 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12
1
x[k]
0.8

0.6
1
0.4
x[k]
0.8
0.2
0.6

0.4 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12
0.2

0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 15
h[11-k]
15
h[10-k]
10

10
5
5

0
0 -10 -8 -6 -4 -2 0 2 4 6 8 10 12
-10 -8 -6 -4 -2 0 2 4 6 8 10 12

30
y[n]

25

20

15

10

0
0 1 2 3 4 5 6 7 8 9 10

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 1:
hn=0:6;
xn=0:6;
h=[1 1 1 1 1 1 1];
x=2.^xn .*(xn<=0);
subplot(3,1,1)
stem(xn,x,'fill','linewidth',2),grid on
xlim([-1 8])
legend('x[n]')
subplot(3,1,2)
stem(hn,h,'fill','linewidth',2),grid on
xlim([-1 8])
legend('h[n]')
y=conv(h,x);
subplot(3,1,3)
n=0:12;
stem(n,y,'fill','linewidth',2),grid on
legend('y[n]=[n]*h[n]')
xlim([-1 8])
1
x[n]
0.5

0
-1 0 1 2 3 4 5 6 7 8
1
h[n]
0.5

0
-1 0 1 2 3 4 5 6 7 8
1
y[n]=[n]*h[n]
0.5

0
-1 0 1 2 3 4 5 6 7 8

METHOD 2:
%STEP 1:

kx=0:6
x=2.^kx .*(kx<=0);
subplot(3,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

kh=0:6
h=[1 1 1 1 1 1 1];
subplot(3,1,2)
stem(kh,h,'fill','linewidth',2),grid on
legend('h[k]')
xlim([-10 12])
%
%-----------------------------------------------------------
%STEP 2:
subplot(3,1,3)
stem(-kh,h,'fill','linewidth',2),grid on
legend('h[-k]')
xlim([-10 12])

close all
figure();
kx=0:6;
x=2.^kx .*(kx<=0);
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=0;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[0-k]')
xlim([-10 12])

figure();
kx=0:6;
x=2.^kx .*(kx<=0);
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=1;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[1-k]')
xlim([-10 12])

figure();
kx=0:6;
x=2.^kx .*(kx<=0);
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=2;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[2-k]')
xlim([-10 12])

figure();
kx=0:6;
x=2.^kx .*(kx<=0);
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=3;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[3-k]')
xlim([-10 12])
figure();
kx=0:6;
x=2.^kx .*(kx<=0);
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=4;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[4-k]')
xlim([-10 12])

figure();
kx=0:6;
x=2.^kx .*(kx<=0);
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=5;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[5-k]')
xlim([-10 12])

figure();
kx=0:6;
x=2.^kx .*(kx<=0);
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=6;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[6-k]')
xlim([-10 12])

figure();
kx=0:6;
x=2.^kx .*(kx<=0);
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=7;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[7-k]')
xlim([-10 12])

figure();
kx=0:6;
x=2.^kx .*(kx<=0);
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=8;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[8-k]')
xlim([-10 12])

figure();
kx=0:6;
x=2.^kx .*(kx<=0);
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=9;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[9-k]')
xlim([-10 12])

figure();
kx=0:6;
x=2.^kx .*(kx<=0);
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=10;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[10-k]')
xlim([-10 12])

figure();
kx=0:6;
x=2.^kx .*(kx<=0);
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=11;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[11-k]')
xlim([-10 12])

figure();
kx=0:6;
x=2.^kx .*(kx<=0);
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=12;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[12-k]')
xlim([-10 12])

figure();
kx=0:6;
x=2.^kx .*(kx<=0);
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-10 12])

n=13;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[13-k]')
xlim([-10 12])

% %CONVULUTION:
figure();
y=[1 1 1 1 1 1 1]
yn=0:6;
stem(yn,y,'fill','linewidth',2),grid on
legend('y[n]')
xlim([-2 8])
1 1
x[k] x[k]
0.8 0.8

0.6 0.6

0.4 0.4

0.2 0.2

0 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12

1 1
h[0-k] h[1-k]
0.8 0.8

0.6 0.6

0.4 0.4

0.2 0.2

0 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12

1 1
x[k] x[k]
0.8 0.8

0.6 0.6

0.4 0.4

0.2 0.2

0 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12

1 1
h[2-k] h[3-k]
0.8 0.8

0.6 0.6

0.4 0.4

0.2 0.2

0 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12

1
x[k] 1
0.8
x[k]
0.8
0.6
0.6
0.4
0.4
0.2
0.2
0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12

1
1
h[4-k]
0.8 h[5-k]
0.8
0.6
0.6
0.4 0.4
0.2 0.2

0 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12

1
x[k]
0.8

0.6
1
0.4
x[k]
0.8
0.2
0.6

0.4 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12
0.2

0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 1
h[7-k]
0.8
1
h[6-k] 0.6
0.8

0.6 0.4
0.4
0.2
0.2
0
0 -10 -8 -6 -4 -2 0 2 4 6 8 10 12
-10 -8 -6 -4 -2 0 2 4 6 8 10 12
1
x[k]
0.8

0.6

0.4
1
x[k]
0.2 0.8

0.6
0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 0.4

0.2
1 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12
h[8-k]
0.8
1
0.6 h[9-k]
0.8
0.4 0.6

0.2 0.4

0.2
0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12

1 1
x[k] x[k]
0.8 0.8

0.6 0.6

0.4 0.4

0.2 0.2

0 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12

1 1
h[10-k] h[11-k]
0.8 0.8

0.6 0.6

0.4 0.4

0.2 0.2

0 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12

1 1
x[k] x[k]
0.8 0.8

0.6 0.6

0.4 0.4

0.2 0.2

0 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12

1 1
h[12-k] h[13-k]
0.8 0.8

0.6 0.6

0.4 0.4

0.2 0.2

0 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12

1
y[n]
0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-2 -1 0 1 2 3 4 5 6 7 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] .

Task 05: Compute (by both procedures) and graph the convolution y[n] , where
(a) y[n] u[n]* u[n], 0 n 6
(b) y[n] 3 [n 4]*(3 4)n u[n],0 n 5

METHOD 1:
hn=0:6;
xn=0:6;
h=[1 0 -1 0 0 0 0];
x=[1 1 1 1 0 0 0];
subplot(3,1,1)
stem(xn,x,'fill','linewidth',2),grid on

legend('x[n]')
subplot(3,1,2)
stem(hn,h,'fill','linewidth',2),grid on

legend('h[n]')
y=conv(h,x);
subplot(3,1,3)
stem(0:12,y,'fill','linewidth',2),grid on
legend('y[n]=[n]*h[n]')
1
x[n]
0.5

0
0 1 2 3 4 5 6
1
h[n]
0

-1
0 1 2 3 4 5 6
1
y[n]=[n]*h[n]
0

-1
0 2 4 6 8 10 12

METHOD 2:
%STEP 1:

kx=0:6
x=[1 1 1 1 0 0 0];
subplot(3,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
axis([-4 8 -1 1])

kh=0:6
h=[1 0 -1 0 0 0 0];
subplot(3,1,2)
stem(kh,h,'fill','linewidth',2),grid on
legend('h[k]')
xlim([-4 8])
%
%-----------------------------------------------------------
%STEP 2:
subplot(3,1,3)
stem(-kh,h,'fill','linewidth',2),grid on
legend('h[-k]')
xlim([-4 8])
1
x[k]
0

-1
-4 -2 0 2 4 6 8
1
h[k]
0

-1
-4 -2 0 2 4 6 8
1
h[-k]
0

-1
-4 -2 0 2 4 6 8

close all
figure();
kx=0:6;
x=[1 1 1 1 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
axis([-4 8 -1 1])

n=0;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[0-k]')
xlim([-4 8])

figure();
kx=0:6;
x=[1 1 1 1 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
axis([-4 8 -1 1])

n=1;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[1-k]')
xlim([-4 8])

figure();
kx=0:6;
x=[1 1 1 1 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
axis([-4 8 -1 1])

n=2;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[2-k]')
xlim([-4 8])

figure();
kx=0:6;
x=[1 1 1 1 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
axis([-4 8 -1 1])

n=3;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[3-k]')
xlim([-4 8])

figure();
kx=0:6;
x=[1 1 1 1 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
axis([-4 8 -1 1])

n=4;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[4-k]')
xlim([-4 8])

figure();
kx=0:6;
x=[1 1 1 1 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
axis([-4 8 -1 1])

n=5;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[5-k]')
xlim([-4 8])

figure();
kx=0:6;
x=[1 1 1 1 0 0 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
axis([-4 8 -1 1])

n=6;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[6-k]')
xlim([-4 8])

% %--------------------------------------------------------------
--
% %CONVULUTION:
figure();
y=[1 1 0 0 -1 -1 0]
yn=0:6;
stem(yn,y,'fill','linewidth',2),grid on
legend('y[n]')

1
x[k]
0.5

0
1
x[k]
0.5 -0.5

0
-1
-4 -2 0 2 4 6 8
-0.5

-1
-4 -2 0 2 4 6 8 1
h[1-k]
1 0.5
h[0-k]
0.5
0
0
-0.5
-0.5
-1
-1 -4 -2 0 2 4 6 8
-4 -2 0 2 4 6 8
1
x[k]
0.5

0
1
-0.5 x[k]
0.5

-1 0
-4 -2 0 2 4 6 8
-0.5

1 -1
-4 -2 0 2 4 6 8
h[2-k]
0.5
1
h[3-k]
0 0.5

0
-0.5
-0.5
-1
-4 -2 0 2 4 6 8 -1
-4 -2 0 2 4 6 8

1 1
x[k] x[k]
0.5 0.5

0 0

-0.5 -0.5

-1 -1
-4 -2 0 2 4 6 8 -4 -2 0 2 4 6 8

1 1
h[4-k] h[5-k]
0.5 0.5

0 0

-0.5 -0.5

-1 -1
-4 -2 0 2 4 6 8 -4 -2 0 2 4 6 8

1
x[k]
0.5

-0.5

-1
-4 -2 0 2 4 6 8

1
h[6-k]
0.5

-0.5

-1
-4 -2 0 2 4 6 8

1
y[n]
0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 1 2 3 4 5 6
METHOD 1:

hn=0:6;
xn=0:6;
h=ones(size(hn));
x=ones(size(xn));
subplot(3,1,1)
stem(xn,x,'fill','linewidth',2),grid on

legend('x[n]')
subplot(3,1,2)
stem(hn,h,'fill','linewidth',2),grid on

legend('h[n]')
y=conv(h,x);
subplot(3,1,3)
stem(0:12,y,'fill','linewidth',2),grid on
legend('y[n]=[n]*h[n]')

1
x[n]
0.5

0
0 1 2 3 4 5 6
1
h[n]
0.5

0
0 1 2 3 4 5 6
10
y[n]=[n]*h[n]
5

0
0 2 4 6 8 10 12

METHOD 2:
%STEP 1:

kx=0:6;
x=ones(size(kx));
subplot(3,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-8 8])

kh=0:6;
h=ones(size(kh));
subplot(3,1,2)
stem(kh,h,'fill','linewidth',2),grid on
legend('h[k]')
xlim([-8 8])

%-----------------------------------------------------------
%STEP 2:
subplot(3,1,3)
stem(-kh,h,'fill','linewidth',2),grid on
legend('h[-k]')
xlim([-8 8])

1
x[k]
0.5

0
-8 -6 -4 -2 0 2 4 6 8
1
h[k]
0.5

0
-8 -6 -4 -2 0 2 4 6 8
1
h[-k]
0.5

0
-8 -6 -4 -2 0 2 4 6 8

%-----------------------------------------------------------
close all
figure();
kx=0:6;
x=ones(size(kx));
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-8 16])

n=0;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[0-k]')
xlim([-8 16])

figure();
kx=0:6;
x=ones(size(kx));
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-8 16])

n=1;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[1-k]')
xlim([-8 16])

figure();
kx=0:6;
x=ones(size(kx));
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-8 16])

n=2;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[2-k]')
xlim([-8 16])

figure();
kx=0:6;
x=ones(size(kx));
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-8 16])

n=3;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[3-k]')
xlim([-8 16])
figure();
kx=0:6;
x=ones(size(kx));
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-8 16])

n=4;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[4-k]')
xlim([-8 16])

figure();
kx=0:6;
x=ones(size(kx));
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-8 16])

n=5;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[5-k]')
xlim([-8 16])

figure();
kx=0:6;
x=ones(size(kx));
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-8 16])

n=6;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[6-k]')
xlim([-8 16])

figure();
kx=0:6;
x=ones(size(kx));
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-8 16])
n=7;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[7-k]')
xlim([-8 16])

figure();
kx=0:6;
x=ones(size(kx));
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-8 16])

n=8;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[8-k]')
xlim([-8 16])

figure();
kx=0:6;
x=ones(size(kx));
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-8 16])

n=9;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[9-k]')
xlim([-8 16])

figure();
kx=0:6;
x=ones(size(kx));
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-8 16])

n=10;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[10-k]')
xlim([-8 16])

figure();
kx=0:6;
x=ones(size(kx));
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-8 16])

n=11;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[11-k]')
xlim([-8 16])

figure();
kx=0:6;
x=ones(size(kx));
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-8 16])

n=12;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[12-k]')
xlim([-8 16])

figure();
kx=0:6;
x=ones(size(kx));
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
legend('x[k]')
xlim([-8 16])

n=13;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
legend('h[13-k]')
xlim([-8 16])

% %--------------------------------------------------------------
--
% %CONVULUTION:
figure();
y=[1 2 3 4 5 6 7 6 5 4 3 2 1];
yn=0:12;
stem(yn,y,'fill','linewidth',2),grid on
legend('y[n]')
1
x[k] 1
0.8
x[k]
0.8
0.6
0.6
0.4
0.4
0.2
0.2
0
-5 0 5 10 15 0
-5 0 5 10 15

1
1
h[0-k]
0.8 h[1-k]
0.8
0.6 0.6
0.4 0.4
0.2 0.2

0 0
-5 0 5 10 15 -5 0 5 10 15

1
1 x[k]
0.8
x[k]
0.8
0.6
0.6
0.4
0.4
0.2
0.2
0
0 -5 0 5 10 15
-5 0 5 10 15

1
1
h[3-k]
h[2-k] 0.8
0.8
0.6
0.6

0.4
0.4

0.2 0.2

0 0
-5 0 5 10 15 -5 0 5 10 15

1 1
x[k] x[k]
0.8 0.8

0.6 0.6

0.4 0.4

0.2 0.2

0 0
-5 0 5 10 15 -5 0 5 10 15

1 1
h[4-k] h[5-k]
0.8 0.8

0.6 0.6

0.4 0.4

0.2 0.2

0 0
-5 0 5 10 15 -5 0 5 10 15

1
x[k]
0.8

0.6
1
x[k] 0.4
0.8

0.6 0.2
0.4
0
0.2 -5 0 5 10 15

0
-5 0 5 10 15
1
h[7-k]
1 0.8
h[6-k]
0.8 0.6
0.6
0.4
0.4
0.2
0.2
0
0 -5 0 5 10 15
-5 0 5 10 15

1
x[k]
0.8

0.6
1
0.4
x[k]
0.8
0.2
0.6

0.4 0
-5 0 5 10 15
0.2

0
-5 0 5 10 15 1
h[9-k]
0.8
1
h[8-k] 0.6
0.8

0.6 0.4
0.4
0.2
0.2
0
0 -5 0 5 10 15
-5 0 5 10 15
1
x[k]
0.8

0.6

0.4

0.2

0
-5 0 5 10 15

1
h[10-k]
0.8

0.6

0.4

0.2

0
-5 0 5 10 15

1
x[k]
0.8

0.6

0.4

0.2

0
-5 0 5 10 15

1
h[11-k]
0.8

0.6

0.4

0.2

0
-5 0 5 10 15

1
1 x[k]
0.8
x[k]
0.8
0.6
0.6
0.4
0.4
0.2
0.2
0
0 -5 0 5 10 15
-5 0 5 10 15

1
1
h[12-k]
h[11-k] 0.8
0.8
0.6
0.6

0.4
0.4

0.2 0.2

0 0
-5 0 5 10 15 -5 0 5 10 15

1 1
x[k] x[k]
0.8 0.8

0.6 0.6

0.4 0.4

0.2 0.2

0 0
-5 0 5 10 15 -5 0 5 10 15

1 1
h[12-k] h[13-k]
0.8 0.8

0.6 0.6

0.4 0.4

0.2 0.2

0 0
-5 0 5 10 15 -5 0 5 10 15
7
y[n]

0
0 2 4 6 8 10 12

METHOD 1:
hn=0:5;
xn=0:5;
h=((3/4).^hn).*(hn>=0);
x=[0 0 0 0 3 0];
subplot(3,1,1)
stem(xn,x,'fill','linewidth',2),grid on

legend('x[n]')
subplot(3,1,2)
stem(hn,h,'fill','linewidth',2),grid on

legend('h[n]')
y=conv(h,x);
subplot(3,1,3)
stem(0:10,y,'fill','linewidth',2),grid on
legend('y[n]=[n]*h[n]')
3
x[n]
2

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
1
h[n]
0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
3
y[n]=[n]*h[n]
2

0
0 1 2 3 4 5 6 7 8 9 10

METHOD 2:
%STEP 1:

kx=0:5
x=[0 0 0 0 3 0];
subplot(3,1,1)
stem(kx,x,'fill','linewidth',2),grid on
xlim([-7 15])
legend('x[k]')

kh=0:5
h=((3/4).^hn).*(hn>=0);
subplot(3,1,2)
stem(kh,h,'fill','linewidth',2),grid on
legend('h[k]')
xlim([-7 15])
%
%-----------------------------------------------------------
%STEP 2:
subplot(3,1,3)
stem(-kh,h,'fill','linewidth',2),grid on
legend('h[-k]')
xlim([-7 15])
3
x[k]
2

0
-6 -4 -2 0 2 4 6 8 10 12 14
1
h[k]
0.5

0
-6 -4 -2 0 2 4 6 8 10 12 14
1
h[-k]
0.5

0
-6 -4 -2 0 2 4 6 8 10 12 14

close all
figure();
kx=0:5;
x=[0 0 0 0 3 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
xlim([-7 15])
legend('x[k]')

n=0;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
xlim([-7 15])
legend('h[0-k]')

figure();
kx=0:5;
x=[0 0 0 0 3 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
xlim([-7 15])
legend('x[k]')

n=1;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
xlim([-7 15])
legend('h[1-k]')

figure();
kx=0:5;
x=[0 0 0 0 3 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
xlim([-7 15])
legend('x[k]')

n=2;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
xlim([-7 15])
legend('h[2-k]')

figure();
kx=0:5;
x=[0 0 0 0 3 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
xlim([-7 15])
legend('x[k]')

n=3;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
xlim([-7 15])
legend('h[3-k]')

figure();
kx=0:5;
x=[0 0 0 0 3 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
xlim([-7 15])
legend('x[k]')

n=4;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
xlim([-7 15])
legend('h[4-k]')

figure();
kx=0:5;
x=[0 0 0 0 3 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
xlim([-7 15])
legend('x[k]')

n=5;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
xlim([-7 15])
legend('h[5-k]')

figure();
kx=0:5;
x=[0 0 0 0 3 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
xlim([-7 15])
legend('x[k]')

n=6;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
xlim([-7 15])
legend('h[6-k]')

figure();
kx=0:5;
x=[0 0 0 0 3 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
xlim([-7 15])
legend('x[k]')

n=7;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
xlim([-7 15])
legend('h[7-k]')

figure();
kx=0:5;
x=[0 0 0 0 3 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
xlim([-7 15])
legend('x[k]')

n=8;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
xlim([-7 15])
legend('h[8-k]')

figure();
kx=0:5;
x=[0 0 0 0 3 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
xlim([-7 15])
legend('x[k]')

n=9;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
xlim([-7 15])
legend('h[9-k]')

figure();
kx=0:5;
x=[0 0 0 0 3 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
xlim([-7 15])
legend('x[k]')

n=10;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
xlim([-7 15])
legend('h[10-k]')

figure();
kx=0:5;
x=[0 0 0 0 3 0];
subplot(2,1,1)
stem(kx,x,'fill','linewidth',2),grid on
xlim([-7 15])
legend('x[k]')

n=11;
subplot(2,1,2)
stem(-kh+n,h,'fill','linewidth',2),grid on
xlim([-7 15])
legend('h[11-k]')

% %--------------------------------------------------------------
--
% %CONVULUTION:
figure();
y=[0 0 0 0 3 2.2 1.8 1.2 1 0.8 0];
yn=0:10;
stem(yn,y,'fill','linewidth',2),grid on
legend('y[n]')
3
x[k]

0
-6 -4 -2 0 2 4 6 8 10 12 14

1
h[0-k]
0.8

0.6

0.4

0.2

0
-6 -4 -2 0 2 4 6 8 10 12 14

3
x[k]

0
-6 -4 -2 0 2 4 6 8 10 12 14

1
h[1-k]
0.8

0.6

0.4

0.2

0
-6 -4 -2 0 2 4 6 8 10 12 14

3
x[k]

0
-6 -4 -2 0 2 4 6 8 10 12 14

1
h[2-k]
0.8

0.6

0.4

0.2

0
-6 -4 -2 0 2 4 6 8 10 12 14

3
x[k]

0
-6 -4 -2 0 2 4 6 8 10 12 14

1
h[3-k]
0.8

0.6

0.4

0.2

0
-6 -4 -2 0 2 4 6 8 10 12 14
3
x[k]

0
-6 -4 -2 0 2 4 6 8 10 12 14

1
h[4-k]
0.8

0.6

0.4

0.2

0
-6 -4 -2 0 2 4 6 8 10 12 14

3
x[k]

0
-6 -4 -2 0 2 4 6 8 10 12 14

1
h[5-k]
0.8

0.6

0.4

0.2

0
-6 -4 -2 0 2 4 6 8 10 12 14

3
x[k]

0
-6 -4 -2 0 2 4 6 8 10 12 14

1
h[6-k]
0.8

0.6

0.4

0.2

0
-6 -4 -2 0 2 4 6 8 10 12 14

3
x[k]

0
-6 -4 -2 0 2 4 6 8 10 12 14

1
h[7-k]
0.8

0.6

0.4

0.2

0
-6 -4 -2 0 2 4 6 8 10 12 14
3
x[k]

0
-6 -4 -2 0 2 4 6 8 10 12 14

1
h[8-k]
0.8

0.6

0.4

0.2

0
-6 -4 -2 0 2 4 6 8 10 12 14

3
x[k]

0
-6 -4 -2 0 2 4 6 8 10 12 14

1
h[9-k]
0.8

0.6

0.4

0.2

0
-6 -4 -2 0 2 4 6 8 10 12 14

3
x[k]

0
-6 -4 -2 0 2 4 6 8 10 12 14

1
h[10-k]
0.8

0.6

0.4

0.2

0
-6 -4 -2 0 2 4 6 8 10 12 14

3
x[k]

0
-6 -4 -2 0 2 4 6 8 10 12 14

1
h[11-k]
0.8

0.6

0.4

0.2

0
-6 -4 -2 0 2 4 6 8 10 12 14
3
y[n]

2.5

1.5

0.5

0
0 1 2 3 4 5 6 7 8 9 10

Post-Lab Tasks
Critical Analysis / Conclusion
In this lab we have implemented convolution of discrete time signals using conv
command (Matlab built) and by using analytical approach .successfully implemented
the code in Matlab and found the plots.

You might also like