Department of Electrical Engineering EE361L: Control Systems Lab

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

Department of Electrical Engineering

EE361L: Control Systems Lab

Course Instructor: Abdullah Mughees Date:

Lab Engineer: Muhammad Kashif Semester: Spring 2024

Batch: BSEE 21

Modelling Linear Systems in State Space

Name Roll No Lab Marks

Shehryar Asad Bsee21015

Graded on: _______________________________

Instructor’s Signature: _______________________________


Learning Outcomes
● Convert a system of linear differential equations to a state-space model.

● Build and simulate state space models of LTI in MATLAB and Simulink.

● Convert state-space models to transfer functions and vice versa using MATLAB.

4.1 Representation of Linear Systems in State Space


Two approaches are available for the analysis and design of feedback control systems. The
first is the classical frequency-domain technique. This approach is based on converting a
system's differential equations to a transfer function, thus generating a mathematical model of
the system that algebraically relates a representation of the output to a representation of the
input. A major advantage of frequency-domain techniques is that they quickly provide
stability and transient response information. However, the primary disadvantage of this
approach is its limited applicability: It can be applied only to LTI systems or the systems that
can be approximated as such.
The state-space approach (a modern time-domain approach) is a unified method for
modeling, analyzing, and designing a wide range of systems. For example, the state-space
approach can be used to represent linear systems, nonlinear systems, systems with nonzero
initial conditions, time-varying systems, (for example, missiles with varying fuel levels or lift
in an aircraft flying through a wide range of altitudes), multi-input multi-output systems, and
digital systems etc. One of its distinctive features is that there can be multiple state-space
representations of a system between a particular input-output pair. However, the transfer
function of a system between a certain input-output pair is always unique. [11]
The state space representation of a system replaces an n th order differential equation of a
system with a single first order matrix differential equation. The state space representation of
a system is given by two equations
ẋ= Ax+ Bu
y=Cx + Du
The first equation is called the state equation. The variable x is the state vector containing
state variables, A is the system matrix, B is the input matrix and u is the input vector. The
second equation is called the output equation, where y is the output vector, C is the output
matrix and D is the feed-forward matrix. The dimensions of A, B, C and D depend on the
number of state variables, the number of inputs and the number of outputs. For example, if a
system has three state variables in vector x but only a single input u, the matrix B will have
dimension 3 ×1.
We can represent any linear system with an input u ( t ) and output y ( t ) as a state space model
as shown in Figure 4-1.

2
Figure 4-1: State space model of a system

4.1.1 Steps to write State Space of LTI System


In general, a linear system can be modeled in space-space through the following steps.
1. Write nth order differential equation(s) that describes the dynamics of the system.
2. Convert nth differential equation(s) to n first order differential equation, if n=1 then
this step will be skipped.
3. Stack all first order differential equation to find first order matrix differential
equation.
4.2 State Space in MATLAB
In MATLAB the state space model of a system can be defined using the function ss(A, B,
C, D) where A, B, C and D are the system matrix, the input matrix, the output matrix and
the feedforward matrix respectively.
4.2.1 Building a state space model in MATLAB
The following code snippet shows how a system is defined as a state space model and
stimulated with a unit impulse function.
Consider the differential equation of a rotary system with air drag, with angle θ and a driving
torque τ ,
θ̈=−0.05 θ̇+0.001 τ
We develop the state space representation of this system by using the steps mentioned earlier.
Here, x is the state variable vector, uis the input and y is the output for this system. The state
vector consists of the elements x 1 and x 2 defined as the following.
x=[ x 1 x 2 ]

u=τ , x 1=θ , x 2=θ̇

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.

Figure 4-2: Impulse response of a state space model

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

4.4 Task 1: Cruise Model of a Car


Objective: Simulate the state-space model in Simulink and investigate the effect of changing
step input parameters.
Recall the following model of the car from Lab 2 Task 2.

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.

Figure 4-6: Inverted pendulum on a cart

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

Dimensions of the state matrix, A 4x4

Dimensions of the input matrix, B 4x1

Dimensions of the output matrix, C 2x4

Dimensions of the feed forward matrix, D 2x1

Table 4-1: State space model of an inverted pendulum on a cart

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]

x=[ x 1 x 2 x3 x 4 ]=¿ ________[ y ẏ θ ∅˙ ] ______

[
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

Angle from downwards θ variable rad

>> [num, den] = ss2tf (A, B, C, D)


num =0 0 1.8182 -0.0000 44.5460
1 0 4.5455 -0.0000 -0.0000
den = 1.0000 0.1818 -31.1818 -4.4541
4. Convert the transfer function to a state space model using the tf2ss() function and
write down the state space model below. [4 points]
A =[ −0.182 31.182 4.454 0 0 0 0 0 0 0 1 0 0 01 0 ] B = [ 1 0 0 0]
C = [ 0 1.818 0−44.56 0 4.546 0 0 ] D = [ 0 0]
5. Compare your original state space model (form part 2) with the one found after two
conversions (in part 4). Compare the values and positions of the elements in the matrices
A, B, C and D. [4
points]
Ans: If we compare. Both values of A, B and C may change from each other where as
values of D remains same.
7. Write down the characteristic polynomial of the state matrix using the charpoly()
function. Compare the characteristic polynomial with the denominator polynomial of the
transfer function model found previously. Compare and explain the similarities and
differences between the coefficients of these polynomials. [3 points]
A = [-0.1181831.19 4.45 0; 1 0 0 0;
0 1 0 0; 0 0 1 0];
Ans: 1.0000 0.1818 -31.1900 -4.4500

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.

Uses computer to Does not know


Uses computer to
7. Computer collect and analyze how to use
2 collect and analyze
use data with minor computer to collect
data effectively.
error. and analyze data.

Total (out of 35)


16

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy