You are on page 1of 12

International Islamic University Islamabad

Faculty of Engineering & Technology


Department of Electrical Engineering

CONTROL SYSTEMS LAB

Experiment No. 2: Linear Time Invariant (LTI) and their representation using

MATLAB

Name of Student: ……………………………………

Registration No.: ……………………………………..

Date of Experiment: …………………………………

Submitted To: ………………………………………...

Experiment No. 2: Linear Time Invariant systems and their representation using MATLAB Page 1
Objectives:
 To learn MATLAB commands which are used to represent LTI systems in terms of
transfer function, pole-zero-gain and state-space representations.
 To analyze LTI systems using pole/zero plots and their time responses due to impulse,
step and arbitrary inputs using MATLAB.
 To represent LTI systems using MATLAB/Simulink.
Equipment Required:
 Personal Computer (PC)
 MATLAB software (updated)
Theory:
Mass-Spring system Model:
Let we have mass-spring model as shown in Figure 2.1(a) whose equivalent block
diagram is depicted in Figure 2.1(b).

Figure 2.1 (a): Mass, spring and damper system Figure 2.1 (b): block diagram
Begin the solution by drawing the free-body diagram shown in Figure 2.2. We assume
that the mass is traveling toward the right. Thus, only the applied force points towards right;
all other forces impede the motion and act to oppose it. Hence, the spring, viscous damper,
and the force due to acceleration point towards left. The spring force is assumed to be either
linear or can be approximated by a linear function ( F s ( x ) = K x ) .

Figure 2.2: Free-body diagram of mass, spring and damper system


We can write the differential equation of motion using Newton’s law; sum all the forces
acting on mass and set equal to zero.

Experiment No. 2: Linear Time Invariant systems and their representation using MATLAB Page 2
𝑑2 𝑥(𝑡) 𝑑𝑥(𝑡)
𝑀 + B + 𝐾𝑥 (𝑡) = 𝐹(𝑡) (2.1)
𝑑𝑡 𝑑𝑡
w h e r e , M i s t h e m a s s , B is the friction coefficient, x(t) is the displacement, F ( t ) is
the applied force and K is known as spring constant.
Transfer Function Representation:
Applying the Laplace transformation while assuming the initial conditions are zeros, we
get the system in frequency domain.
(𝑀𝑠 2 + 𝐵𝑠 + 𝐾) ∗ 𝑋(𝑠) = 𝐹(𝑠) (2.2)
The transfer function (G(s)) of the system can be written as:
𝑂𝑢𝑡𝑝𝑢𝑡 𝑜𝑓 𝑠𝑦𝑠𝑡𝑒𝑚 𝐹(𝑠) 1
𝐺(𝑠) = = = (2.3)
𝐼𝑛𝑝𝑢𝑡 𝑜𝑑 𝑠𝑦𝑠𝑡𝑒𝑚 𝑋(𝑠) 𝑀𝑠 2 +𝐵𝑠+𝐾

Representation of Linear Time Invariant (LTI) systems in MATLAB:


Control System Toolbox in MATLAB offers extensive tools to manipulate and analyze
linear time-invariant (LTI) models. It supports both continuous-time and discrete-time
systems. Systems can be single-input/single-output (SISO) or multiple-input/multiple-output
(MIMO). Control System Toolbox provides functions for creating basic representations of
linear time-invariant (LTI) models such as:
a. Transfer Function (tf) models

b. Zero-Pole-Gain (zpk) models

c. State-Space (ss) models

i. Creating Transfer Function models:


Transfer functions (TF) are frequency-domain representations of LTI systems. A SISO
transfer function is a ratio of polynomials:
𝑁 (𝑠 ) (𝑎1 𝑠 𝑛 + 𝑎2 𝑠 𝑛−1 + … … . + 𝑎𝑛+1 )
𝐻 (𝑠 ) = =
𝐷(𝑠 ) (𝑏1 𝑠 𝑚 + 𝑎2 𝑠 𝑚−1 + … … . + 𝑎𝑚+1 )
Transfer functions are specified by their numerator and denominator N(s) and D(s)
polynomials. In MATLAB, a polynomial is represented by the vector containing its
coefficients, for example, the polynomial 𝑠 2 + 2𝑠 + 10 is specified as [1 2 10].
Example:
Let we have mass-spring system (G(s)) as represented in Eq. (2.3):
1
𝐺(𝑠) =
𝑀𝑠 2 +𝐵𝑠+𝐾
Given that: M = 1-kg, B = 5-Nsec/m, K = 3-N/m.

