Professional Documents
Culture Documents
COURSE: DSP-3105
Laboratory Manual
Prepared by: Supervised by:
Saiful Islam Dr. Md. Junaebur Rashid
Lecturer of ICT, BUP Associate Professor of EEE, DU
Experiment Name: Study of Convolution and its Application
Objectives:
1. To understand shift and fold (reverse) operation in MATLAB.
2. To understand convolution of two sequences.
3. To learn how to generate and plot a rectangular pulse and impulse response in MATLAB.
4. To learn how to do convolution by difference equation in MATLAB.
5. To familiarize with a convolution application: speech signal and noise signal.
Pre-Lab works
1. Read carefully the experiment manual before attending the lab.
2. See the theory lecture notes (bring them with you if necessary).
3. Practice the examples given in this experiment at home for better class performance.
4. Do not bring any relevant MATLAB codes, neither in any portable device nor in written
form.
5. Familiarize yourself with the MATLAB commands that may be required for this lab (see
the list).
y ( n) = x ( n) * h( n)
= x ( k ) h( n − k )
k = −
Where the symbol [*] is used to denote convolution.
To obtain y(n0) at some instant of time, n = n0
y (n0 ) = x ( k ) h( n
k = −
0 − k)
Shifting
MATLAB can be used to perform shifting of signals. A signal can be delayed as well as advanced.
The basic idea is to add the shift value to indices and thereby plotting the signal. The following is a
program to delay or advance a signal x(n). The shift value is decided at the run time.
Code
n1=input('Enter the amount to be delayed=');
n2=input('Enter the amount to be advanced=');
n=-2:2;
x=[-2 3 0 1 5];
subplot(3,1,1);
stem(n,x);
title('Signal x(n)');
m=n+n1;
y=x;
subplot(3,1,2);
stem(m,y);
title('Delayed signal x(n-n1)');
t=n-n2;
z=x;
subplot(3,1,3);
stem(t,z);
title('Advanced signal x(n+n2)');
Output:
Enter the amount to be delayed=2
Enter the amount to be advanced=3
Folding or Reversing
The inbuilt function fliplr() function can be used to perform reversing or folding a signal.
Syntax
fliplr(a) : if a is row vector it returns a vector with the same size of a, but with reversed order. If a is
column vector it flips the elements one column to the other.
Basic Idea :
flip the elements
flip the indices with a ‘ – ‘ sign
Code
n=-1:2;
x=[3 -1 0 -4];
subplot(2,1,1)
stem(n,x);
axis([-3 3 -5 5]);
title('Signal x(n)');
c=fliplr(x);
y=fliplr(-n);
subplot(2,1,2);
stem(y,c);
axis([-3 3 -5 5]);
title('Reversed Signal x(-n)') ;
EXAMPLE
1. Two discrete sequences are as follows:
x=[3,11,7,0,-1,4,2]; y=[2,3,0,-5,2,1];
clc;
clear all;
close all;
% First sequence
x=[3,11,7,0,-1,4,2];
subplot(3,1,1)
stem(x)
xlabel('n')
ylabel('x(n)')
title('First sequence')
% Second sequence
y=[2,3,0,-5,2,1];
subplot(3,1,2)
stem(y)
xlabel('n')
ylabel('y(n)')
title('Second sequence')
z=conv(x,y);
subplot(3,1,3)
stem(z)
axis([-4,7,-60,60]) % Set axis limits and appearance
xlabel('n')
ylabel('z(n)= x(n)* y(n)')
title('Convolution of sequence')
MATLAB Coding (Convolution of a Rectangular pulse)
Calculate and plot the discrete convolution in each case. Level the X and Y coordinate and use
a title of the response.
% Convolution of a rectangular pulse
clc;
clear all;
close all
n=-5:50;
u1=[zeros(1,5),ones(1,51)]; % generation of u(n)
u2=[zeros(1,15),ones(1,41)]; % generation of u(n-10)
x=u1-u2;
subplot(4,1,1)
stem(n,x)
xlabel('n')
ylabel('x(n)')
title('Rectangular pulse')
% Step: 01
a=conv(x,x)
subplot(4,1,2)
stem(a)
xlabel('n')
ylabel('a(n)= x(n) * x(n)')
title('Convolution of rectangular pulse: 01')
% Step: 02
b=conv(a,x)
subplot(4,1,3)
stem(b)
xlabel('n')
ylabel('b(n)= a(n) * x(n)')
title('Convolution of rectangular pulse: 02')
% Step: 03
c=conv(b,x)
subplot(4,1,4)
stem(c)
xlabel('n')
ylabel('c(n)= b(n) * x(n)')
title('Convolution of rectangular pulse: 03')
LAB WORK: 01
Let us consider a discrete system whose input sequence (rectangular pulse) is of finite duration
given by:
x(n) = u(n) − u(n − 10)
while the impulse response is of infinite duration:
n
h(n) = (0.9) u(n)
PART A
a. Generate the rectangular pulse in MATLAB.
b. Generate the impulse response in MATLAB.
c. Determine z(n) = x(n) ∗ h(n) [convolution of rectangular pulse and impulse response)
PART B
Calculate and plot the discrete convolution in each case. Level the X and Y coordinate and use a
title of the response.
Hint:
1. At first write the difference equation of the impulse response. It can be done as follows:
If the LTI system, given by the impulse response h(n), can be described by a difference equation,
then y(n) can be obtained from the filter function. From the h(n) expression
n-1
(0.9) h(n − 1) = (0.9) (0.9) u(n − 1)
n
= (0.9) u(n − 1)
or
n n
h(n) − (0.9) h(n − 1) = (0.9) u(n) − (0.9) u(n − 1)
n
= (0.9) [u(n) − u(n − 1)]
n
= (0.9) δ(n)
= δ(n)
The last step follows from the fact that δ(n) is nonzero only at n = 0. By definition h(n) is the
output of an LTI system when the input is δ(n). Hence substituting x(n) for δ(n) and y(n) for h(n),
the difference equation is:
y(n) − 0.9y(n − 1) = x(n)
s=filter(b,a,x)
LAB WORK: 02
Convolution of a speech signal with a noise signal
a. Load a supplied speech signal into MATLAB using the command
[y,Fs] = audioread('handel.wav').
b. Generate a colored noise signal using: Channel =1 and Samples = 1000.
c. Do convolution between loaded speech and noise signal. Observe the waveform and
comment on it if you find any change after the convolution with noise signal.
Plot and Level the X and Y coordinate and use a title of the response.
REPORT:
1. Submit a report on your lab work along with the corresponding MATLAB script file and
figure window for each work.
2. Clearly label x-axis, y-axis, and title in each figure.
3. Answer all the questions in Lab Work.
Warning
1. Don’t copy from your mates.
Reference
1. Digital Signal Processing Using MATLAB®, Third Edition Vinay K. Ingle, John G.
Proakis.