Linear Time Invariant (LTI) systems in Matlab
This page will discuss only single input-single output (SISO) systems, though Matlab can handle systems with multiple inputs and multiple outputs (MIMO). If you are interested in seeing how to apply the commands listed below to MIMO systems, use Matlabs "help" command.
Though Matlab has 3 ways to define systems (Transfer functions, State Variables, and Pole-Zero), this document on deals with Transfer Function and State Variable Representations.
Defining a system with a Transfer Function
tf
» Sys1=tf(num,den)
Create a new system by defining the transfer function numerator and
denominator polynomial.
Consider the transfer function:
To define a system Sys1 in Matlab you could type:
» Sys1=tf([2 2],[1 3 2])
Transfer function:
2 s + 2
-------------
s^2 + 3 s + 2
This defines an "system object" which has certain properties. To list the properties
» get(Sys1)
num = {[0 2 2]}
den = {[1 3 2]}
Variable = 's'
Ts = 0
Td = 0
InputName = {''}
OutputName = {''}
Notes = {}
UserData = []
Note that the numerator and denominator polynomials are in braces "{}". This is to handle the MIMO case. If you want to get the system numerator, type:
» n=Sys1.num{1}
n =
0 2 2
and likewise for the denominator. Another way to do this is with the get function (which will return a property):
» n1=Sys1.num{1};
» n=n1{1};
You can also use the command "tfdata" to get both numerator and denominator:
» [n,d]=tfdata(Sys1,'v');
The argument 'v' is important to get the actual numerator and denominator for a SISO system. The only other object properties that you might want to use are the InputName and OutputName. If you assign these properties, the input name and output name will be printed on all graphs, and whenever you display the transfer function. To name the input and output and then display the transfer function:
» Sys1.InputName='MyInput';
» Sys1.OutputName='MyOutput';
» Sys1
Transfer function from input "MyInput" to output "MyOutput":
2 s + 2
-------------
s^2 + 3 s + 2
Defining a system
with State Variables
ss
» Sys2=ss(a,b,c,d)
Create a new system by defining the state space representation.
Likewise a system can be defined using the state-variable representation:
» a=[0 1; -2 -3]; b=[0 1]'; c=[1 0]; d=0;
» Sys2=ss(a,b,c,d);
To view the object properties:
» get(Sys2)
a = [2x2 double]
b = [2x1 double]
c = [1 0]
d = 0
e = []
StateName = {2x1 cell}
Ts = 0
Td = 0
InputName = {''}
OutputName = {''}
Notes = {}
UserData = []
The state variables and input and output can be named:
» Sys2.InputName='S2 In';
» Sys2.OutputName='S2 Out';
» Sys2.StateName={'S2 State1' 'S2 State2'};
These names appear when viewing the object:
» Sys2 a = S2 State1 S2 State2 S2 State1 0 1 S2 State2 -2 -3 b = S2 In S2 State1 0 S2 State2 1c = S2 State1 S2 State2 S2 Out 1 0 d = S2 In S2 Out 0 Continuous-time system.
As with the systems defined in terms of the transfer function it is possible to get the state space properties. To get the amatrix
» amatrix=Sys2.a
amatrix =
0 1
-2 -3
or to get all matrices at one time
» [amatrix,bmatrix,cmatrix,dmatrix]=ssdata(Sys2);
Converting Between LTI Representations
Recall, from above, that Sys1 was defined in terms of the transfer function and Sys2 was defined in terms of its state-space representation:
Transfer function to state space.
» Sys3=ss(Sys1);
Creates a new state-space system, Sys3, that is equivalent to the transfer
function system Sys1.
See also "tf2ss" and "ssdata".
State Space to transfer function.
» Sys4=tf(Sys2);
Creates a new transfer function system, Sys4, that is equivalent to the state
space system Sys2.
See also "ss2tf" and "tfdata".
State
Space to State Space.
» Sys5=ss2ss(Sys2,T);
Matlab performs a similarity transform to go from one state space representation to
another, using the matrix "T". Note that the transform is different from
the one described in most textbooks, such that T-1=P.
Zero-pole
representation
If you want to use the zero-pole representation use the
"zpk" function (and "zpk", "zp2tf", "tf2zp",
"zp2tf" and "tf2zp").
System Characterization and
Responses
In the following, "sys" is an LTI SISO
system.
Impulse
Response
» impulse(sys);
Plots the impulse response of "sys". If you have given names to the
inputs and outputs, these are displayed on the graph.
»
impulse(sys,t);
Calculates the impulse response at the times specified by the vector "t".
»
[y,t,x]=impulse(sys);
Does not plot the impulse response, but returns with the values of the output, the
time vector, and the state variables
.Step
Response
» step(sys);
Plots the step response of "sys". If you have given names to the
inputs and outputs, these are displayed on the graph.
»
step(sys,t);
Calculates the step response at the times specified by the vector "t".
»
[y,t,x]=step(sys);
Does not plot the step response, but returns with the values of the output, the
time vector, and the state variables.
Response
to Arbitrary Inputs
» lsim(sys,u,t);
Plots the response of "sys" to the input u defined at times t.
»
[y,t,x]=lsim(sys,u,t);
Does not plot the response, but returns with the values of the output, the time
vector, and the state variables. If the system is in state variable form, it is
possible to include a set of initial conditions.»
y=conv(h,u);
Convolves the impulse response h, with the input u. Note, this does a
summation, not the convolution integral and does not account for the timestep used in the
data. Note also that length(y)=length(h)+length(u)-1.
![]()
Response
to Initial Conditions
» initial(sys,x0);
Plots the response of "sys" to the initial conditions defined by
x0. The system must be in state variable form.
»
[y,t,x]=initial(sys,x0);
Does not plot the response, but returns with the values of the output, the time
vector, and the state variables.
Pole Zero
Plot
» pzmap(sys);
Plots the pole-zero map of "sys".
»
[p,z]=pzmap(sys);
Does not plot the map, but returns the poles and zeros of the system.
Bode Plot
» bode(sys);
Plots the bode response of "sys". If you have given names to the
inputs and outputs, these are displayed on the graphs.
»
bode(sys,w);
Calculates the step response at the frequencies specified by the vector
"w". To specify logarithmically spaced w (link).
»
[m,p,w]=bode(sys);
Does not plot, but returns with the magnitude and phase of the output,and the
frequency vector.
LTIViewer
» LTIView;
Brings up the LTI viewer which is useful for comparing several different systems.
Will generate any of the plots discussed above.
email me with any comments on how to improve the information on this page (either presentation or content)