Experiment No. 2: Linear Time Invariant systems and their representation using MATLAB Page 3
After substitution, we can write G(s) as:
1
𝐺 (𝑠) =
𝑠2 + 5𝑠 + 3
In MATLAB, to create a transfer function (G(s)), specify the “numerator” and “denominator”
polynomials and then use “tf” command:
>> num = [1];
>> den = [1 5 3];
>> G = tf(num,den)
G =
1
----------------
s^2 + 5 s + 3
Alternatively, you can specify this model as a rational expression of the Laplace variable ‘s’:
>> s = tf('s');
>> G = 1/(s^2 + 5*s + 3)
G =
1
----------------
s^2 + 5 s + 3
This is identical to the previous transfer function.
ii. Creating Zero-Pole-Gain models:
Zero-pole-gain (ZPK) models are the factored form of transfer functions:
(𝑠 − 𝑧1 )(𝑠 − 𝑧2 ) … . . (𝑠 − 𝑧𝑚 )
𝐻 (𝑠 ) = 𝑘
(𝑠 − 𝑝1 )(𝑠 − 𝑝2 ) … . . (𝑠 − 𝑝𝑚 )
Such models expose the roots “z” of the numerator (as zeros) and the roots “p” of the
denominator (as poles). The scalar coefficient k is called the gain. To create zero-pole-gain
(zpk) model:
−2𝑠
𝐻 (𝑠) =
(𝑠−2)(𝑠 2 −2𝑠+2)

You must specify the vectors of poles and zeros and the gain k:
>> z = 0; % Zeros
>> p = [2 1+i 1-i]; % Poles
>> k = -2; % Gain
>> H = zpk(z,p,k)
H =
-2s
--------------------
(s-2) (s^2 - 2s + 2)

Experiment No. 2: Linear Time Invariant systems and their representation using MATLAB Page 4
iii. Creating State-Space models:
State-space (SS) models are time-domain representations of LTI systems:
𝑥̇ = 𝐴𝑥 + 𝐵𝑢
𝑦 = 𝐶𝑥 + 𝐷𝑢
where x(t) is the state vector, u(t) is input vector, and y(t) is the output trajectory.
State-space models are derived from the differential equations describing the system
dynamics. For example, consider the second-order ordinary differential equation for a simple
electric motor:
𝑑 2 𝜃 2𝑑𝜃
+ + 5𝜃 = 3𝐼
𝑑𝑡 2 𝑑𝑡
where I is the driving current (input) and 𝜃 is the angular displacement of the rotor (output).
d𝜃
The angular displacement (𝜃) and angular velocity (𝜃̇ = dt ) are the state variables.
𝑑𝑥
𝑥̇ =
𝑑𝑡
= 𝐴𝑥 + 𝐵𝐼, 𝜃 = 𝐶𝑥 + 𝐷𝐼 ,
The equivalent transfer function of the system can be written as:
𝜃(𝑠) 3
= 2
I(s) 𝑠 + 2𝑠 + 5

In MATLAB, “[A B C D] = tf2ss(num,den)” command is used to create a state-


state model using a transfer function. The following state-space model appears in command
window.
>> num=[3]
>> den=[1 2 5]
>> [A B C D] = tf2ss(num,den)
A =
-2 -5
1 0
B =
1
0
C =
0 3
D =
0
To obtain a transfer function from state-space equations, use “[num,den] =
ss2tf(A,B,C,D)” command:
>> A = [-2 -5;1 0];
>> B = [1;0];
>> C = [0 3];
>> D = 0;
>> [num den] = ss2tf(A,B,C,D)
>> sys = tf(num,den)

