Lab 4 Convolution
Lab 4 Convolution
LAB # 4
DISCRETE TIME CONVOLUTION
OBJECTIVE:
The basic objective of this lab is to perform the convolution in Matlab.
The convolution between two discrete time signals is computed by using the MATLAB
command conv.
The process that has to be followed to analytically derive the convolution sum is as follows.
First, the input and impulse response signals are plotted in the k -axis. One of the two signals is
reversed about the amplitude axis and its reflection is shifted from -∞ to +∞ by changing
appropriately the value of n. The output of the system is computed from the overlapping values
of x[n]and h[n - k] according to the convolution sum
1
DSP Lab Manual, Electrical Engineering Department, COMSATS Institute of IT, Islamabad
There are three basic principles that should be considered while computing the convolution
between two discrete time signals x[n] and h[n]using conv command as follows:
y=conv (x,h)
1. The length and time inyerval of input and impulse response should be same.
2. There should be no overlap between interval for input and impulse response signal.
3. The length of output vector ‘y’ should be calculated by following formulae:
2. If non zeros values of x[n] are in the interval [ ax , bx ] and non zero values of h[n] are in the
Interval [ah , bh] then the non zero values of the output y[n] are in the interval [ ax+ah , bx+bh ].
– Step 1: time reversal of either signal (e.g., x[k] x[-k] or h[k] h[-k] )
– Step 3: multiply x [k] and h [n-k] for each k and then take the summation over k
Convolution can also be evaluated by using loops and if else statement with the following code:
Code:
2
DSP Lab Manual, Electrical Engineering Department, COMSATS Institute of IT, Islamabad
n=length(h)
X=[x,zeros(1,m)]
H=[h,zeros(1,n)]
for i=1:n+m-1
Y(i)=0
for j=1:m
if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
else
end
end
end
Y;
stem(Y)
ylabel('Y[n]')
xlabel('----->n');
3
DSP Lab Manual, Electrical Engineering Department, COMSATS Institute of IT, Islamabad
Lab Tasks
In-Lab Task 01: Compute convolution of following signals by using 'conv' command and loops
Post-Lab Task 01: Compute convolution of following signals by using 'conv' command and
loops