Вы находитесь на странице: 1из 6

American University of Science

& Technology

Signals & Systems


Introduction:
In the study of linear systems, sinusoids and complex exponentials are i
mportant classes of signals. MATLAB provides several functions to represent thes
e signals especially if a continuous-time or discrete-time index vector is defin
ed.
MATLAB provides the ability to write M-files of two types: command scrip
ts and functions. A command script is a text file of MATLAP commands whose filen
ame ends with .m. IF you type the name of this file (without the .m), MATLAP wil
l execute the commands stored in the file.
An M-file implementing a function is a text file with a title ending in
.m whose first word is function. The rest of the first line of the file specifie
s the names of inputs and outputs arguments of the function.
Objective:
This tutorial will introduce the students to convolution and let them un
derstand some of the basic properties of the convolution operation by computing
the output of the LTI system using some MATLAB functions like conv, filter, and
lsim. The students will learn about the approximation of continuous-time systems
abd the numerical issues involed. Also, this tutorial covers most properties of
discrete-time LTI systems.
convolution:
The combination of linearity and time-invariance therefore allows a sys
tem to be completely described by its impulse response h[n] , since the output o
f the system y[n] is related to the input x[n] through the convolution sum
Y[n]=?_(m=-?)^???h[n-m]x[m]?
Similarly, the output y(t) of a continuous-time LTI system is related to the inp
ut x(t) and the impulse response h(t) through the convolution integral
y(t)= ?_(-?)^??h(t-?) x(?)d?
% Part 3
% 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;
dsip ('Output sequence = ');
disp(c);

stem(n ,c);
xlabel ( 'Time index n');
ylabel ( 'Amplitude ');
Consider the finite-length signal
x[n]={?(1,
0?n?5,@0,
otherwise )?
plot x[n] and analytically determine y[n]=x[n]*x[n]
n=0:5;
x=(0<=n<=5);
stem(n,x);
title('finite length signal');
xlabel('n');
ylabel('x');

Compute the nonzero samples of y[n]=x[n]*x[n] using conv


les in the vector y. You should define first the vector x
of x[n] on the interval 0<=n<=5. Also construct an index
he index of the samples of y[n] as discussed before. Plot
ny,y).
n=0:5;
x=(0<=n<=5);
ny=n(1)+n(1):n(1)+n(1)+length(x)+length(x)-2;
y=conv(x,x);
stem(ny,y);
title('non zero sample');
xlabel('ny');
ylabel('y');

Consider the finite-length signal