Experiment No. 2: Linear Time Invariant systems and their representation using MATLAB Page 5
Plotting Poles and Zeros of a system:
“pzmap” command plots the poles and zero plot of a dynamic system.
>> pzmap(sys)
>> pzmap(sys1,sys2,...,sysN)
>> [p,z] = pzmap(sys)
Description of pzmap:
pzmap (sys) plots the pole- zero map of the continuous or discrete-time LTI model “sys”.
For SISO systems, pzmap plots the transfer function poles and zeros. The poles are plotted as
x’s and the zeros are plotted as o’s. pzmap(sys1, sys2,..., sysN) plots the pole-zero map of
several LTI models on a single figure. The LTI models can have different numbers of inputs
and outputs. When invoked with left-hand arguments, [p, z] = pzmap(sys) returns the system
poles and zeros in the column vectors p and z. No plot is drawn on the screen in this case.
You can use the functions sgrid or zgrid to plot lines of constant damping ratio and natural
frequency in the s or z plane.
Example:
Plot the poles and zeros of the continuous-time system (H(s))?
2𝑠 2 + 5𝑠 + 1
𝐻 (𝑠) =
𝑠 2 + 2𝑠 + 3
Solution:
>> H = tf ([2 5 1],[1 2 3]);
>> pzmap(H)
Pole-Zero Map
1.5
System: sys
Pole : -1 + 1.41i
1 Damping: 0.577
Overshoot (%): 10.8
Frequency (rad/s): 1.73
System: sys
Imaginary Axis (seconds -1)

Zero : -2.28
0.5
Damping: 1
Overshoot (%): 0
Frequency (rad/s): 2.28
0
System: sys
Zero : -0.219
Damping: 1
-0.5 Overshoot (%): 0
System: sys Frequency (rad/s): 0.219
Pole : -1 - 1.41i
-1 Damping: 0.577
Overshoot (%): 10.8
Frequency (rad/s): 1.73

-1.5
-2.5 -2 -1.5 -1 -0.5 0
-1
Real Axis (seconds )

Figure 2.3(a)

Experiment No. 2: Linear Time Invariant systems and their representation using MATLAB Page 6
Example:
Plot the poles and zeros of the continuous-time systems (𝐻1 (𝑠) 𝑎𝑛𝑑 𝐻2 (𝑠))?
4𝑠 2 + 3𝑠 + 7
𝐻1 (𝑠) =
2𝑠 2 + 5𝑠 + 9

2𝑠 2 + 6𝑠 + 4
𝐻2 (𝑠) =
2𝑠 2 + 8𝑠 + 3

Solution:
>> H1 = tf ([4 3 7],[2 5 9])
>> H2 = tf ([2 6 4],[2 8 3])
>> pzmap(H1,H2)

Figure 2.3(b)
Example:
Obtain the poles and zeros of the continuous-time system (H(s))?
4𝑠 2 + 9𝑠 + 2
𝐻 (𝑠) =
𝑠 2 + 7𝑠 + 3

Solution:
>> H = tf ([4 9 2],[1 7 3]);
>> [p,z] = pzmap(H)
p =
-6.5414
-0.4586
z =
-2.0000
-0.2500

Experiment No. 2: Linear Time Invariant systems and their representation using MATLAB Page 7
Response of LTI systems to different inputs:
Impulse and Step Response:
You can simulate the LTI systems with different inputs like impulse, step and other

standard inputs. “impulse” command computes the unit impulse response of the system

and “step” returns the unit step response of the system. When invoked without left-hand

arguments, these commands plot the response on the screen.


Example:
Obtain the impulse response of the continuous-time system (G(s))?
2𝑠 2 + 5𝑠 + 1
𝐺 (𝑠) =
𝑠 2 + 2𝑠 + 3

Solution:
>> num = [2 5 1];
>> den = [1 2 3];
>> G = tf(num,den)
>> impulse(G)

Figure 2.4
To obtain a step response type,
>> step(G)

Experiment No. 2: Linear Time Invariant systems and their representation using MATLAB Page 8
Figure 2.5
Time-interval specification:
You can also specify the time interval to simulate the system too.
>> t = 0:0.01:10;
>> G = tf([2 5 1],[1 2 3]);
>> impulse(G,t)
>> step(G,t)

