You are on page 1of 7

CCE330(B)L MATLAB Applications in Signals and (Bio)Systems

Mr. Nashaat El Halabi

AMERICAN UNIVERSITY OF SCIENCE & TECHNOLOGY


DEPARTMENT OF COMPUTER AND COMMUNICATIONS ENGINEERING
DEPARTMENT OF BIOMEDICAL ENGINEERING

CCE330(B)L: MATLAB APPLICATIONS IN SIGNALS


AND (BIO)SYSTEMS
LAB No. 4
Linear Time-Invariant Systems
Purpose:
This laboratory session will introduce the students to convolution and let them understand
some of the basic properties of the convolution operation by computing the output of LTI
systems using some MATLAB functions.

Procedure:
1. Convolution
In discrete-time, linearity provides the ability to completely characterize a system in
terms of its response hk[n] to signals of the form [n k ] for all k. The combination of
linearity and time-invariance therefore allows a system to be completely described by its
impulse response h[n], since the output of the system y[n] is related to the input x[n]
through the convolution sum
y[n]

h[n m]x[m]

Similarly, the output y(t) of a continuous-time LTI system is related to the input x(t) and
the impulse response h(t) through the convolution integral
y (t )

h(t ) x( )d

The MATLAB function conv computes the convolution sum above. Assuming that x[n]
and h[n] are finite-length sequences, if x[n] is nonzero only on the interval
n x n n x N x 1 , and h[n] is nonzero only on the interval n h n n h N h 1 , then
y[n] can be nonzero only on the interval ( n x n h ) n (n x n h ) N x N h 2 ,
meaning that conv need only to compute y[n] for Nx + Nh 1 samples on this interval.

If x is an Nx-dimensional vector containing x[n] on the interval n x n n x N x 1 , and


h is an Nh-dimensional vector containing h[n] on the interval n h n n h N h 1 , then
conv(h, x) returns in y the Nx + Nh 1 samples of y[n] on the interval
Page 1 of 7

CCE330(B)L MATLAB Applications in Signals and (Bio)Systems

Mr. Nashaat El Halabi

( n x n h ) n (n x n h ) N x N h 2 . However conv does not return the indices of


the samples of y[n] stored in y, which makes you responsible for keeping track of these
indices.
The following MATLAB script file illustrates convolution:
% Illustration of convolution
a = input('Type in the first sequence = ');
b = input('Type in the second sequence = ');
c = conv(a, b);
M = length(c)-1;
n = 0:1:M;
disp('Output sequence = ');
disp(c);
stem(n, c);
xlabel('Time index n');
ylabel('Amplitude');
(a). Consider the finite-length signal
1, 0 n 5,
0, otherwise.

x[ n]

Plot x[n] and analytically determine y[n] = x[n]*x[n].


(b). Compute the nonzero samples of y[n] = x[n]*x[n] using conv, and store these
samples in the vector y. You should define first the vector x to contain the samples
of x[n] on the interval 0 n 5 . Also construct an index vector ny containing the
index of the samples of y[n] as discussed before. Plot the result using stem(ny,
y) and check if it matches part (a).
(c). Consider the finite-length signal
n, 0 n 5,
0, otherwise.

h[ n]

Analytically determine y[n] = x[n]*h[n]. Next use MATLAB to plot y[n].


(d). In the previous part, h[n] can be viewed as the impulse response of a linear-time
invariant system for which x[n] is the system input and y[n] is the system output.
Because h[n] is zero for n<0, this system is causal. However, conv can also be used
to implement LTI systems which are noncausal. For example, consider the system
with impulse response h[n+5], where h[n] is as defined in part (c). Plot the new
convolution of this new system y2[n] = x[n]*h[n+5] and compare it to the plot in part
(c). What do you conclude?
Note that the indices of y2[n] have changed. Make sure to keep track of all indices.
Page 2 of 7

CCE330(B)L MATLAB Applications in Signals and (Bio)Systems

Mr. Nashaat El Halabi

(e). Consider the finite-length signal


2n 3, 0 n 5,
0, otherwise.

x[n]

Plot x[n] and analytically determine y[n] = x[n]*x[n].


(f). Compute the nonzero samples of y[n] = x[n]*x[n] using conv, and store these
samples in the vector y. You should define first the vector x to contain the samples
of x[n] on the interval 0 n 5 . Also construct an index vector ny containing the
index of the samples of y[n] as discussed before. Plot the result using stem(ny,
y) and check if it matches part (e).
(g). Consider the finite-length signal

1 n 2 , 0 n 4,
0, otherwise.

h[ n]

Analytically determine y[n] = x[n]*h[n]. Next use MATLAB to plot y[n].


2. Filter
The filter command in MATLAB computes the output of a causal, LTI system for a
given input when the system is specified by a linear constant-coefficient difference
equation. Consider the LTI system satisfying the difference equation:
K

a
k 0

y[n k ] bk x[n m],


m 0

where x[n] is the system input and y[n] is the system output. If x is a vector containing the
input on the interval n x n n x N x 1 and the vectors a and b contain the coefficients
ak and bk, then y = filter(b, a, x) returns the output of this causal LTI system
satisfying
K

k 0

m0

a(k 1) y(n k ) b(m 1) x(n m).