h[n]={?(n,
0?n?5,@0,

, and store these samp


to contain the samples
vector ny containing t
the result using stem(

otherwise )?

Analytically determine y[n]=x[n]*h[n]next use the MATLAB to plot y[n]


n=0:5;
x=(0<=n<=5);
h=n(0<=n<=5);
ny=n(1)+h(1):n(1)+h(1)+length(x)+length(h)-2;
y=conv(x,h);
stem(ny,y);
title('finite length signal');
xlabel('ny');
ylabel('y');
Consider the system with impulse response h[n+5], where h[n] is as defined in p
art (1). Plot the new convolution of this new system y2[n]=x[n]*h[n+5] and compa
re it to the plot in part (1).
n=[-5:5];
x=(0<=n<=5);
h=n.*(-5<=n<=0);
ny=n(1)+h(1):n(1)+h(1)+length(x)+length(h)-2;
y=conv(x,h);
stem(ny,y);
xlabel('ny');

ylabel('y');
In conclusion, it looks very different comparing with that in part 1.
Consider the finite-length signal
x[n]={?(2n+1

0?n?5@0

elsewhere )?

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


n=[0:5];
x=[1 3 5 7 9 11];
stem(n,x);
title('finite length signal');
xlabel('n');
ylabel('x');
Compute the nonzero samples of y[n]=x[n]*x[n] using conv
les in the vector y. You should define first the vector x
of x[n] on the interval 0<=n<=5. Also construct an index
he index of the samples of y[n] as discussed before. Plot
ny,y).
n=[0:5];
x=[1 3 5 7 9 11];
ny=n(1)+n(1):n(1)+n(1)+length(x)+length(x)-2;
y=conv(x,x);
stem(ny,y);
title('non zero sample');
xlabel('ny');
ylabel('y');
Consider the finite-length signal
h[n]={?(2n+1
0?n?4@ 0
elsewhere

, and store these samp


to contain the samples
vector ny containing t
the result using stem(

)?

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


n=[0:5];
x=[1 3 5 7 9 11];
n=0:4;
h=[1 3 9 19 33];
ny=n(1)+h(1):n(1)+h(1)+length(x)+length(h)-2;
y=conv(x,h);
stem(ny,y);
title('finite length signal');
xlabel('ny');
ylabel('y');

Filter :
The filter command in MATLAB computes the output of a causal, LTI system for a g
iven input when the system is specified by a linear constant-coefficient differe
nce equation. Consider the LTI system satisfying the difference equation:
?_(k=0)^K?a_k y[n-k]=?_(m=0)^M?b_k x[n-m]
Where x[n] is the system input and y[n] is the system output. If x is a vector c
ontaining the input on the interval n_x<=n<=n_x+ N_x-1 and the vectors a and b c
ontain the coefficients a_k and b_k then y= filter (b, a, x) returns the output
of this causal LTI system satisfying
?_(K=0)^K??a(k+1)y(n-k)=?_(m=0)^M?b(m+1)x(n-m) ?

Note thata(k+1)=ak and b(m+1)=bm.


Define the coefficient vectors a1 and b1, a2 and b2,and a3 and b3 to represent
respectively the causal LTI systems specified by
Y[n]=2x[n] +0.5x[n-1]+2x[n-3],
Y[n]=2y[n-1]+3x[n],
Y[n]-0.5y[n-1]=2x[n-1],
For each of these three systems , use filter to compute the response y[n] on the
interval 1<=n<=4 to the input signal x[n]=n[n].
n=1:4;
x=n.*(1<=n<=4);
a1=1;
b1=[2 0.5 0 2];
a2=[1 -2];
b2=3;
a3=[1 -0.5];
b3=[0 2];
y1= filter(b1 ,a1 ,x);
y2= filter(b2 ,a2 ,x);
y3= filter(b3 ,a3 ,x);
subplot(3,1,1);
stem(n,y1);
title('function of ramp sequence');
xlabel('n');
ylabel('y1');
subplot(3,1,2);
stem(n,y2);
xlabel('n');
ylabel('y2');
subplot(3,1,3);
stem(n,y3);
xlabel('n');
ylabel('y3');
Consider the signals from parts 2-(b) and 2-(d). Redefine x[n]
interval 0<=n<=5 i vectors x and h. In order to use filter to
olution of x[n] and h[n] , you need to define b as h and a as1,
=filter(h,1,x)
>>ny=[0:5]
Plot the result and compare it to the plot you got from
n=0:5;
x=(0<=n<=5);
h=n.*(0<=n<=5);
y=filter(h,1,x);
ny=[0:5];
stem(ny,y);
title('filter');
xlabel('ny');
ylabel('y');

and h[n] on the


perform the conv
and then use >>y
part 2-(d).

The result is different from that shown in part 2(d).


Consider the signal h2[n]=h[n+2], where h[n] is defined as in part 1-(c). Store
h2[n] on the interval -5<=n<=0 in the vector h2.
Plot the result and compare it to part 1-(d).
n=0:5;

x=(0<=n<=5);
n=-5:0;
h2=n.*(-3<=n<=2);
y2=filter(h2,1,x);
stem(n,y2);
title('filter');
xlabel('n');
ylabel('y2');
Simulation of the Time Response of the LTI System with Differential Equations:
the function lsim in MATLAB can be used to simulate the output of continuous ti
me, LTI system described by linear constant-coefficient differential equations o
f the form,
?_(k=0)^N??a_k (d^k y(t))/?dt?^k ?=?_(m=0)^M??b_m (d^m x(t))/?dt?^m ?
We define a and b as vectors .with a and b defined, the vector y will simulate t
he output when executing command
>>y= lsim(b,a,x,t);
t=[0:0.5:10];
x= ones(1, length(t));
b=3;
a=[3 2];
s=lsim(b, a, x,t);
plot(t,s);
title('LTI system');
xlabel('t');
ylabel('s');

(b)- Use lsim can simulate the response to the causal LTI system described by
(dy(t))/dt=-3y(t)+2x(t)
to the input x(t)=(t-2). Use t=[0:0.5:10].
clear all;
t=[0:0.5:10];
x=(t>=2);
a=[1 3];
b=2;
s=lsim(b,a,x,t);
plot(t,s);
smoothing of Time Sequences
Loading and Visualizing the Data:
load beer,
plot(beer)
title('beer')
the graph:

Conclusion:
In, general MATLAB helps us to represent, manipulate, and analyze basic
signals and systems.

MATLAB enables us to develop tools dealing with both discrete-LTI systems.


MATLAB enables us to implement a function by defining its characteristics, also
using this function by giving its word with basic characteristics.
But for these experiments, it is so helpful to understand some of the basics pro
perties of the convolution operation and to make sure that your analytical resul
t is correct.