Figure 2.6 Figure 2.7


Response to Arbitrary Inputs:
To simulate the (time) response of continuous or discrete linear systems to arbitrary
inputs, use “lsim” command. When invoked without left-hand arguments, “lsim” plots the
response on the screen. “lsim(sys,u,t)” produces a plot of the time response of the LTI
model “sys” to the input time history ‘t’,’u’. The vector ‘t’ specifies the time samples for the
simulation and consists of regularly spaced time samples. The matrix u must have as many

Experiment No. 2: Linear Time Invariant systems and their representation using MATLAB Page 9
rows as time samples (length(t)) and as many columns as system inputs. Each row 𝑢(𝑖),
specifies the input value at time sample 𝑡(𝑖).
Example:
Plot the output response of the system (G(s)) to a square wave having time period of 5
seconds.
2𝑠 2 + 5𝑠 + 1
𝐺 (𝑠) =
𝑠 2 + 2𝑠 + 3
Solution:
First, obtain the transfer function of the system (G(s)).
>> G = tf([2 5 1],[1 2 3])
G =
2 s^2 + 5 s + 1
--------------------
s^2 + 2 s + 3
Then, generate a square wave having time period of 5 seconds, time duration 15 seconds, and
sampling at every 0.01 second using “gensig” command.
>> [u,t] = gensig('square',5,15,0.01);

“[u,t]=gensig(type,tp,Tf,Ts” specifies the “type” of signal (‘sine’, square’, ‘pulse’ )

time period “Tp”, time duration “Tf” of the signal and the spacing “Ts” between the time
samples t. You can feed the outputs ‘u’ and ‘t’ directly to lsim and simulate the response of a
single-input linear system to the specified signal.
>> lsim(G,u,t)

Figure 2.8

Experiment No. 2: Linear Time Invariant systems and their representation using MATLAB Page 10
Example:
Plot the output response of the system (H(s)) to a sine wave having time period of 3 seconds.
𝑠+5
𝐻 (𝑠) =
2𝑠 2 + 3𝑠 + 6
Solution:
>> H = tf([1 5],[2 3 6])
>> [u,t] = gensig('sin',3,9,0.01);
>> lsim(H,u,t)
>> legend('Output Response to Sine Input')

Figure 2.9
Representation of Linear Time Invariant (LTI) systems using MATLAB/Simulink:
Let us construct and simulate the following LTI systems in MATLAB/Simulink and
observe their outputs using a scope.

Figure 2.10

Experiment No. 2: Linear Time Invariant systems and their representation using MATLAB Page 11
Exercise Problems
Question No. 1: Consider the transfer function P(s),
𝐶(𝑠) 1
𝑃(𝑠) = = 2
𝑅 (𝑠) 𝑠 + 0.2𝑠 + 1
a. Using MATLAB, find and plot the poles/zeros of the above system?
b. Find the unit impulse response of the following system using MATLAB?
c. Find the unit step response of the following system using MATLAB?

Question No. 2:

a. Find the transfer function of RLC network given in Figure 2.10 using theoretical
knowledge. Then, find and plots its zeros/poles using MATLAB?
b. Using MATLAB, obtain the unit step response of the system?

Assume that Vi = 1V, R = 5Ω, L = 3H and C = 0.1F.

Figure 2.10

Question No. 3: Consider the differential equation system given by:

𝒚̈ + 𝟑𝒚̇ + 𝟐𝒚 = 𝟎

where 𝑦(0) = 0.1, 𝑦̇ (0) = 0.05


a. Determine the solution “y(t)” analytically subjected to the given initial conditions and
then plot the analytical solution using MATLAB.
Hint: Use Laplace transform approach to obtain the solution “y(t)”.

b. Using MATLAB, obtain and plot the solution “y(t)”, subjected to the given initial
conditions.
Hint: Use state space approach, and then utilize the command “initial(sys,x0,t)”.

Experiment No. 2: Linear Time Invariant systems and their representation using MATLAB Page 12

You might also like