Lab 04 DSIP
Lab 04 DSIP
1 10
•Plot x sequence 6
•x = [3,11,7,0,-1,4,2];
4
•stem(x)
2
-2
1 2 3 4 5 6 7
3
0
•Plot h sequence
•h = [2, 3, 0, -5, 2, 1]; -1
•stem(h)
-2
-3
-4
-5
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
Example: 1 given the following two
sequences: x(n) = [3,11,7, 0, -1,4,2], h(n) = 60
[2,3,0, -5,2,1]
determine the convolution y(n) = x(n) * h(n). 40
20
y = conv(x,h)
y=
-20
-40
6 31 47 6 -51 -5 41
18 -22 -3 8 2 -60
0 2 4 6 8 10 12
Example 4
02 3.5
2.5
Plot x[n]=[1 2 3 4] with -1≤n≤2
x = [1 2 3 4]; 2
Lx=length(x); 1.5
nx=0:Lx-1; 1
figure, stem(nx-1,x),
grid on 0.5
0
-1 -0.5 0 0.5 1 1.5 2
Example 4
03 3.5
2.5
For example, given the following two
sequences: 2
h = [5 6 4 9 2]; 5
Lh=length(h); 4
nh=0:Lh-1;
3
figure, stem(nh-2,h),
grid on 2
0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
60
50
40
y = conv(x,h);
Ly=length(y); 30
ny=0:Ly-1;
20
figure, stem(ny-4,y),
grid on 10
0
-4 -3 -2 -1 0 1 2 3
h[n]
Example 04
1
0.9
0.8
0.7
0.5
clear all
close all 0.4
n=-10:1:100; 0.3
x=1*(n>=0);
stem(n,x);grid on 0.2
a=0.9; 0.1
h=(a.^n).*x;
0
figure,stem(n,h);grid on -20 0 20 40 60 80 100
x[n]
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-20 0 20 40 60 80 100
clear all
close all
n=-10:1:100;
x=1*(n>=0);
a=0.9;
h=(a.^n).*x;
y = conv(x,h);
Lx=length(x);
Lh=length(h);
Ly=length(y);
nx=0:Lx-1;
nh=0:Lh-1;
ny=0:Ly-1;
figure, stem(nx-10,x);title('x[n]');grid on
figure, stem(nh-10,h);title('h[n]');grid on
figure, stem(ny-20,y);title('y[n]');grid on
output
y[n]
10
0
-50 0 50 100 150 200
For example, given the following two sequences:
x(n) = [1 2 3 1], 0n3; h(n) = [1 2 1 -1], -1n2
determine the convolution y(n) = x(n) * h(n).
x = [0 1 2 3 1];
h = [1 2 1 -1];
y = conv(x,h);
Lx=length(x);
Lh=length(h);
Ly=length(y);
nx=0:Lx-1;
nh=0:Lh-1;
ny=0:Ly-1;
figure, stem(nx-1,x); title('x[n]');grid on
figure, stem(nh-1,h);title('h[n]');grid on
figure, stem(ny-2,y);title('y[n]');grid on
grid on
output
x[n]
3 h[n]
2 y[n]
8
2.5 7
1.5
6
2
1 5
4
1.5
0.5 3
2
1 0
1
0.5 0
-0.5
-1
0 -1 -2
-1 -0.5 0 0.5 1 1.5 2 2.5 3 -1 -0.5 0 0.5 1 1.5 2 -2 -1 0 1 2 3 4 5
Lab task#01
Compute and plot the convolutions x(n)*h(n) for the pairs of signals
shown in Fig.
Lab task#02