2019 - Feedback Control Systems - Matlab - Simulink Approach - Farzin Asadi, Robert E. Bolanos, Jorge Rodriguez
2019 - Feedback Control Systems - Matlab - Simulink Approach - Farzin Asadi, Robert E. Bolanos, Jorge Rodriguez
2019 - Feedback Control Systems - Matlab - Simulink Approach - Farzin Asadi, Robert E. Bolanos, Jorge Rodriguez
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in
any form or by any means—electronic, mechanical, photocopy, recording, or any other except for brief quotations
in printed reviews, without the prior permission of the publisher.
DOI 10.2200/S00909ED1V01Y201903CRM005
Lecture #5
Series Editors: Chaouki Abdallah, Georgia Institute of Technology
Mark Spong, University of Texas at Dallas
Series ISSN
Print 1939-0564 Electronic 1939-0572
Feedback Control Systems
The MATLAB®/Simulink® Approach
Farzin Asadi
Kocaeli University, Kocaeli, Turkey
Robert E. Bolanos
Southwest Research Institute, Texas, U.S.A.
Jorge Rodríguez
Power Smart Control, Leganés, Spain
M
&C Morgan & cLaypool publishers
ABSTRACT
Feedback control systems is an important course in aerospace engineering, chemical engineering,
electrical engineering, mechanical engineering, and mechatronics engineering, to name just a
few. Feedback control systems improve the system’s behavior so the desired response can be
acheived.
The first course on control engineering deals with Continuous Time (CT) Linear Time
Invariant (LTI) systems. Plenty of good textbooks on the subject are available on the market, so
there is no need to add one more. This book does not focus on the control engineering theories
as it is assumed that the reader is familiar with them, i.e., took/takes a course on control en-
gineering, and now wants to learn the applications of MATLAB® in control engineering. The
focus of this book is control engineering applications of MATLAB® for a first course on control
engineering.
KEYWORDS
closed-loop control, control, controller, feeback, PID controller, MATLAB® ,
Simulink®
vii
Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
1 Introduction to MATLAB® . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Different Parts of MATLAB® . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 MATLAB’s Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 MATLAB’s Help System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.5 MATLAB’s Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.6 MATLAB’s Toolboxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.7 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.8 Basic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.9 Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.10 Trigonometrics Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.11 Logarithmic and Exponential Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.12 Complex Numbers Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.13 Rounding Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.14 Remainder Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.15 Matrixes in MATLAB® . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.16 Commands: rand, ones, zeros, eye . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.17 The Colon Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.18 logspace and linspace Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.19 Operation with Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.20 Finding Polynomial Roots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
1.21 Product of Two Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
1.22 Solution of Linear Systems of Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
1.23 Solution of Nonlinear Systems of Equations . . . . . . . . . . . . . . . . . . . . . . . . . . 23
1.24 Solving Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
1.25 Differention and Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
viii
1.26 Drawing Diagrams with MATLAB® . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1.27 Drawing the Graph of Collected Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.28 Drawing Two or More Data Simultanously . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
1.29 Drawing the Frequency Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3 Introduction to Simulink® . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
3.2 Running the Simulink® . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
3.3 Searching for Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
3.4 Example 1: Simulink® of a RLC Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
3.5 Exporting the Results to Workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
3.6 Example 2: Simulation in Transfer Functions . . . . . . . . . . . . . . . . . . . . . . . . . 108
3.7 Example 3: Simulation of Electric Circuits with the Aid of Simscap Library 109
3.8 Example 4: Simulation of Nonlinear Systems . . . . . . . . . . . . . . . . . . . . . . . . . 123
3.9 Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
3.10 Function Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
3.11 Example 5: Use of Function Block in the Simulink® Simulations . . . . . . . . . 128
3.12 Simulation of Discrete Time Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
3.13 Example 6: Simulation of Discrete Time Systems . . . . . . . . . . . . . . . . . . . . . 139
3.14 Example 7: Simulation of Discrete Time Systems . . . . . . . . . . . . . . . . . . . . . 144
3.15 Showing Two or More Signals Simultaneously . . . . . . . . . . . . . . . . . . . . . . . 145
3.16 Simulation of a Closed-Loop Control System in Simulink® . . . . . . . . . . . . . 151
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Preface
This book is composed of five chapters. Here is a brief summary of these chapters:
Chapter 1: Introduction to MATLAB® . This chapter introduces the MATLAB® for
novices. The reader learns the fundamental concepts of MATLAB® .
Chapter 2: Commonly Used Commands in Analysis of Control Systems. This chapter
studies some of the most important commands of Control Systems Toolbox™ . Commands such
tf, zpk, ss, bode, nyquist, rlocus, impulse, step, feedback, seriesi, parallel, etc. are
studied in this chapter.
Chapter 3: Introduction to Simulink® . Simulink® is one of the most important tools
for simulation of dynamical systems. Simulink® is a graphical environment. The user makes the
model of system using plenty of ready to use blocks. So, thanks to the powerful library of blocks
Simulink® has, the user can simulate even complex systems easily without dealing with coding.
This chapter introduces the Simulink® with some examples.
Chapter 4: Controller Design in MATLAB® . Computers are an important part of mod-
ern engineering sciences. Nearly all the engineering designs are done with the aid of computers.
Control engineering is not an exception at all. MATLAB’s Control System Toolbox provides
plenty of functions to the design of control systems.
About 90% of controllers in industry are PID (Proportional-Integral-Derivative). Keep-
ing this in mind, the chapter starts with pidTuner command, a powerful command to design
PID controllers. The chapter finishes with the Control System Designer app.
Chapter 5: Introduction to System Identification Toolbox™ . System Identification
makes mathematical models for dynamical systems based on their input/output signals. An il-
lustrative example is studied in this chapter.
Acknowledgments
The authors gratefully acknowledge MathWorks® support for this project.
CHAPTER 1
Introduction to MATLAB®
1.1 INTRODUCTION
MATLAB® (MATrix LABoratory) is a multi-paradigm numerical computing environment and
proprietary programming language developed by MathWorks. MATLAB® allows matrix ma-
nipulations, plotting of functions and data, implementation of algorithms, creation of user in-
terfaces, and interfacing with programs written in other languages, including C, C++, C#, Java,
Fortran, and Python.
As of 2018, MATLAB® has more than 3 million users worldwide. MATLAB® users have
varied backgrounds in engineering, science, and economics. This chapter is a general introduc-
tion to MATLAB® .
Command Window
Command window is shown with number 1 in Fig. 1.1. The MATLAB® commands are written
in this window. After the command is written, the Enter key of the keyboard must be pressed
in order to run it (see Fig. 1.2).
Work Space
Workspace window is shown with number 2 in Fig. 1.1. Variables defined inside the MATLAB®
environment are listed in Fig. 1.3.
Current Folder
Current folder window is shown with number 3 in Fig. 1.1. It shows the current working path.
You can set your desired path by clicking the “Browse for folder” icon (see Fig. 1.4).
Menu Bar
Menu bar is shown with number 4 in Fig. 1.1. It provides easy access to some of the widely
used operations (see Fig. 1.5). For instance, in order to enter the Simulink environment, the
user must type the word “simulink” in the command window. The user can get rid of writing the
word simulink by clicking the Simulink icon (Fig. 1.6) in the menu bar.
1.3. MATLAB’S EDITOR 3
You can obtain the default layout, i.e., layout shown in Fig. 1.7, by clicking the “Default.”
>>edit
Figure 1.9: Save the content of editor with the aid of save button.
6 1. INTRODUCTION TO MATLAB®
Press the F5 key on the keyboard or click the Run icon in order to run the commands
written inside the editor (Fig. 1.10).
Figure 1.12: You can use the help command to obtain information about a command.
8 1. INTRODUCTION TO MATLAB®
1.7 VARIABLES
Variable names are composed of English characters, numbers, or underline. The variable name
must start with an English character. For instance, “_myAge” or “1a” are NOT acceptable.
You can use the isvarname command in order to see if the selected name is acceptable or
NOT. For instance, if you write isvarname kp and press the Enter key, the MATLAB® shows
1. This means that the selected name (in this example “kp”) is acceptable. When MATLAB®
shows 0, it means that the name is NOT acceptable.
MATLAB® is a case-sensitive program, i.e., it is sensitive to small and capital letters. For
instance, “my_variable” and “My_variable” is NOT the same.
Some of the MATLAB’s simple commands are shown in Table 1.3.
MATLAB® does NOT show the command result on the screen if you put a semicolon at
the end of commands.
>>Dataspeed=115200;
>>Dataspeed=115200
Dataspeed =
115200
In order to see the variables defined variables, use the who command, i.e., write who in the
command window and press Enter key. If you want to see the size and number of bytes used for
variables, use the command whos.
10 1. INTRODUCTION TO MATLAB®
Commands Explanation
>>x=2018 This command asked MATLAB to make a variable named “x”. x is 1×1
matrix and contains value 2018.
>>x This command asks MATLAB to show the content of variable “x”.
>>x=x+1 This command asks MATLAB to increase the value of variable x by 1.
>>Name= ’John’ This command asks MATLAB to make a variable named “Name”.
“Name” is 1×4 matrix contains “John” word.
You can clear the screen by using the command clc. In order to clear all the variables, use
the command clear all. If you want to clear a specific variable use the command clear. You
must write the variable name after the clear.
Example 1.1
>>A=[1 2 3];
>>B=[4 5 6];
>>A./B
12 1. INTRODUCTION TO MATLAB®
ans =
>>A.^B
ans =
1 32 729
>>A.*B
ans =
4 10 18
Example 1.2
Calculate sin.x/4 3 cos.x/ for x D 30ı .
Solution:
First way:
>>x=30*pi/180;
>>sin(x)^4-3*cos(x)
ans=
-2.5356
1.10. TRIGONOMETRICS FUNCTIONS 13
Second way:
>>x=30;
>>sind(x)^4-3*cosd(x)
ans=
-2.5356
Mathematics MATLAB
1234 >>12^34
1 -3 >>(1/2)^(-3)
2
123 × 10-4 >>123*10^-4
or
>>123e-4
3
124 >>12^(3/4)
18 1. INTRODUCTION TO MATLAB®
>>A=123;
>>B=-456.7;
>>C=12e-3;
>>D=12+34*i;
Table 1.12: Entering a matrix in MATLAB® . (Note: in order to read the array in the 3rd row
and 2nd column of matrix F, you write, F(3,2).)
Mathematics MATLAB
1 2 3 >>F=[1 2 3;4 5 6;7 8 9]
or
>>F=[1,2,3;4,5,6;7,8,9]
• ones: reate array of all ones. For instance, ones(k), creates a k k matrix which all the
arrays are 1.
• zeros: create array of all zeros. For instance, zeros(k), creats a k k matrix which all
the arrays are 0.
• eye: makes identity matrix. For instance, eye(4) create a 4 4 identity matrix.
1.17. THE COLON OPERATOR 21
1.17 THE COLON OPERATOR
You can use the colon operator (:) to creat matrices. Here is the syntax:
Example 1.3
>>n=[1:2:10]
n =
1 3 5 7 9
>>n(2:4)
ans =
3 5 7
f D x 4 C 2x 3 C 3x 2 C 4x C 5:
>>f=[1 2 3 4 5]
>>roots(f)
You can use the command polyval in order to obtain the value of a polynomial function at a
specific point. For instance, in order to calculate the polynomial f at x=0 you write:
>>polyval(f,0)
>>f=[1 2 3 4 5];
>>g=[1 0 0 5];
>>conv(f,g)
1.22. SOLUTION OF LINEAR SYSTEMS OF EQUATIONS 23
ans =
1 2 3 9 15 15 20 25
Table 1.13: Solving a linear system of equations in MATLAB® . (Note: instead of BnA you can
use inv(A)*B or A O -1*B.)
Mathematics MATLAB
>>A=[1 2 3;4 5 6;7 8 8];
>>B=[1;2;3];
1 2 3 1
>>B\A
4 5 6 × = 2
ans=
7 8 9 3
-0.3333
0.6667
0
You must prepare a MATLAB® function that contains the desired equation. The structure of a
MATLAB® function is shown bellow:
study the following example to see how to use the fzero command.
24 1. INTRODUCTION TO MATLAB®
Example 1.4
Find the root of f D x 4 C 3x 3 C 3x 2 C 14x C 5 with the aid of fzero command.
Solution:
In order to prepare the MATLAB® function containing the non linear equations, enter the
editor environment (Fig. 1.15).
Figure 1.15: You can enter the editor by typing edit in the command line.
function y=f(x)
y=x^4+3*x^3+3*x^2+14*x+5;
end
1.24. SOLVING DIFFERENTIAL EQUATIONS 25
Save the file as f.m. When you save a function, you must use the same name as the function
name. Since we call the MATLAB® function f, we must save it as f.m. Type the following
command in command prompt of MATLAB® :
>>fzero(`f',0)
ans=
-0.3776
NOTE: Set the “Current Folder” window of MATLAB® to where you saved f.m, other-
wise MATLAB® cannot find the f.m.
Example 1.5
Solve dy.t
dt
/
C 4y .t/ D e t ; y .0/ D 1 with MATLAB® .
Solution:
See Fig. 1.17.
dy.t/
Figure 1.17: Solving the dt
C 4y .t/ D e t ; y .0/ D 1. (Note: syms defines symbolic vari-
ables.)
26 1. INTRODUCTION TO MATLAB®
Example 1.6
2
Solve 2 d y.t/
2 C dy.t /
dt
C 11y .t/ D e t ; y .0/ D 1; y 0 .0/ D 0 with MATLAB® .
dt
Solution:
See Fig. 1.18.
2 y.t/
Figure 1.18: Solving the 2 d C dy.t/
C 11y .t/ D e t ; y .0/ D 1; y 0 .0/ D 0.
dt 2 dt
dn
This example used the “Dn” operator instead of “diff” command(Dn(.)D dt n
.:/).
Example 1.7
Solve dy.t/
dt
D ty with MATLAB® .
Solution:
See Fig. 1.19.
dy.t /
Figure 1.19: Solving the dt
D ty .
1.24. SOLVING DIFFERENTIAL EQUATIONS 27
Example 1.8
Solve . dy.t
dt
/
C y.t //2 D 1; y .0/ D 0 with MATLAB® .
Solution:
See Fig. 1.20.
Example 1.9
d 2 y.x/
Solve D cos .2x/ y; y .0/ D 1; y 0 .0/ D 0 with MATLAB® .
dx 2
Solution:
See Fig. 1.21.
28 1. INTRODUCTION TO MATLAB®
d 2 y.x/
Figure 1.21: Solving the D cos .2x/ y; y .0/ D 1; y 0 .0/ D 0.
dx 2
Mathematics MATLAB
3– >>syms x
= 2+ 8) >>diff(‛(x^3-x)/(x^2+8)’)
=?
= 3+ 2+ >>syms x y
>>f=x^3+3*y^2+4*x*y
=?
>>diff(f,y)
3– >>syms x
2+ 8 >>int((x^3-x)/(x^2+8))
1 3 >>syms x
>>int((x^3)/(x^2+8),x,0,1)
1.26. DRAWING DIAGRAMS WITH MATLAB® 29
Example 1.10
>>x=[0:0.01:2*pi];
>>y=sin(x);
>>plot(x,y)
>>x=[0:0.01:2*pi];
>>y1=sin(x);
>>y2=cos(x);
>>plot(x,y1,x,y2)
Command Color
r red
g green
b blue
c cyan
m magenta
y yellow
k black
w white
32 1. INTRODUCTION TO MATLAB®
Table 1.17: Available markers
.
+
*
O
x
s
d
v
^
<
>
Command Explanation
grid Display or hide axes grid lines
title(‘’) Add title.
xlabel(‘’) Label X axis.
ylabel(‘’) Label Y axis.
text(x,y,’’) Add text descriptions to data points
Example 1.12
>>x=[0:0.01:2*pi];
>>y=sin(x+pi/4);
>>plot(x,y,'b--')
>>xlabel(`Time(s)')
1.26. DRAWING DIAGRAMS WITH MATLAB® 33
>>ylabel(`Voltage Values(V)')
>>grid on
You can draw the bargraph, stairstep graph, and pie chart with the aid of bar, stair, and
pie commands, respectively.
Example 1.13
>>a=[0 1 3 7 9];
34 1. INTRODUCTION TO MATLAB®
>>b=[2 1 4 2 3];
>>figure(1)
>>bar(a,b)
>>stairs(a,b)
>>pie(a)
Example 1.14
Table 1.19 shows the current-voltage for a resistor. We want to draw the plot of this data.
V (Volt) I (Amper)
0.499 0.10
0.985 0.20
1.508 0.31
1.969 0.41
2.528 0.53
2.935 0.61
3.481 0.73
3.971 0.83
4.486 0.94
4.960 1.04
5.502 1.15
6.007 1.26
6.60 1.38
Use the plot command to draw the graph (Fig. 1.29). The result is shown in Fig. 1.30.
If you need smaller grid axes, use the command grid minor. Results are shown in
Figs. 1.31 and 1.32.
38 1. INTRODUCTION TO MATLAB®
Figure 1.34: Graph of measured data. Data points are shown with red stars.
1.27. DRAWING THE GRAPH OF COLLECTED DATA 41
Use “xlabel” and “ylabel” to add descriptive texts to the axes (Figs. 1.35 and 1.36).
Figure 1.37: You can add labels to the axes with the aid of insert menu.
1.27. DRAWING THE GRAPH OF COLLECTED DATA 43
You can save the drawn graph as a graphic file. To do this use File>Save As… See
Fig. 1.38.
Figure 1.38: You can export the drawn graph as a graphic file.
44 1. INTRODUCTION TO MATLAB®
Select the desired graphic file format and save the file. See Fig. 1.39.
V (Volt) I (Amper)
0.579 0.10
0.978 0.17
1.598 0.28
1.976 0.34
2.496 0.43
2.953 0.51
3.458 0.60
4.068 0.71
4.450 0.78
4.917 0.86
5.35 0.93
5.75 1.01
6.37 1.11
6.60 1.15
Figure 1.40: You draw two or more plots on the same axes simultanously with the aid of hold
on command.
46 1. INTRODUCTION TO MATLAB®
Table 1.21: Frequency response data for circuit shown in Fig. 1.45
Magnitude Phase (
∢
( ( )
Frequency (Hz)
( ) (Degrees)
1 1.000 -0.36
10 0.998 -3.60
20 0.992 -7.16
50 0.954 -17.44
100 0.847 -32.13
150 0.728 -43.30
200 0.623 -51.48
250 0.537 -57.51
300 0.469 -62.05
350 0.414 -65.54
400 0.370 -68.30
450 0.333 -70.51
500 0.303 -72.34
550 0.278 -73.85
600 0.256 -75.14
1k
+
+
~
–
Vin 1uF Vout
–
You can add a descriptive title to the graph. To do this, click the Insert>Title and type
the desired title (Fig. 1.51).
52 1. INTRODUCTION TO MATLAB®
CHAPTER 2
Example 2.1
We want to define the following transfer function in MATLAB.
100
H .s/ D
s2 C 6s C 100
>>H=tf([100],[1 6 100]);
>> s=tf('s');
>> H=100/(s^2+6*s+100)
Example 2.2
To define following transfer function,
s 2 6s
I.s/ D
s 3 C 6s C 100
>>J=zpk([-1],[-2 -3 -4],1);
The zpk command takes three inputs: the first input is a vector contain transfer function zeros,
the second is the vector contains transfer function poles, and the third one is a gain. Since J,
has only one zero places at 1, the zero vector contains only one array, 1. The J has poles
at 2, 3, and 4. So, second input of zpk command is [ 2 3 4]. The gain zero since
sC1 sC1
J .s/ D .sC2/.sC3/.sC4/ D 1 .sC2/.sC3/.sC4/ . To model K .s/ D 5 .sC2/.ss 13/.sC4/ one must
use the command >>K=zpk([+1],[-2 +3 -4],-5).
Figure 2.1 shows how to transfer a zpk model to tf model.
You can define state space models as well. Use ss command to define state space models.
See Fig. 2.2 to see an example.
You can obtain the transfer function associated with the state space model with the aid of
tf command (Fig. 2.3).
You can obtain the location of polse and zeros with the aid of pole and zero commands,
respectively (Figs. 2.4 and 2.5).
You can obtain a graphical plot of location of poles and zeros with the aid of pzmap com-
mand. pzmap shows the location of poles with a mark and location of zeors with an open circle.
For instance, you can draw the pole-zero map of L with the aid of the following command. The
result is shown in Fig. 2.6.
>>pzmap(L)
A system is stable if all the poles lies in the open Left Half Plane (LHP), i.e., the left half
plane without the imaginary access. You can use the command isstable to learn whether or
not the system is stable.
2.2. DEFINING THE TRANSFER FUNCTION 57
Figure 2.4: Obtaining the poles and zeros. H, is a transfer function model.
Figure 2.5: Obtaining the poles and zeros. L, is a state space model.
2.2. DEFINING THE TRANSFER FUNCTION 61
>>H=tf([100],[1 6 100]);
>>isstable(H)
ans=
1
62 2. COMMONLY USED COMMANDS IN ANALYSIS OF CONTROL SYSTEMS
2.3 IMPULSE RESPONSE OF A SYSTEM
Impluse response of a system can be drawn with the aid of impulse command.
Example 2.4
Draw the impulse response of following system. The result is shown in Fig. 2.7.
100
H .s/ D
s 2 C 6s C 100
>>H=tf([100],[1 6 100]);
>>impluse(H)
>>grid on
You can ask MATLAB to show peak response and settling time. To do this, right-click
on the plot. Click on the Characteristics and select your desired option. For instance, we select
the Peak Response (Fig. 2.8).
After you clicked the Peak Response, the MATLAB shows the Peak of graph with a point
(Fig. 2.9).
After you clicked on the shown point, MATLAB adds a label and shows the coordimnate
of the point with a label (Fig. 2.10).
You can use the Data Cursor icon shown in Fig. 2.11 to add cursor to the graph. First
click the Data Cursor icon and then click a point on the graph.
Using the cursor, you can read the coordinate of desired point easily (Fig. 2.12).
You can slide the cursor to desired point. You can slide the cursor more easily if you set
the Selection Style to Mouse Position (Fig. 2.13). To see the Selection Style, right-click on the
graph.
You can zoom in/out the drawn graph with the aid of a magnifier icon (Fig. 2.14).
You can export the drawn graph as a graphic file. To do this, click theSave as… (Fig. 2.15).
Type your desired name and Select the desired graphic file (i.e., bmp, jpg, png) and export
the graphic (Fig. 2.16).
2.3. IMPULSE RESPONSE OF A SYSTEM 63
Impulse Response
7
3
Amplitude
-1
-2
-3
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Time (s)
Figure 2.9: Peak of the graph is shown with a filled blue circle.
66 2. COMMONLY USED COMMANDS IN ANALYSIS OF CONTROL SYSTEMS
Figure 2.12: You can read the coordinate of desired point with the aid of added cursor. To remove
the shown box, left-click on it and press the delete key on the keyboard.
2.3. IMPULSE RESPONSE OF A SYSTEM 69
Figure 2.13: You can move the cursor more smoothly if you select the mouse position.
70 2. COMMONLY USED COMMANDS IN ANALYSIS OF CONTROL SYSTEMS
Figure 2.14: You can zoom in/out with the aid of a magnifier.
2.3. IMPULSE RESPONSE OF A SYSTEM 71
Figure 2.15: You can save the drawn plot with the aid of save as ….
72 2. COMMONLY USED COMMANDS IN ANALYSIS OF CONTROL SYSTEMS
You can draw the impulse response in a specific interval if you want. For instance, to draw
the impulse response in the [.2,1.8] interval you type:
>>H=tf([100],[1 6 100]);
>>impluse(H,[.2:.01:1.8])
>>grid on
NOTE: .01, is the time step. The above code asks MATLAB to calculate the impulse
response at t D 0:2; 0:21; 0:22; 0:23; : : : ; 1:8 and draw them. The result is shown in Fig. 2.17.
2.4. STEP RESPONSE OF A SYSTEM 73
Impulse Response
6
Amplitude
2
-1
-2
-3
0.4 0.6 0.8 1 1.2 1.4 1.6
Time (s)
Example 2.5
Draw the step response of following system. The result is shown in Fig. 2.18.
100
H .s/ D
s 2 C 6s C 100
>>H=tf([100],[1 6 100]);
>>step(H)
>>grid on
74 2. COMMONLY USED COMMANDS IN ANALYSIS OF CONTROL SYSTEMS
You can draw the step response in a specific interval if you want. For instance, to draw the
step response in the [.2,1.8] interval you type:
>>H=tf([100],[1 6 100]);
>>step(H,[.2:.01:1.8])
>>grid on
NOTE: .01, is the time step. The above code asks MATLAB to calculate the step response
at t D 0:2; 0:21; 0:22; 0:23; : : : ; 1:8 and draw them. The result is shown in Fig. 2.19.
2.4. STEP RESPONSE OF A SYSTEM 75
Step Response
1.4
1.3
1.2
Amplitude
1.1
0.9
0.8
0.4 0.6 0.8 1 1.2 1.4 1.6
Time (s)
You can ask MATLAB to measure the important characteristics of the response and shows
them. To do this, right-click on the step response plot and click characteristics. Select desired
option from the shown menu. See Fig. 2.20.
For instance, we select the Rise Time from the shown menu. The result is shown in
Fig. 2.21. Rise time is the time it takes for the response to rise from 10–90% of the steady-
state response.
You can use the command stepinfo to see the step response characteristics (Fig. 2.22).
76 2. COMMONLY USED COMMANDS IN ANALYSIS OF CONTROL SYSTEMS
>>bode(H),grid on
If you want to draw the frequency response of a system in a specific interval, you must de-
fine the desired interval. You can use the bode(sys,w) where w is the vector of desired frequency
range.
h i if you want to draw the frequency response of system in Example 2.1 for
For instance,
Rad Rad
100 s ; 1000 s interval, you can use the following code. The result is shown in Fig. 2.24.
>>w=logspace(log10(100),log10(1000))
>>bode(H,w)
>>grid on
You can measure the important characteristics of the drawn graph by right-clicking on it
and select the Characteristics (Fig. 2.25).
2.5. DRAWING THE FREQUENCY RESPONSE OF A SYSTEM 79
Bode Diagram
-30
-40
Magnitude (dB)
-50
-60
-70
-80
-176
-177
Phase (deg)
-178
-179
-180
10-2 103
Frequency (rad/s)
h i
Figure 2.24: Bode plot of H for 100 Rad
s
; 1000 Rad
s
interval.
2.6. DRAWING THE NYQUIST DIAGRAM OF A SYSTEM 81
>>nyquist(H)
You can see the characteristics of the drawn plot by right-clicking the plot and select the
characteristics (Fig. 2.27).
You can add the grids to the drawn graph by right-clicking on the graph and click the
Grid in the appeared list (Fig. 2.28). The result is shown in Fig. 2.29. Another way of adding
grid to your graph is typing the >>grid on in the MATLAB command prompt.
82 2. COMMONLY USED COMMANDS IN ANALYSIS OF CONTROL SYSTEMS
Figure 2.28: Click the grid in order to add the axes grids to the drawn Nyquist plot.
2.7. ROOT LOCUS PLOT 85
Click the Data Cursor icon in order to add a cursor to the plot. Move the added cursor;
the required gain is shown for each point (Fig. 2.31).
86 2. COMMONLY USED COMMANDS IN ANALYSIS OF CONTROL SYSTEMS
2s 2 C5sC1
Figure 2.30: Root locus of H.s/ D s 2 C2sC3
.
2.7. ROOT LOCUS PLOT 87
Figure 2.31: You can use the cursor to see the required gain. According to the shown box,
gain of 0.125 places one of the closed loop poles at 1:05 C 1:15i . You can use the command
pole(feedback(0.125*H,1) to check it (H=tf([2 5 1],[1 2 3])).
There is another command to draw the root locus plot: rltool. With the aid of rltool
you can see the movement of all the poles at the same time. Type the following commands:
Figure 2.32: Control system designer window will appear after you run the rltool command.
2.8. CONNECTING THE SYSTEMS TOGETHER 89
Figure 2.33: Click the root locus editor for loop transfer tab to see the root locus plot. Closed
loop poles are shown with black arrows.
Move the closed-loop poles to desired location. To do this, left-click the pink points and
move the points to the desired location without releasing the left mouse button. You can see the
movement of all points at the same time. Required gain and other useful information are shown
in the bottom of the window (Fig. 2.34).
>>P=tf([1],[1 3 3 1]);
90 2. COMMONLY USED COMMANDS IN ANALYSIS OF CONTROL SYSTEMS
1.13 + .45 1
+_ 3+3 2+3 +1
Controller Plant
>>CL=feedback(C*P,1)
You can see the step response of closed-loop system with the >>step(feedback(C*P,1)) com-
mand.
Consider a block diagram such as the one shown in Fig. 2.36.
In this case, the closed-loop transfer function can be calculated as follows:
2.8. CONNECTING THE SYSTEMS TOGETHER 91
1
+_ 3+3 2+3 +1
1.13s + .45
>>P=tf([1],[1 3 3 1]);
>>CL=feedback(P,C)
Consider the block diagram shown in Fig. 2.37 (the feedback is positive in this block
diagram).
1
++ 3+3 2+3 +1
1.13s + .45
>>P=tf([1],[1 3 3 1]);
>>CL=feedback(P,C,+1)
1.13 + .45 1
3 + 32 + 3 +1
Controller Plant
1
++
3 + 32 + 3 +1
1.13 + .45
CHAPTER 3
Introduction to Simulink®
3.1 INTRODUCTION
Simulink® is a graphical programming environment for modeling, simulating, and analyzing
multidomain dynamical systems. Using Simulink® , the user can simulate the system behavior
without using any code! The user only drag and drop the required blocks from the library to the
simulation file and connect them. This chapter introduces this important tool with the Aid of
some examples.
>>simulink
You can even click the Simulink® icon in the menu bar in order to run Simulink® (Fig. 3.1).
Figure 3.5: Use the shown icon if Simulink® doesn’t show the library browser.
Figure 3.8: Use the Enter search term to find the desired blocks.
S R = 1Ω L = 1H
C = 1F
V
We want to simulate this Differential Equation in Simulink® . To do this, we rearange the ob-
tained equation as
d 2 i .t/ R d i .t / 1 d i .0/ E
D i .t/ i .0/ D 0 D : (3.2)
dt 2 L dt LC dt L
100 3. INTRODUCTION TO Simulink®
Use the Simulink® Library Browser to add two integrators to the simulation file. Connect them
as shown in Fig. 3.10.
2!/ "^2 i/ " !
> 1 1 >
# #
Integrator 1 Integrator
Add two gain blocks, a summer and a scope to the simulation file, and connect them as
shown in Fig. 3.11.
2 /!^2 i/!
+ 1 1
+ " "
Integrator1 Integrator Scope
Gain1
-R/L
Gain
-1/L/C
Double-click on the gain blocks and set their Gain box (see Figs. 3.11 and 3.12) to R=L
and 1=L=C . We will define the value of R, L, and C later.
Simulink® has different solvers to solve the systems dynamic equation. The user can set
his/her desired solver. To set the solver, click on the gearbox icon (Fig. 3.13).
Select the desired solver from Solver: drop down list (Fig. 3.14).
ode45 is a quite good solver for this example. Simulink® shows the active solver, i.e., the
one which will be used during the simulation, in the bottom right side (Fig. 3.15).
We filled the values of gain blocks with R=L and 1=L=C . So, we must define the used
variables before running the simulation. Otherwise the simulation will fail and an error message
will be produced.
To define the values of aforementioned variables, go to command prompt and enter the
commands shown in Fig. 3.16.
i .0/
The differential equation has the i .0/ D 0; d dt DE
L
set of initial conditions. To set the
initial conditions, double-click the integrators and set the Initial condition box (Fig. 3.17). Set
the initial condition of left integrator to E=L and the right one to 0 (Fig. 3.18).
3.4. EXAMPLE 1: Simulink® OF A RLC CIRCUIT 101
Figure 3.15: Active solver is shown in the right button of the screen.
2 /!^2 i/!
+ 1 1
+ " "
Integrator1 Integrator Scope
Gain1
-R/L
Gain
-1/L/C
Figure 3.18: Set the initial condition of left integrator to E=L and the right one to 0.
Enter the desired simulation interval inside the following box (see Fig. 3.19). The box is
filled with 10, so the system response is calculated for an interval of 10 s.
Press the F5 button on your keyboard or click the shown icon to run the simulation
(Fig. 3.20).
After simulation is finished, double-click the scope block to see the current (Fig. 3.21).
3.5. EXPORTING THE RESULTS TO WORKSPACE 105
2 /!^2 i/!
+ 1 1
+ " "
Integrator1 Integrator Scope
Gain1
-R/L
Gain
-1/L/C
Figure 3.24: Simout and tout are added to the workspace variables.
We want to study the capacitor voltage in presence of a ramp voltage. We draw the sim-
ulation diagram shown in Fig. 3.26. The simulation result is shown in Fig. 3.27.
1
* .!2 + #* .! + 1
Ramp Transfer Fcn Scope
We give the system dynamics to Simulink® in the previous examples, i.e., we do the modeling
phase by ourselves. We show how Simulink® can be used to simulate electric circuits in this ex-
ample. Simulink® has a library named Simscape (see Fig. 3.28) which contains electrical blocks,
i.e., resistors, capacitors, inductors, MOSFETs, AC/DC motors, etc. The Simscape library is
used in this example.
S R = 1Ω L = 1H
C = 1F
V
Add three Series RLC branch (see Figs. 3.33 and 3.34) to the simulation file.
Double-click the Series RLC branch’s. Use the Branch type (see Fig. 3.35) to convert the
components to a resistor, an inductor, and a capacitor (see Fig. 3.36).
Double-click the components to set their values. Set the initial condition of induc-
tor/capacitor as shown in Fig. 3.37.
Go to Simscape>SimPowerSystems>Specialized Technology>Fundamental Blocks.
Click the Electrical Sources (see Fig. 3.38) and select a DC Voltage Source (see Fig. 3.39).
Drag and drop the DC source to simulation file (see Fig. 3.40).
We need voltmeter and ammeter to show the circuits voltage and currents.
Voltmeter and ammeter can be found in Simscape>SimPowerSystems>Specialized
Technology>Fundamental Blocks>Measurements (see Fig. 3.41).
Add voltmeter and ammeter to the circuit (see Figs. 3.42 and 3.43).
You can rotate a block place in the simulation file. To do this right-click the block and
select the Rotate and flip. You can rotate a block by left-clicking it and then pressing the Ctrl+R
(see Fig. 3.44).
All the simulations contains the SimPowerSystems blocks must contain a powergui block
(Fig. 3.45). Otherwise the simulation can’t be run and lead to an error message (see Fig. 3.46).
The complete simulation diagram is shown in Fig. 3.47
After running the simulation, the result shown in Fig. 3.48 is obtained.
112 3. INTRODUCTION TO Simulink®
Figure 3.34: Addition of three series RLC branch to the simulation file.
114 3. INTRODUCTION TO Simulink®
Figure 3.36: Conversion of series RLC branches to resistor, inductor, and capacitor.
116 3. INTRODUCTION TO Simulink®
Figure 3.46: An error message occurs when you don’t add the powergui to your simulation file.
122 3. INTRODUCTION TO Simulink®
Continuous
powergui
+ i
− + + +
Current Measurement
Series RLC Branch Series RLC Branch 1 Series RLC Branch 2
+ +v ×
DC Voltage Source −
Voltage Measurement Product Scope
iL and vC are system states and u is the system input. u only takes two values: 0 and 1, i.e.,
u 2 f0; 1g. All the initial conditions are zero, i.e., iL .0/ D 0 and vC .0/ D 0.
When u D 1, (
d
i D vLin
dt L
d 1
(3.5)
v D RC
dt C
vc :
When u D 0, (
d vin vc
i
dt L
D L
d 1 1
(3.6)
v
dt C
D i
C L
v :
RC c
1 iL
E 1/L +
+ s
Constant 2 Gain Integrator
0
Constant1 >0
-1/L
Gain3 Switch
vc
+ 1
Pulse -1/R/C + s
Generator
Integrator1
Gain2
Constant >0
1/C
Gain1 Switch1
0 T/2 T t[s]
1
Figure 3.50: Excitation signal T D 25000
D 40 s .
3.8. EXAMPLE 4: SIMULATION OF NONLINEAR SYSTEMS 125
iL
20
15
10
iL
0
-5
-10
-15
0 2 4 6 8 10 12 14 16 18 20
Time (ms)
vC
50
45
40
35
30
vC
25
20
15
10
0
0 2 4 6 8 10 12 14 16 18 20
Time (ms)
1
Step Integrator Scope
1
Step Integrator Scope
1
Step Integrator Scope
Subsystem
Figure 3.55: Simulink® convert the selected blocks into a subsystem once create subsystem is
clicked.
In1 Out1
Subsystem
Connect a Step and Scope blocks to the subsystems, as shown in Fig. 3.58.
In1 Out1
Step Scope
Subsystem
Figure 3.58: Addition of step and scope block to the simulation file.
_ !"
1
% +
+ #
Sine Wave Product Integrator Scope
Gain
3
Figure 3.59: Simulink® diagram of Example 5 in Section 3.11. No function block is used in this
simulation.
f(u)
Fcn
Double-click the Fcn block and fill the Expression box, as shown in Fig. 3.63.
3.11. EXAMPLE 5: USE OF FUNCTION BLOCK IN THE Simulink® SIMULATIONS 131
The u.1/ and u.2/ are the inputs of the multiplexer block. The u.1/ is the topmost input
(see Fig. 3.64).
u(1)
f(u)
u(2)
Fcn
Figure 3.64: Input of function block are u.1/ and u.2/. u.1/ is the topmost input.
1
f(u)
Sine Wave
Fcn Scope
Figure 3.65: Simulink® diagram of Example 5 in Section 3.11. Function block is used in this
simulation.
Use of function blocks (when possible) is suggested. The simulation result is shown in
Fig. 3.66.
132 3. INTRODUCTION TO Simulink®
2 x .n 1/ C 6 x .n 2/ D x .n/ ; x . 1/ D 11x . 2/ D 7:
We want to obtain x .n/ ; n 0. Some of the first terms can be calculated manually
x .0/ D 2 11 C 6 7 D 64
x .1/ D 2 64 C 6 11 D 194
x .2/ D 2 194 C 6 64 D 772:
The system can be simulated with the aid of simulation diagram shown in Fig. 3.69.
The initial condition can be set with the aid of Initial condition box. Double-click the delay
blocks (Figs. 3.70 and 3.71), after the block is opened; set their corresponding initial condition
value (Fig. 3.72).
134 3. INTRODUCTION TO Simulink®
Delay1 Delay
Figure 3.68: Two delay blocks are added to the simulation file.
Scope
+
+ -1 -1
Delay1 Delay
Gain
Gain1
Scope
11 7
+
+ -1 -1
Delay1 Delay
Gain
Gain1
Figure 3.72: Initial value of left delay block is set to 11 and the right block is set to 7.
Click the gear icon and set the Solver to Discrete (no continuous state). See Figs. 3.73
and 3.74.
Figure 3.74: Setting the solver type to discrete (no continuous states).
3.13. EXAMPLE 6: SIMULATION OF DISCRETE TIME SYSTEMS 139
y .n/ 3 y .n 1/ D 4n 1
; y . 1/ D 0:
y .n/ D 3 y .n 1/ C 4n 1
; y . 1/ D 0:
140 3. INTRODUCTION TO Simulink®
The first few terms can be calculated:
y .0/ D 3 0 C 4 1 D 0:25;
3 7
y .1/ D C 1 D D 1:75;
4 4
21 37
y .2/ D C4D D 9:25:
4 4
The system can be simulated with the aid of following simulation diagram (see Fig. 3.76).
Scope
f(u) + -1
+
Clock Zero-Order Fcn Delay
Hold
Gain
1
In order to produce the excitation term (4n 1 term), we used a Clock block, a Zero-Order
Hold block, and a function block (Fig. 3.77). The clock block produces a continuous output.
Zero-Order Hold converts the output of the clock block to a staircase signal (see Figs. 3.78,
3.79, and 3.80).
3.13. EXAMPLE 6: SIMULATION OF DISCRETE TIME SYSTEMS 141
0.25 Scope
Gain1
+
+
-1
+
1 -1 0.25
Delay
Constant Delay1 Gain2
Gain
0.5
Sine Wave
Scope
Step
Repeating
Sequence
Stair
1.13s + .45 1
+_
s s3 + 3s2 + 3s +1
Controller Plant
1 1
s+1 s+1
Transfer Fcn 1 Transfer Fcn
Figure 3.91: Adding two transfer function block to the simulation file.
3.16. SIMULATION OF A CLOSED-LOOP CONTROL SYSTEM IN Simulink® 153
Add a summer to the simulation file (Figs. 3.92 and 3.93).
1 1
+
+ s+1 s+1
Transfer Fcn 1 Transfer Fcn
Figure 3.94: Set the List of signs to C in order to simulate negative feedback.
1 1
+
− +1 +1
Transfer Fcn 1 Transfer Fcn
1 1
+
− +1 +1
Controller Plant
Double-click on the Controller and Plant and set the transfer functions, as shown in
Figs. 3.97 and 3.98. The simulation diagram looks like the one shown in Fig. 3.99 after you
change the coefficients.
You can make the Plant a little bit bigger to see the equation of transfer function inside it
(Fig. 3.100).
Add a step block to the simulation file (Figs. 3.101 and 3.102).
Double-click the simulation file. Step time is set to 1 by default (Fig. 3.103). This cause
the block to produce the signal shown in Fig. 3.104. Turn the Step time to 0 if you want to
stimulate the system with the one shown in Fig. 3.105.
Add a Scope block to the system (Fig. 3.106). An scope block is added to see the plant
output (Fig. 3.107). Run the simulation with the aid of the button shown (Fig. 3.108). See the
results in Fig. 3.109.
156 3. INTRODUCTION TO Simulink®
1.13s + .45 1
+
− s den(s)
Controller Plant
1.13 + .45 1
+
− 3 + 32 + 3 + 1
Controller Plant
Figure 3.100: Drag the plant sides in order to show the transfer function inside it.
1.13 + .45 1
+
− 3 + 32 + 3 + 1
Step Controller Plant
1.5
0.5
-0.5
-2 -1 0 1 2
1.5
0.5
-0.5
-2 -1 0 1 2
1.13 + .45 1
+
− 3 + 32 + 3 + 1
Step Controller Plant Scope
Figure 3.108: Run the simulation with the aid of the button shown.
CHAPTER 4
Controller Design in
MATLAB®
4.1 INTRODUCTION
MATLAB® can be used to design different types of controllers. This chapter introduces some
of the most important tools provided by MATLAB® to design linear controllers.
PID controllers are the most commonly used controller used in real world. About 90% of
controllers used in industry are PID controllers. Fortunatly, MATLAB® has powerful functions
to tune this important controller. Using MATLAB® a PID controller can be tuned within few
minutes!
pidTuner.plantName/
We must define the dynamical equation in the MATLAB® environment. We do the job with
the aid of one of the following commands.
or
>>H=zpk([-1],[-2 -3 -4],1);
The step function of this transfer function is shown in Fig. 4.1. So, there is a need to a
controller, since it cannot track a step signal, i.e., the steady-state error is not zero. The systems
is slow as well.
164 4. CONTROLLER DESIGN IN MATLAB®
Step Response
0.05
0.045
0.04
0.035
0.03
Amplitude
0.025
0.02
0.015
0.01
0.005
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Time (s)
>>pidTuner(H)
Figure 4.5: You can tune the controller in the frequency domain.
Figure 4.7: The controller parameters are shown in the bottom left side of the window.
Always ensure that the control signal (see Fig. 4.8) is within the desired range. Obtaining
a desired output response (Fig. 4.7) is not enough; you must ensure the controller is able to
produce the control signal as well. To ensure that control signals are withing their range, click
the Add Plot icon and select the Controller Effort (Fig. 4.9).
Control Signal
+
−
Controller Plant Output
Figure 4.8: Control signal (control effort) is the signal produced by the controller.
The controller effort window will be added to the PID Tuner window (Fig. 4.10).
168 4. CONTROLLER DESIGN IN MATLAB®
Figure 4.9: Plot of controller effort can be added to the main window by clicking the controller
effort.
4.2. PID CONTROLLER DESIGN IN MATLAB® 169
Figure 4.10: The designer can see the controller effort while he/she changes the sliders.
If the control signal is too large, repeat the design process, i.e., change the sliders until you
obtain a more suitable response. Openning the controller effort plot is always suggested. Since
the designer can see the control signal during the design process.
We want to regenerate the graphics shown in Fig. 4.10. Since the Kp D 41:59 and Ki D
105:1 the controller equation is Hc .s/ D 41:59 C 105:1 s
. The following code (Fig. 4.11) draws
the closed-loop step response. The result is shown in Fig. 4.12 and is the same with the graph
shown in bottom left of the window (see Fig. 4.10).
The following code (Fig. 4.13) draws the control signal (control effort) for a step input.
The result is shown in Fig. 4.14 and is the same with the graph shown in bottom right of the
window (see Fig. 4.10).
Use the Export icon to export the designed controller into the MATLAB® workspace
(Fig. 4.15).
170 4. CONTROLLER DESIGN IN MATLAB®
After you click the Export icon, the following window will appear (Fig. 4.16). Click
OK to export the controller. The designed controller is saved in a variable named C inside the
workspace.
You can see the closed-loop step response with the aid of following command:
>>step(feedback(H*C,1))
+ PID(s) +1
− 3 + 92 + 26 + 24
Step PID Controller Transfer Fcn Output
Figure 4.19: Select the desired type of controller from the drop-down list.
The Simulink® runs the PID Tuner for you. You can tune the block in the same way
studied before (Fig. 4.21). Once you obtain the desired output response (with acceptable control
4.3. TUNING THE PID CONTROLLERS INSIDE THE Simulink® ENVIRONMENT 175
effort) you can click the Update Block icon and Simulink® update the PID block with the new
coefficients (Fig. 4.22).
Figure 4.21: Simulink® runs the PID tuner after you clicked the tune ….
176 4. CONTROLLER DESIGN IN MATLAB®
Figure 4.22: Click the update block to update the controller coefficients.
Figure 4.23: Control system designer can be run with the command controlSystemDesigner.
We want to design a linear controller for H.
You can select the desired structure using the “Edit Architecture” button as shown in
Fig. 4.25. Using the icons you can import the transfer functions from the Workspace.
You can use the “Tuning Methods” button (Fig. 4.26) and “Automated Tuning” section
to automatically tune the controller (Block C in Fig. 4.25). If you click the “PID Tuning,” a
window like that shown in Fig. 4.27 will appear.
You can do the tuning either in time domain or frequency domain (Fig. 4.28).
4.4. DESIGN OF LINEAR CONTROLLERS WITH SISOTOOL 177
Figure 4.25: Selecting the desired control topology. The one shown with black arrow is the most
commonly used topology.
4.4. DESIGN OF LINEAR CONTROLLERS WITH SISOTOOL 179
Figure 4.28: Tuning can be done either in time domain or frequency domain.
182 4. CONTROLLER DESIGN IN MATLAB®
1. Select the desired controller type (P, PI, PID, etc.). Always start with simple P-type con-
troller. If response is not acceptable then use PI or PID.
5. See the step response and decide whether the response is good or not. If you are not happy,
redo the previous steps, i.e., move the sliders again.
You can right-click on the shown step response and use the Characteristics in order to see
the characteristics of the response (Fig. 4.30).
4.4. DESIGN OF LINEAR CONTROLLERS WITH SISOTOOL 183
You can export the tuned controller to Workspace. To do this, click the Export button
(Fig. 4.31).
A window like the one shown in Fig. 4.32 will appear. Check the box to the left of C and
click the Export button.
A new variable named C will be added to Workspace after you clicked Export button. It
contains the designed controller. You can see the controller equation with the aid of tf command
(Fig. 4.33).
184 4. CONTROLLER DESIGN IN MATLAB®
You can use design the controller by using the loop shaping method (Fig. 4.34).
U(s) R(s)
+
−
C(s) P(s)
Figure 4.35: Schematic of a simple closed loop control system. C(s) and P(s) show the controller
and plant, respectively.
If we apply a step function to such a system, it tracks the step function with zero steady-state
error within K5 s. For example, if C .s/ P .s/ D 1000
s
, it takes about 1000 5
D 5 ms, to track the
step command. The response is shown in Fig. 4.36. Note that the response has no overshoot or
oscillatory nature.
!n 2
As another example, assume that C .s/ P .s/ D s.sC2 !n /
. In this case, the closed-loop
transfer function is
!n 2
R.s/ s.sC2 !n / !n 2
HCL .s/ D D D :
U.s/ !n 2
1 C s.sC2! s 2 C 2!n s C !n 2
n /
Based on the values of and !n , the response takes different forms. Figure 4.37, shows the step
response for two different values of . As you see, an increase in decrease the oscillatory nature.
Loop shaping takes the desired loop transfer function (i.e., Hdesired .s/) and design the
controller block (block C in Fig. 4.35) such that the error between Hdesired .s/ C.s/P .s/ is
minimized.
One may ask, C.s/ D Hdesired
P .s/
.s/
makes the error zero since,
Hdesired .s/
Hdesired .s/ C.s/P .s/ D Hdesired .s/ P .s/ D 0:
P .s/
4.5. LOOP SHAPING 187
Step Response
1
0.9
0.8
0.7
0.6
Amplitude
0.5
0.4
0.3
0.2
0.1
0
0 1 2 3 4 5 6 7 8 9
Time (s) ×10-3
1000
Figure 4.36: Step response of sC1000
.
188 4. CONTROLLER DESIGN IN MATLAB®
Step Response
1.8
ζ = 0.7
1.6 ζ = 0.1
1.4
1.2
Amplitude
1
0.8
0.6
0.4
0.2
0
0 0.01 0.02 0.03 0.04 0.05 0.06
Time (s)
Although the approach seems correct, it is not applicable except for simple cases. Studying an
4
example is quite usefull. For example, assume that P .s/ D .sC7/.sC8/ and Hdesired .s/ D 10
s
. So,
C.s/ D Hdesired
P .s/
.s/
D 10.sC7/.sC8/
4s
. The obtained controller is not proper, so it is not realizable.
The Loop Shaping button in “AUTOMATED TUNING” section of Fig. 4.34, uses op-
timization techniques to obtain the proper controller C(s). User translates the requirement into
the Hdesired .s/ for example if one need a response free of overshoot with settling time less than
5 ms, he/she may use Hdesired .s/ D C.s/P .s/ D 1000s
is a good option. If an overshoot of less than
10002
5% is acceptable, one may use Hdesired .s/ D C.s/P .s/ D s.sC20:71000/ . Normally, Hdesired .s/
is selected among the first- and second-order transfer functions to avoid increase in the order of
designed controller.
When you click the Loop Shaping button in Fig. 4.34, the window shown in Fig. 4.38 will
appear. You enter the selected Hdesired .s/ into the “Target open-loop shape (LTI)” box using the
command “tf.” “Frequency range for loop shaping [wmin,wmax]:” box takes the frequency por-
tion where the optimization must be done. Normally, we need the overlap in the low frequency
range.
4.5. LOOP SHAPING 189
“Desired controller order” slider bar takes the controller order. You start by lower values
(i.e., 1). Design process is started by pressing the “Update Compensator” button. When the
order of controller is too low, the software shows a warning and asks you to increase the order.
In this case you increase the order by one. If the warning comes out again, you increase it again.
190 4. CONTROLLER DESIGN IN MATLAB®
4.6 MANUAL CONTROLLER DESIGN
You can add your desired pole/zero to the controller. Adding the pole/zero can be done by right-
clicking one of the diagrams shown in the Control System Designer environment (Fig. 4.39).
You can add the desired pole/zero by selecting the “Add Pole/Zero” as shown in Fig. 4.40. As
shown in Fig. 4.40 you can add integrator, lead, lag, etc. easily by clicking the corresponding
choice. If the steady-state error for a step input is not zero, add an integrator to the loop.
You can push the left mouse button on the Bode diagram and (without releasing the left
mouse button) move the diagram up/down. This lets you to set the gain of system.
The P.M. and G.M. on the Bode plot shows Phase Margin and Gain Margin, respectively.
You can see the equation of designed controller by right-clicking on the plots and select Edit
Compensator (Fig. 4.41).
Figure 4.41: Click the edit compensator to see the equation of controller.
193
CHAPTER 5
Introduction to System
Identification Toolbox™
5.1 INTRODUCTION
In the previous chapters we assumed that the dynamical model of plant is known. If you don’t
know the dynamical model of plant in hand, you can make a model for it based on the in-
put/output data. System identification is a methodology for building mathematical models of
dynamic systems using measurements of the system’s input and output signals.
This chapter introduces the System Identification Toolbox™ with an example.
.s C 1/ .s C 2/ 30s 2 C 90s C 60
H .s/ D 30 D 3 : (5.1)
.s C 3/ .s C 4/ .s C 5/ s C 12s 2 C 47s C 60
! "
To Workspace To Workspace1
302 + 90 + 60
+ 122 + 47 + 60
3
The system is stimulated with a step function. Meanwile the input and output of the
system are send to workspace for further process.
The “To Workspace” blocks Save format is set to Structure With Time (Figs. 5.2 and 5.3).
Click the gear icon. Do the setting such as the one shown in Fig. 5.4. This asks the
Simulink® to sample the input/output with the rate of 10 ms (Fig. 5.5).
194 5. INTRODUCTION TO SYSTEM IDENTIFICATION Toolbox™
Run the simulation. After the simulation is done, three new variables are added to
MATLAB® Workspace. These are tout, u, and y (Fig. 5.6).
Figure 5.6: New variables (tout, u, and y) are added to the workspace.
>>U=u.signals.values;
>>Y=y.signals.values;
The following command draws the input and output on the same graph (Fig. 5.7).
>>plot(tout,U,tout,Y),
2.5
1.5
0.5
0
0 0.5 1 1.5 2 2.5 3
Time (s)
Figure 5.7: Input/output signals of system (Fig. 5.1) are drawn on the same graph.
>>ident
Figure 5.12: Select transfer function models… to estimate a transfer function for the in-
put/output data.
Set the Number of poles and zeros (Fig. 5.13). You must have some insight about your
system to set these values, i.e., you know the order of your system. We asked the toolbox to make
a third-order model for us. After you enter the number of polse and zeros, click the Estimate
button. The toolbox start processing (Fig. 5.14).
After calculations finished, you can see the summary of what has been done in the Result
section of the window (Figs. 5.14 and 5.15). Fit to estimation data must be a larg number (i.e.,
80%). It can be an indicator of how reliable our model is. Since we have no noise and we set the
number of poles and zeros, it reaches 100% in this example. However, in a real-world application,
i.e., when the data is collected with sensors, there are some noise and reaching 100% seems
difficult.
202 5. INTRODUCTION TO SYSTEM IDENTIFICATION Toolbox™
Figure 5.13: Defining the order of model, i.e., how many poles/zeros the model have.
5.2. ILLUSTRATIVE EXAMPLE 203
Click Close to return to main window of toolbox. If you want to send the calculated trans-
fer function to MATLAB® workspace, you can drag the tf1 and release it on the To Workspace
button (Fig. 5.16).
You can see a variable named tf1 is added to the Workspace (Fig. 5.17).
Type tf1 at the Workspace to see the obtained transfer function equation (Fig. 5.18).
5.2. ILLUSTRATIVE EXAMPLE 205
Figure 5.19: Estimating a second-order model to the imported data. In this case the Fit to
estimation decreased slightly.
Bode Diagram
10
0
Magnitude (dB)
-10
-20
-30
45
Phase (deg)
-45
-90
10-2 10-1 100 101 102 103
Frequency (rad/s)
Figure 5.20: Drawing of the original systems frequency response and the second-order estimate
on the same graph.
209
References
[1] Katsuhiko Ogata, Modern Control Engineering, Pearson, 2009. DOI: 10.1115/1.3426465.
[2] Benjamin C. Kuo and Farid Golnaraghi, Automatic Control Systems, Wiley, 2002.
[3] Gene F. Franklin, J. Da Powell, and Abbas Emami Naeini, Feedback Control of Dynamic
Systems, Pearson, 2014.
[4] Chi-Tsong Chen, Linear System Theory and Design, Oxford University, 2012.
[5] Katsuhiko Ogata, Matlab for Control Engineers, Pearson, 2007.
[6] Simscape User’s Guide, MathWorks, 2015.
[7] Lennart Lejung, System Identification: Theory for the User, Prentice Hall, 1999.
[8] Johan Schoukens, Rik Pintelon, and Yves Rolain, Mastering System Identification in 100
Exercises, Wiley, IEEE Press, 2012. DOI: 10.1002/9781118218532.
[9] Katsuhiko Ogata, Matlab for Control Engineers, Pearson, 2007.
[10] Brian Hahn and Daniel T. Valentine, Essential Matlab for Engineers and Scientists, Aca-
demic Press, 2016.
[11] Farzin Asadi, Computer Techniques for Dynamic Modeling for DC-DC Power Converters,
Synthesis Lectures on Power Electronics, Morgan & Claypool Publishers, 2018.
[12] Farzin Asadi, Robust Control of DC-DC Converters: The Kharitonov’s Theorem Approach with
MATLAB® Codes, Synthesis Lectures on Power Electronics, Morgan & Claypool Publish-
ers, 2018.
[13] Farzin Asadi and Key Eguchi, Dynamics and Control of DC-DC Converters, Synthesis Lec-
tures on Power Electronics, Morgan & Claypool Publishers, 2018.
[14] Farzin Asadi, Sawai Pongswadt, Kei Eguchi, and Ngo Lam Trung, Modeling Uncertainties
in DC-DC Converters with MATLAB® and PLECS® , Synthesis Lectures on Power Elec-
tronics, Morgan & Claypool Publishers, 2018.
211
Authors’ Biographies
FARZIN ASADI
Farzin Asadi is with the Department of Mechatronics En-
gineering at the Kocaeli University, Kocaeli, Turkey. Farzin
has published 30 international papers and 10 books. He is on
the editorial board of 6 scientific journals as well. His research
interests include switching converters, control theory, robust
control of power electronics converters, and robotics.
ROBERT E. BOLANOS
Robert E. Bolanos received a B.S. in Electrical Engineering
from the University of Texas at San Antonio, and an M.S.
in Electrical Engineering from the University of Idaho. Cur-
rently, he is a Principal Engineer at Southwest Research Insti-
tute, Space Science and Engineering Division 15. Mr. Bolanos
designs space-rated switch power supplies, RF oscillators, and
high voltage pulsers. He has worked on both NASA and ESA
space projects such as IBEX, JUICE, BepiColombo, and EU-
ROPA (MASPEX).
212 AUTHORS’ BIOGRAPHIES
JORGE RODRÍGUEZ
Jorge Rodríguez received a B.S. in Electronics Engineering
and a Master’s in Electronics Engineering, both at Carlos III
University of Madrid (Spain). Currently, he is working as a
R&D hardware engineer at Power Smart Control focusing on
SoC devices, developing HIL systems, and as a support engi-
neer for PSIM and SmartCtrl software.