Lab No 3
Lab No 3
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:
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.
xo ( n) xo (n)
if
Any arbitrary real-valued sequence x(n) can be decomposed into its even and odd
component
x( n) xe ( n) xo ( n)
Input: x[n]
Output: y[n]
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: