ENG3018 Practical 0
ENG3018 Practical 0
Practical (Introduction)
Christopher Edwards, Prathyush P Menon
This is intended to introduce some of the MATLAB commands which will be useful in the later
sessions. The subsequent laboratory sessions will be assessed, but this one will not.
1 Preface
Before the first laboratory session, if you plan on using your own computer, install MATLAB onto
your computer or register with Mathworks to use the online version. MATLAB can be downloaded
through the University’s Software Centre. See the following video or you can follow the link. The
link will eventually provide you with a word document which includes detailed information on how
to install MATLAB. Follow the instructions carefully - it will require you to register with Mathworks
and associate your account with the University’s site licence. You will then be able to download
MATLAB, access tutorials and online courses and also use an on-line version of MATLAB.
If you install MATLAB, unless you have a large hard drive, it is recommended that you install only
the required toolboxes listed below:
• optimisation toolbox,
2 Polynomials
Polynomials play a key role in the study of SISO control systems where the plant system is modelled
as a ratio of polynomials (transfer functions).
Consider the polynomial
p(s) := s4 + 7s3 + 19s2 + 23s + 10
and suppose we have to find the roots of this polynomial. Polynomials are represented in MATLAB
by row vectors whose elements are the polynomial coefficients in order of descending degree. In
MATLAB the polynomial above would be represented as
>> pc = [1 7 19 23 10];
The command roots finds the roots of the associated polynomial.
>> pc = [1 7 19 23 10];
1
>> r = roots(pc)
r =
-2.0000 + 1.0000i
-2.0000 - 1.0000i
-2.0000
-1.0000
In the above, pc is a row vector containing the coefficients of p(s) in descending degree, and
roots(pc) is a column vector containing the roots of the polynomial, saved in the vector r.
Conversely, if r, the column vector containing the roots of the polynomial is known or given, then
poly(r) is a row vector with the polynomial coefficients in descending degree whose roots are
elements of r. Specifically
>> ps = poly(r)
ps =
1.0000 7.0000 19.0000 23.0000 10.0000
Consider the polynomial
q(s) := s4 + 7s3 + 19s2 + 10
p(s) = (s + 1)
q(s) = (s + 0.2)
Suppose the polynomials p(s) and q(s) are to be multiplied to create the polynomial
The function polyval can be used to evaluate the value of a polynomial at a given value of the
variable. When s = 1, The polynomial n(s) has the value n(1) = 2.4.
2
>> val = polyval(nc,1)
val =
2.4000
3 Transfer functions
Transfer function can be treated as single objects in MATLAB, and can be manipulated as single
entities. The transfer functions can be created using the MATLAB command tf.
Example: Consider the block diagram
Vehicle
Gain
ψr +- fe - +- f u - 0.1(s+0.5) - 1
ψ
-
K (s+1)(s+0.2) s
− 6 − 6
Sensor
s
In what follows assume the gain K = 10. The ultimate objective is to obtain the transfer function
between Ψr and Ψ using MATLAB commands.
In Fig. 1, consider first the ‘vehicle’ block. This can be created using MATLAB the commands:
>> num = [0.1 0.1*0.5];
>> den1 = [1 1];
>> den2 = [1 0.2];
>> den = conv(den1, den2);
>> G1 = tf(num, den)
G1 =
0.1s + 0.05
-----------------------
s2 + 1.2s + 0.2
Continuous-time transfer function.
0.1(s+0.5)
The object G1 represents the transfer function (s+1)(s+0.2) .
1
The transfer function of the integrator s can be represented as
>> G2 = tf([1], [1 0]);
G2 =
1
3
-----
s
Continuous-time transfer function.
From Fig. 1 it is clear that the transfer function G1 should be placed in series/cascade with the
0.1(s+0.5)
transfer function G2. To cascade the two transfer functions G1 = (s+1)(s+0.2) and G2 = 1s , the
series function is used as follows:
>> G3 = series(G1, G2)
G3 =
0.1s + 0.05
--------------------------
s3 + 1.2s2 + 0.2s
Continuous-time transfer function.
The sensor (differentiator) block s can be represented as
>> G4 = tf([1 0], [1])
G4 =
s
Continuous-time transfer function.
From Fig. 1, the cascaded transfer function G3 and G4 form a feedback loop, with G4 in the negative
feedback path. To obtain a transfer function representation for this, the command feedback1 can
be used.
u --->O---->[ M1 ]----+---> y
| | y = M * u
+-----[ M2 ]<---+
4
signal is the input to the gain block K. The signal Ψ is the output of transfer function Gcl. To
obtain the closed loop transfer function representation between Ψr and Ψ the following MATLAB
commands can be used:
>> K = 10;
>> GS = K*Gcl1
GS =
s + 0.5
----------------------
s3 + 1.3s2 + 0.25s
Continuous-time transfer function.
>> GCL = feedback(GS,[1])
GCL =
s + 0.5
----------------------------
s3 + 1.3s2 + 1.25s + 0.5
Continuous-time transfer function. This can be checked against the expression obtained
in the class notes on Block Diagrams.
5 Time responses
This section looks at three type of input signals for Ψr in the system built in §2.
5
Pole−Zero Map
1
1
0.52 0.38 0.28 0.2 0.12 0.06
0.8
0.8
0.68
0.6
0.6
0.4
0.4
0.88
Imaginary Axis (seconds−1)
0.2
0.2
−0.2
0.2
0.88
−0.4
0.4
−0.6
0.6
0.68
−0.8
0.8
6
Impulse Response
0.7
0.6
0.5
0.4
Amplitude
0.3
0.2
0.1
−0.1
−0.2
0 2 4 6 8 10 12 14 16 18
Time (seconds)
7
0.7
0.6
0.5
0.4
0.3
(t)
0.2
0.1
-0.1
-0.2
0 5 10 15 20 25
Time (seconds)
1.4
1.2
0.8
(t)
0.6
0.4
0.2
0
0 5 10 15 20 25
Time (seconds)
8
5.3 Ramp input
Similar to the earlier cases, a ramp response can be generated using the following MATLAB script2 :
>> T = [0:0.01:25];
>> c = 3.17;
>> ramp = c*T;
>> [Psi, T] = lsim(GCL,ramp,T);
>> plot(T,Psi,‘k’,‘Linewidth’,2);
>> hold on
>> plot(T,ramp,‘b--’,‘Linewidth’,2);
>> grid on
>> xlabel(‘Time (seconds)’)
>> ylabel(‘ \Psi (t)’)
>> legend(‘Ramp response’,‘Ramp input’)
The ramp input as well as the ramp response are shown in Fig. 6.
80
70
60
50
(t)
40
30
20
10
0
0 5 10 15 20 25
Time (seconds)
Note the lsim command is very flexible. It can be used to simulate the response of a transfer to
any input (represented as time series).
2
The command lsim is very flexible. To understand this type >> help lsim
9
6 Exercises
Exercise 1
(s+5)
In Fig. 1, replace the vehicle block with (s+10)(s+2) .
i. Compute the (new) closed loop transfer function GCL(s) between Ψ and Ψr .
ii. Determine the poles and zeros of the (new) closed loop system GCL(s).
iv. Compare the unit step responses for K = 50, K = 100, K = 150, by plotting all the three
responses in a single plot with time as the x-axis.
v. What happens to the unit step response of the closed loop system, when K = −100?
vi. Set K = 100 and compute the transfer function GCL(s). Then, determine the closed loop
response to an input signal Ψ(t) = sin( 32 t).
Proof of the Circle Criterion
Exercise 2
Consider the feedback loop
Consider the two block diagrams
−
m - m m
?
- -
G(s) r G1(s)
6 6−
−
φ y ⇔ y
m
G2(s) G2(s)
6−
10
Exercise 3 Consider two transfer functions
6s2 + 1 (s + 1)(s + 2)
G(s) = and H(s) =
s3 + 3s2 + 3s + 1 (s + 2i)(s − 2i)(s + 3)
Using MATLAB
iii. Divide G(s) by H(s) and obtain resultant transfer function J(s).
iv. Determine the pole zero map and unit step response of the resultant transfer function J(s).
[Make observations regarding the poles from the pole zero map]
C. Edwards
January 29, 2024
11