You are on page 1of 4

COMSATS INSTITUTE OF INFORMATION TECHNOLOGY

Digital Signal Processing


Lab#3
Convolution of Discrete-Time Sequences

Objective:
By the end of this lab students will be able to get output from LTI systems by
convolving input with impulse responses.

Pre-Lab Tasks
Useful Commands:

conv: Convolution and polynomial multiplication.

filter: filters the data in vector X with the filter described by vectors A and B
to create the filtered data.

subplot: breaks the Figure window into an m-by-n matrix of small axes,
selects the pth axes for the current plot, and returns the axis handle.

Even and odd synthesis


xe ( n) xe ( n)
if

then xe ( n) is called even( symmetric)

xo ( n) xo (n)
if

then xo (n) is called odd (antisymmetric )

Any arbitrary real-valued sequence x(n) can be decomposed into its even and odd
component

x( n) xe ( n) xo ( n)

xe ( n) 1 [ x(n) x( n)], xo ( n) 1 [ x(n) x( n)]


2
2
Codes for even and odd decomposition of signals
function [xe, xo, m] = evenodd(x,n)
if any(imag(x) ~= 0)

error('x is not a real sequence')


end
m = -fliplr(n);
m1 = min([m,n]); m2 = max([m,n]); m = m1:m2;
nm = n(1)-m(1); n1 = 1:length(n);
x1 = zeros(1,length(m));
x1(n1+nm) = x; x = x1;
xe = 0.5*(x + fliplr(x));
xo = 0.5*(x - fliplr(x));
% MATLAB code example 2
n = [0:10]; x = stepseq(0,0,10)-stepseq(10,0,10);
[xe,xo,m] = evenodd(x,n);
subplot(1,1,1)
subplot(2,2,1); stem(n,x); title('Rectangular pulse')
xlabel('n'); ylabel('x(n)'); axis([-10,10,0,1.2])
subplot(2,2,2); stem(m,xe); title('Even Part')
xlabel('n'); ylabel('xe(n)'); axis([-10,10,0,1.2])
subplot(2,2,4); stem(m,xo); title('Odd Part')
xlabel('n'); ylabel('xo(n)'); axis([-10,10,-0.6,0.6])
Convolution
Convolution is a weighted moving average with one signal flipped back to front.

Input: x[n]

Impulse Response: h[n]

Output: y[n]

A single point of the convolution function is calculated as:


first, one signal is flipped back to front
then, one signal is shifted with respect to the other
the amount of the shift is the position of the convolution function point to be
calculated
each element of one signal is multiplied by the corresponding element of the other
the area under the resulting curve is integrated

In-Lab Tasks
Task1:
Convolution can be evaluated in many different ways.
If arbitrary sequences are of infinite duration, then MATLAB cannot be used directly to
compute the convolution.
As you already know, there are 3 conditions (cases) for evaluation:
No overlap
Partially overlap
Complete overlap
A built in function to compute convolution of 2 finite duration is called conv.
It assumes that the two sequences begin at n = 0:
>> y = conv(x,h)

Convolved sequence

50

10

y(n)

x(m )

0
-50
-100

10

15

n
Sequence y(o)

y(o)

5
0

0
-2
-4
-6

Sequence x(m)

15

Is This Correct???

-5

4
m

Based on the plots, conv function neither provides nor accepts any timing information.
We need the beginning and the end point of y(n).
A simple extension of the conv function, called conv_m, can be written to perform
the convolution of arbitrary support sequences:
function [y,ny] = conv_m(x,nx,h,nh)
% Modified convolution routine for signal processing
% ----------------------------------------------------% [y,ny] = conv_m(x,nx,h,nh)
% [y,ny] = convolution result
% [x,nx] = first signal
% [h,nh] = second signal
%
nyb = nx(1)+nh(1); nye = nx(length(x)) + nh(length(h));
ny = [nyb:nye];
y = conv(x,h);
Lets do the convolution again from the previous example:
x = [3,11,7,0,-1,4,2]; nx = [-3:3];
>> h = [2,3,0,-5,2,1]; nh = [-1:4];
>> [y,ny] = conv_m(x,nx,h,nh)
y=
6 31 47 6 -51 -5 41 18 -22 -3 8 2
ny =
-4 -3 -2 -1 0 1 2 3 4 5 6 7

Task-2:
Convolve following sequences using MATLAB Function conv and plot the
input, impulse response and output in one figure using subplot:

x[n] = [1 2 1], n=[0 1 2]


h[n] = [1 1 1], n= [0 1 2]

x[n] = [-1 4 -3 -2 1 0 2], n=[-2:4] h[n] = [1 1 1], n= [-1 0 1]

You might also like