Note that a(k+1) = ak and b(m+1) = bm, since MATLAB requires that all vector indices
begin at one and not at zero.
(h). Define the coefficient vectors a and b, to represent the causal LTI systems specified
by
y[n] = 2x[n] + 0.5x[n 1] + 2x[n 3],

Page 3 of 7

CCE330(B)L MATLAB Applications in Signals and (Bio)Systems

Mr. Nashaat El Halabi

For this system, use filter to compute the response y[n] on the interval 1 n 10
to the input signal x[n] = nu[n].
Hint: you should use filter as follows:
>> y = filter(b, a, x);
Note that filter assumes the samples x[0] and x[-1] to be equal to zero in order to
calculate y.
(i). The filter command in MATLAB can also be used to perform discrete-time
convolution.
Consider the signals from parts 1-(a) and 1-(c). Redefine x[n] and h[n] on the
interval 0 n 5 in vectors x and h. In order to use filter to perform the
convolution of x[n] and h[n], you need to define b as h and a as 1, and then use
>> y = filter(h, 1, x);
Keep in mind that filter returns a vector that is the same length as x. So you
need to define an index vector for y, say ny, to have the same length as the length of
x.
>> ny = [0:5];
Plot the result and compare it to the plot you got from part 1-(c).
3. Simulation of the Time Response of LTI Systems with Differential Equations
The function lsim in MATLAB can be used to simulate the output of continuous-time,
causal LTI systems described by linear constant-coefficient differential equations of the
form
N

ak
k 0

d k y (t ) M
d m x (t )

b
m dt m .
dt k
m 0

Note that if vector a is used to represent ak, it must contain N + 1 elements, which may
require the addition of zeros to a. The same applies to vector b that is used to represent bk
that must contain M + 1 elements. With a and b defined, the vector y will simulate the
output when executing the command
>> y = lsim(b, a, x, t);
Consider the following signal on the interval 0 t 10
3 | t 5 |, 2 t 8,
0, otherwise.

x(t )

Page 4 of 7

CCE330(B)L MATLAB Applications in Signals and (Bio)Systems

Mr. Nashaat El Halabi

This can be plot using the plot command and the following code:
>> t = [0 1 2 5 8 9 10];
>> x = [0 0 0 3 0 0 0];
>> plot(t, x);
Note that x and t are not completely defined on the interval 0 t 10 ; however, the
plot command in MATLAB will interpolate the values. lsim will do the same. But be
careful because you need to completely define the input signals in order to get the right
output signals.
Now, consider the causal LTI system described by the first-order difference equation
dy (t )
1
y (t ) x (t ).
dt
2

The step response of this system can be computed by typing the following commands:
>>
>>
>>
>>
>>
>>

t = [0:10];
x = ones(1, length(t));
b = 1;
a = [1 0.5];
s = lsim(b, a, x, t);
plot(t, s);

(j). Use lsim to compute the response of the casual LTI system described by
dy (t )
3 y (t ) 2 x(t ).
dt

to the input x(t) = u(t 3). Use t = [0:0.1:10].


While lsim can simulate the response to any input which can be approximated by linear
interpolation, the functions impulse and step can be used to compute the impulse and
step responses of such systems.
(k). Use step and impulse to compute the step and impulse responses of the casual
LTI system in the previous part. Compare these responses with the exact impulse
that you can calculate and plot.

Page 5 of 7

CCE330(B)L MATLAB Applications in Signals and (Bio)Systems

Mr. Nashaat El Halabi

Report
According to the course syllabus, you must hand in a report for every laboratory session. The
deadline for the submission of the report is stated at the first page of the handouts. No late
reports will be accepted.
The report should include the solution of all problems with the MATLAB m-files, equations,
plots and graphs (labeled with headings, axes labels and scales, legends, grid, etc), and
complete answers to all problems.
The report should start with a title page (containing the name of the course, the tutorial
number, your name and ID number, the date and an abstract of the report), a table of contents
(with page numbers), an Introduction part, Theoretical Analysis, the Solution to all problems
with the above details, a Discussion and Conclusion part, and a Reference page.
A typical solution to a problem would include the statement of the problem, the theoretical
and mathematical solution of the problem, the MATLAB code, the plots or graphs, and the
direct answer to all questions with the adequate proof.
The report should be typed, printed, and stapled (no binding). The typeface you should use is
Times New Roman, size 12 (Headings should be 16 and Bold, Sub-Headings should be 12
and Underline), and Font Color black. The paragraph alignment should be set to Justify. Line
spacing should be set to 1.5 Lines. All margins should be set to 1 inch.
The report will be graded on a five-point scale, from 0 to 4, as shown in the table below, and
according to the same standards as the problem sets.
Grade

Description

You fail to turn in the report for the laboratory session.

You turn in the report, but basically, did nothing worthwhile.

You turn in the report; however, most problems are either incomplete or nonunderstandable.

You complete most or all of the problems in the report; however, you still has some evident
mistakes in the worked solution.

You complete all of the problems in the report with perhaps little insignificant
mathematical or typing mistakes; however, you demonstrate a solid understanding of the
material.

Page 6 of 7

CCE330(B)L MATLAB Applications in Signals and (Bio)Systems

Mr. Nashaat El Halabi

Copyright 2004-2015 American University of Science and Technology Department of Computer and
Communications Engineering. All rights reserved.

Page 7 of 7

You might also like