Department of Electrical Engineering EE361L: Control Systems Lab
Department of Electrical Engineering EE361L: Control Systems Lab
Department of Electrical Engineering EE361L: Control Systems Lab
Batch: BSEE 21
● Build and simulate state space models of LTI in MATLAB and Simulink.
● Convert state-space models to transfer functions and vice versa using MATLAB.
2
Figure 4-1: State space model of a system
We can define the following two linear differential equations relating x 1 and x 2 and an
equation for y from the system’s differential equation given above.
x˙1=x 2
x˙2=−0.05 x 2+ 0.001u
y=x 1
Now we can arrange these differential equations in matrix representation as the following.
[ x˙1 x˙2 ]=[ 0 1 0 0.05 ] [ x 1 x 2 ] + [ 0 0.001 ] u
3
y= [ 1 0 ] [ x1 x 2 ]
These equations can be written in terms of the state vector x to arrive at the standard state
space respresentation of this system.
ẋ=[ 0 1 0−0.05 ] x + [ 0 0.001 ] u
y= [ 1 0 ] x+ [ 0 ] u
>> A = [0 1; 0 -0.05];
>> B = [0; 0.001];
>> C = [1 0];
>> D = 0;
>> sys = ss (A, B, C, D);
>> impulse(sys)
MATLAB shows the impulse response of this system in a new window as shown in Figure 4-
2.
Similarly, we can also plot the step response of this system using step() function in
MATLAB.
Sometimes it is also useful to convert between state-space and transfer function
representations of LTI systems. The following functions are available in MATLAB if you
want to convert from a state-space model to the transfer function model (in either ZPK or
polynomial form) and vice versa.
[num, den] = ss2tf(A, B, C, D): state space to polynomial transfer function
4
[Z, P, K] = ss2zp(A, B, C, D): state space to ZPK transfer function
[A, B, C, D] = tf2ss(num, den): polynomial transfer function to state space
[A, B, C, D] = zp2ss(Z, P, K): ZPK transfer function to state space
4.2.2 Eigenvalues of a System Matrix
A very insightful relation between the state-space and the frequency-domain representations
is that the eigenvalues of the system matrix A of an LTI system are the poles of the system's
transfer function. We can find the eigenvalues of any square matrix using the eig()
function in MATLAB as shown in the following example.
>> A = [3 2 4; 5 1 2; 1 1 2]
>> eig(A)
4.2.3 Characteristic polynomial of a state space model
The characteristic polynomial of a square matrix A is a polynomial whose roots are
eigenvalues of A. You must have seen such polynomials in your Linear Algebra course. The
function charpoly() can be applied on a matrix A to find its characteristic polynomial as
shown in the following example.
>> A = [3 2 4;5 1 2; 1 1 2]
>> charpoly(A)
MATLAB gives the following output to this code.
A =
3 2 4
5 1 2
1 1 2
ans =
1 -6 -5 0
The ans output is the characteristic polynomial of the matrix A. This polynomial is
expressed as its coefficients in decreasing powers of s.
4.3 State Space in Simulink
In Simulink, the state space block is available in the Continuous library. The block and its
configuration window is shown in Figure 4-3.
The matrices A, B, C and D for the state space model can be edited from the configuration
window and it can be stimulated with any combination of time domain inputs to have the
corresponding outputs.
5
Figure 4-3: State space block in Simulink
6
Figure 4-4: A car and the forces acting on it
The following differential equation relates the displacement x of the car and the engine force
u.
m ẍ+b ẋ =u
1. Pre-Lab Convert this differential equation to a state space model, clearly specifying the
state variables and the matrices A, B, C and D. It is given that u is the input and x is the
output. You may consider x and x ' as the state variables. [3
points]
State variables are 2 as because the highest differential power is 2.
X1 = X, Ẋ 1 =X 2-------(1)
X2 = Ẋ , Ẋ 2 = Ẍ
u Ẋ
Ẋ 2 = −b
m m
u ḃ
Ẋ 2 = − X 2 --------------(2)
m m
b 1
[ Ẋ Ẋ ] = [ 0 1 0− m ] [ X 1 X ] + [ 0 m ]u
1 2 2
Y = [1 0] [ X1X ] + 0
2
2. Consider a car with a mass of m=1000 kg and a linear drag constant, b=50 Ns m−1. Build
the state space model in Simulink. Use two step functions to apply a 500 N force on the
car from t=0 s to t=10 s . Configure the solver as fixed step Runge-Kutta with step size
of 10−3 . Run the simulation for 100 s and insert the graph here. [5 points]
7
3. Find the distance travelled by the car in the first 10 seconds if the car starts from rest.
[2 points]
x (10 )=¿_________19m________________
4. As there is no force applied to the car after t=10 s , it should eventually come to a rest.
Find the total distance covered by the car until it stops. [2 points]
Total Distance Covered = _______99.7m_______________
5. Repeat part 4, but this time with an initial velocity of 10 m s−1. Find the distance covered
by the car until it stops. [2 points]
Total Distance Covered = _________307.2m_______________
6. For how long we need to push the car with a constant force of 500 N, if the car starts from
rest, so that it covers a total distance of 2 km before coming to rest again?
Hint: Adjust the step time of the step function so that the car approaches a distance of 2 km
when it comes to rest. [2 points]
T pulse=¿ ________200sec_________________
4.5 Task 2: Permanent Magnet DC Motor
Objective: Build a state space model from a set of differential equations representing a
permanent magnet DC motor and use Simulink to find an appropriate voltage to achieve a
desired speed. Convert and compare the state space model to a transfer function.
Recall the DC motor model from Task 4 of Lab 2 as shown in Figure 4-5. The mechanical
and electrical parameters of the motor are J=0.01, b=0.1 , K e =K t =0.01 , R=1 , L=0.5.
8
Figure 4-5: Permanent magnet DC motor
The angular speed of the motor is related to the current and voltage as represented in the
following differential equations. Here, θ is the angular position, ω is the angular velocity, iis
the current through the armature and v is the voltage across the motor’s terminals.
J θ̈+b θ̇=i K t
di
L + iR=v− K e θ̇
dt
1. Pre-Lab Transform the differential equations into a state space model, considering θ and ω
as the outputs and v as input. You may use i, θ and ω as state variables. Do not substitute
the values of J , b , K t , K e , Rand L in the model yet. [10 points]
u=¿________v_______________
y=¿_______∅ +w ____________
[ x 1 x 2 x 3 ]=¿__[ θ ∅ i ] ___
[
A=¿__ 0 10 0−
b KT
J J
Ke R
0− − __
L L ]
[ ]
B=¿ _______ 0 0
1
L
______
C=¿ ¿_____
D=¿______[ 0 ] _________
2. Build the state space model of the motor in Simulink and stimulate it with a step input of
5 V . Insert the graph here. Describe the shape, maximum and minimum values and 95 %
settling time for the angular velocity of the motor. [3 points]
9
Ans: Her in the graph the angular velocity is 0 rads-1 from 0sec to 1sec. After that the
graph shows linearity and velocity increases until 4.5 rads-1.
3. Note that if the motor is provided with a rectangular pulse, the energy losses due to friction
would cause it to stop (ω=0 ) after some time. It would have spun through an angle
depending on the amplitude and duration of the voltage pulse. Adjust the time and height
of the pulse such that the motor comes to a stop any time before 3 s and covers an angle of
π
rad correct to 2 decimal places. [3 points]
4
V pk =¿ ___________5V_______________
T pulse=¿_________2.63sec____________
4. Create the motor's state-space model in MATLAB. Use the MATLAB function ss2zp()
to convert the state space model to a transfer function in the ZPK form and write down the
value of K and the location of the poles and zeros of the system. [3 points]
K=¿ _________2_________
Poles: ______0, 0.998, -2.003___________
Zeros: __________None_______________
5. Pre-Lab Replace one of the state variables with v R , the voltage across the resistor and build
the state space model again. [4 points]
[ x 1 x 2 x 3 ]=¿_________θ θ̇ iR___________
[
A=¿_____ 0 10 0−
b KT RKe R
J RJ
0
J
− ______
L ]
[ ]
B=¿ ________ 0 0
R
L
____________
10
C=¿_____[11 0]_________
D=¿________[ 0 ] ___________
6. Analysis Use the function ss2zp() to transform this model to a transfer function in
ZPK form. Explain the similarities and differences from your answer to part 4. [3 points]
Ans: Z = -1
P = 0, -9.998, -2.003
K=2
There is some different in zero, other elements are same.
4.6 Task 3: Conversion of State Space Model to transfer Function and Vice
Versa
Objective: Identify the minimum sizes of matrices in the state space representation of given
linear system. Use MATLAB to build a sate space model and find its eigenvalues and
characteristic polynomial.
Recall the inverted pendulum on a cart model from Task 1 in Lab 3 as shown in Figure 4-6.
Here, u is the external force applied on the cart, y is the displacement of the cart and θ is the
angle of the pendulum from the vertically upwards direction. You have to use the linear
model of the pendulum which was linearized around θ=π in that previous Lab.
1. Pre-Lab By observing these differential equations, write the values of the quantities given
in Table 4-1. Consider u as the input θ as the output and θ , θ̇ , y and ẏ as the state
variables. [8
points]
Quantity Value
11
Order of the system 4
Number of 1st order diff. eq. needed to model 4
the system
Minimum number of state variable needed in 4
state space representation
Number of state variable used in state space 4
representation
Number of inputs 1
Number of outputs 1
2. Pre-Lab Convert the differential equations of the given system to a state space model
considering u as the input and θ as the output. Write the values of the matrices in the given
space. [8 points]
[
A= 0 1 .0 0 0
(l+ ml 2)
2
m2 g l2
l(M + m)+ Mm l l(M +m)+ Mml 2
0000
−mlb
l(M + m)+ Mm l2
.0 1
mgl(M + m)
l(M +m)+ Mml 2
0
]
B=¿ ____ 0
[ l+ml 2
0
ml
l(M +m)+ Mml l(M + m)+ Mm l 2
2 ___
]
C=¿___[ 1 0 0 0 00 1 0 ]____
D=¿_______[ 0 0 ] _________
3. Build this state space model in MATLAB. Use the function ss2tf()to convert this
model to a transfer function. Write the transfer function below. Define the following
parameters in MATLAB and use them in your model.
[4 points]
12
Parameter Symbol Value Unit
Mass M 0.5 kg
Coefficient of friction b 0.1 Ns m
−1
Cart
Position y variable m
External force u variable N
Mass m 0.2 kg
Length to CoM l 0.3 m
Pendulum
Moment of inertia I 0.006 kg m
2
Ans: The first two values and last value are same in both of cases which are
(1, 0.1818, -4.45). The third value is slightly different from each other.
13
8. Analysis Find the poles of the system from the transfer function. Find the eigenvalues of
the state matrix using eig() function. Describe any similarities and differences in the
coefficients of the numerator and denominator polynomials in these transfer functions.
[2 points]
Ans: All the values are different. There are no similarities in the values.
14
Assessment Rubric
Method:
Lab report evaluation and instructor observation during lab sessions.
Performanc CL Able to complete the Able to complete the Tasks completion
Marks
e O tasks over 80% (4-5) tasks 50 – 80% (2-3) below 50% (0-1)
Distracts or
Actively engages and Cooperates with
discourages other
cooperates with other other group
1. Teamwork 1 group members
group members in an members in a
from conducting
effective manner. reasonable manner.
the experiment.
2. Laboratory Respectfully and Observes safety
Disregards safety
safety and carefully observes rules and
disciplinary
1 rules and
safety rules and procedures with
rules procedures.
procedures minor deviation.
Needs guidance to
Selects relevant
select relevant Incapable of
equipment to the
equipment to the selecting relevant
3. Realization experiment, develops
of experiment
2 experiment and to equipment to
setup diagrams of
develop equipment conduct the
equipment
connection or experiment.
connections or wiring.
wiring diagrams.
Uses the equipment Unable to use
Uses each equipment
and components appropriate
and components as
4. Conducting with minor error. equipment, and
experiment
2 intended, conducting
Needs help in experiment is
the experiment
conducting substantially
perfectly.
experiment. wrong.
Plans data Does not know
Plans data collection
collection to how to plan data
to achieve
achieve collection to
experimental
5. Data experimental achieve
2 objectives, and
collection objectives, and experimental goals;
conducts an orderly
collects complete data collected is
and a complete data
data with minor incomplete and
collection.
error. contain errors.
Conducts
Accurately conducts computations and
Unable to conduct
simple computations analysis on
simple analysis on
and statistical analysis collected data with
collected data; no
6. Data using collected data; minor error;
2 attempt to correlate
analysis correlates reasonably
experimental
experimental results to correlates
results with known
known theoretical experimental
theoretical values.
values. results to known
theoretical values.