60
Matlab Exercises for Introductory Control Theory Jenő Hetthéssy Ruth Bars András Barta Department of Automation and Applied Informatics Budapest University of Technology and Economics 2004

Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Embed Size (px)

Citation preview

Page 1: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Matlab Exercises

for Introductory Control Theory

Jenő Hetthéssy Ruth Bars

András Barta

Department of Automation and Applied Informatics Budapest University of Technology and Economics

2004

Page 2: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

2

Contents

Foreword ..........................................................................................................................................3

1. Introduction to Matlab..................................................................................................................4

2. Introduction to Matlab Control System Toolbox .......................................................................10

3. The Frequency Function.............................................................................................................16

4. Elements of a Linear System......................................................................................................20

5. Feedback and Closed Loop ........................................................................................................27

6. Stability ......................................................................................................................................30

7. Series PID Compensation...........................................................................................................34

8. Series Compensation in Case of Dead Time..............................................................................41

9. Controlling Unstable Processes..................................................................................................44

10. Discrete-time Systems..............................................................................................................46

11. Discrete PID Control ................................................................................................................50

12. State Space Representation, Observability, Controllability .....................................................53

13. State Feedback Control ............................................................................................................56

Page 3: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Foreword .

3

Foreword This book is intended to aid students in their study of MATLAB/SIMULINK for use in solving control problems. Specifically, 13 labs for an introductory control course have been developed at the Department of Automation and Applied Informatics. This book is a collection of these labs. The importance to accompany text books by labs using CAD software was recognized decades ago at the Department. That time a set of FORTRAN libraries supported the instructions both in control systems analysis and design. We still believe that learning control theory is best motivated by applications and simulations rather than by concepts only. In fact, the use of MATLAB allows a lot of theoretical concepts to be easily implemented. If students can immediately show for themselves how certain concepts work in practice, they will go back to the theoretical considerations with higher confidence and improved ability to move to the next field to study. Well, feedback is around us, anyway. The problems discussed in this book are limited to linear, time-invariant control systems. Both continuous-time and discrete-time systems are considered with deterministic inputs. MATLAB/SIMULINK is useful only for those students, who master the tools offered. Though the application of MATLAB commands is simple and straightforward, a systematic introduction together with control related examples is a must in our opinion. Time should be devoted to practice fundamental MATLAB facilities, alternative command sequences and visualization capabilities. Two introductory labs are devoted to demonstrate the availability and power of MATLAB in this respect. Frequency functions and transfer functions form essential tools in classical control theory. Interestingly enough, the frequency domain considerations gave remarkable impetus for the post-modern control era, as well. Four labs have been devoted to discuss fundamental analysis for continuous-time systems including feedback and stability, as well. As far as the controller synthesis is concerned, labs to treat PID compensation and series compensation for processes with time delay have also been elaborated. The case of controlling unstable processes is involved in a separate lab. Theoretical discussion of state-space representations is supported by two labs offering a gentle introduction to the subject, as well as demonstrating the efficient algorithms and MATLAB commands available for state variable feedback. In our days controllers are implemented as digital controllers. As most of the processes to be controlled are of continuous-time in nature, digital control needs additional tools to cover sampled-data systems. Just to support the development of a proper view on discrete-time systems, an introductory lab has been added to this field. The wide class of digital controllers is limited to the design of discrete-time PID controllers in this book. Each lab is introduced by summarizing the basic concepts and definitions of the topic discussed. The MATLAB related functions are discussed in details. Labs have been designed to be accomplished within a 2 hours period each. Solved examples and reinforcement problems intend to help the better understanding. Examples range from simple drills just to demonstrate MATLAB commands to more complex problems, and in most cases a short evaluation completes the lab. It is to be emphasized that this set of labs is not a substitute of a textbook in any respect. Excellent textbooks are available for students with deep and comprehensive treatment of control related subjects. Labs in this book are intended to serve as pedagogical tools offering the students a chance for active learning and experimenting. The present set of the labs have been instructed for several semesters.

Page 4: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Introduction to Matlab .

4

1. Introduction to Matlab MATLAB is an interactive environment for scientific and engineering calculations, simulations and data visualization. Mathematics is the common language of much of science and engineering. Matrices, differential equations, arrays of data, plots and graphs are the basic building blocks of both applied mathematics and MATLAB. It is the underlying mathematical base that makes MATLAB accessible and powerful. To run external programs easily a given sequence of MATLAB commands can be composed in a script file (a text file) with a .m extension. The basic set of the MATLAB operations and functions can be extended by powerful toolboxes. To support control courses the application of the Control system toolbox is highly recommended.

The goal of this introduction is to enable the newcomers to use MATLAB as quickly as possible. However, for detailed descriptions the users should consult with the MATLAB manuals. In electronic form they can be found in the ‘matlab/help’ directory. Also, an on-line help is at the MATLAB users’ disposal.

» helpdesk The help command displays information about any command. For example:

» help sqrt Variable names: Maximum length is 31 characters (letters, numbers and underscore). First character must be a letter. Lower and upper cases are distinguished. The casesen command alters the case sensitivity.

» casesen You will find that a=A . The casesen command toggles the case sensitivity status. Every variable is treated as a matrix. A scalar variable is a 1 by 1 matrix. Data entry: If data entry or any other statement/operation is not terminated by semicolon, the result of the statement will always be displayed. Matlab can use several types of variables and the type declaration is automatic. Integer:

» k=2 » J=-4

Real: » s=3.6 » F2=-12.6e-5

Complex: » z=3+4*i » r=5*exp(i*pi/3)

i=sqrt(-1) is predefined, however, you may want to denote the unity imaginary vector by another variable. You are allowed to do so, e.g. simply type

» j=sqrt(-1) Vectors:

» x=[1, 2, 3] % row vector, elements are separated by comma or space » q=[4; 5; 6] % column vector, elements are separated by semicolon

transpose: » v=[4, 5, 6]’ % same as q

Remark: be careful when using the above transpose operation! For complex z values z’ results in complex conjugate:

» i’ 0 - 1.000i

Matrices: » A=[7, 8, 9; 5, 6, 7] % A is a 2x3 matrix, » MATRIX=[row1; row2; . . . ; rowN];

Special vectors and matrices:

» u=1:3; % generates v=[1 2 3] as a row vector, » u=start:stop » w=1:2:10; % generates w=[1 3 5 7 9], » w=start:increment:stop » E=eye(4)

E= 1 0 0 0 0 1 0 0

Page 5: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Introduction to Matlab .

5

0 0 1 0 0 0 0 1

» B=eye(3,4) B= 1 0 0 0 0 1 0 0 0 0 1 0

» C=zeros(2,4) C= 0 0 0 0 0 0 0 0

» D=ones(3,5) D= 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Variable values: Typing the name of a variable displays its value:

» A A= 7 8 9 5 6 7

» A(2, 3) ans =

7 The first index is the row number and the second index is the column number. The answer is stored in the ans variable. Changing one single value in v results in the printing of the entire vector v, unless printing is not suppressed by a semicolon:

» v(2)= -6 v= 4 -6 6 Subscripting: Colon (:) can be used to access multiple elements of a matrix. It can be used in several ways for accessing and setting matrix elements. Start index : end index - means a part of the matrix : - means all the elements in a row or in a column For vectors: v=[v(1) v(2) . . . v(N)] For matrices: M=[M(1,1)...M(1,m); M(2,1)...M(2,m); ... ; M(n,1)...M(n,m)] Assume B is an 8x8 matrix, then B(1:5,3) is a column vector like [B(1,3); B(2,3); B(3,3); B(4,3); B(5,3)] B(2:3,4:5) is a matrix like [B(2,4) B(2,5); B(3,4) B(3,5)] B(:,3) assigns all the elements of the third column of B B(2,:) assigns the second row of B B(1:3,:) assigns the first three rows of B.

» A(2,1:2) % second row , first and second elements » A(:,2) % all the elements in the second column

Workspace: The used variables are stored in a memory area called workspace. The workspace is displayed by the following commands:

» who » whos % displays the size of the variables

The size of the variables can be displayed by commands length and size.

Page 6: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Introduction to Matlab .

6

For vectors: » lng=length(v)

lng= 3 For matrices and vectors:

» [m,n]=size(A) m= 4 % number of rows n= 4 % number of columns The workspace can be saved, loaded and cleared:

» save % saves the workspace to the default matlab.mat file. » save filename.mat % saves the workspace to filename.mat file. » clear % clears the workspace, deletes all the variables. » load % loads the default matlab.mat file from the workspace. » load filename.mat % loads the filename.mat file from the workspace.

Arithmetic operations: Addition and subtraction:

» A=[1 2; 3 4]; » B=A’; » C=A+B;

C= 2 5 5 8

» D=A-B D= 0 -1 1 0

» x=[-1 0 2]’; » y=x-1 (Observe that all entries will be affected!)

y= -2 -1 1 Multiplication: Vector by scalar:

» 2*x ans= -2 0 4 Matrix by scalar:

» 3*A ans= 3 6 9 12 Inner (scalar) product:

» s=x’*y s= 4 » y’*x ans= 4 Outer product:

Page 7: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Introduction to Matlab .

7

» M=x*y’ M= 2 1 -1 0 0 0 -4 -2 2

» y*x’ ans= 2 0 -4 1 0 -2 -1 0 2 Matrix by vector:

» b=M*x b= -4 0 8 Division:

» C/2 For matrices: B/A corresponds to BA-1 A\B corresponds to A-1B Powers: A^p , where A is a square matrix and p is a real constant e.g. inverse of A : A^(-1) , or equivalently you can use inv(A) Manipulations on complex numbers:

» r r= 2.5000 + 4.3301i

» real(r) ans= 2.5000

» imag(r) ans= 4.3301 » abs(r) ans= 5

» angle(r) ans= 1.0472 To get the phase in degrees type

» 180/pi*angle(r) ans= 60.0000 Array operations in an element-by-element way: Array operations form an extremely important class of operations and they mean arithmetic operations in an element by element way. To indicate an array operation the operator should be proceeded by a period (.). Example:

» a=[2 4 6] » b=[5 3 1] » a.*b

ans= 10 12 6

Page 8: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Introduction to Matlab .

8

The matrix element operator can be used for different operations, e.g. for division and power: ./, .^ Elementary math functions: (use the on-line help for details and additional items) abs absolute value or magnitude of complex numbers sqrt square root real real part imag imaginary part conj comlplex conjugate round round to nearest integer fix round towards zero floor round towards -infinity ceil round towards +infinity sign signum function rem remainder sin sine cos cosine tan tangent asin arcsine acos arccosine atan arctangent atan2 four quadrant arctangent sinh hyperbolic sine cosh hyperbolic cosine tanh hyperbolic tangent exp exponential base e log natural logarithm log10 log base 10 bessel Bessel function rat rational approximation expm matrix exponential logm matrix logarithm sqrtm matrix square root. For example:

» g=sqrt(2)

Graphic output: The most basic graphic command is plot.

» plot(2,3) % plots the x=2, y=3 point Multiple points can be plotted by storing the coordinate values in vectors.

» x=[1,2,3] » y=[0,2,1] » plot(x,y) % notice that the points are connected with a line » plot(x,y,’*’) % only the points are plotted

More complex curves can also be displayed by the plot command. Example:

» t=0:0.05:4*pi; » y=sin(t); » plot(t,y) » title(‘Sine function’),xlabel(‘Time’),ylabel(‘sin(t)’),grid;

where title , xlabel , ylabel and grid are optional. Plotting multiple lines:

» y1=3*sin(2*t); » plot(t,y,’r’,t,y1,’b’); % r-red, b-blue

Page 9: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Introduction to Matlab .

9

Type and colour for plotting (optional): » plot(t,y,’@#’), where ‘@’ means line type as follows: - solid -- dashed : dotted . point + plus * star o circle x x-mark and ‘#’ means colour as follows: r red g green b blue w white y yellow. Polynomials: To define a polynomial, e.g. P(x)=4x4-6x3+9x2-5 simply introduce a vector containing the coefficients of the polynomial:

» v=[4 -6 9 0 -5] You may want to see the roots of the equation P(x)=0. MATLAB offers you the function roots to find the roots:

» p=roots(v) p =

0.6198 + 1.4337i 0.6198 - 1.4337i 0.8577 -0.5974 In case of having the p1, p2, ... , pn roots of an equation you can easily derive the related P(x)=(x- p1)(x- p2)...(x- pn) polynomial:

» v1=poly(p) v1 =

1.0000 -1.5000 2.2500 0 -1.2500 The poly command results in a polynomial with a leading coefficient of 1, therefore to get the original polynomial we have to multiply it by 4.

» v2=4*poly(p) v2 =

4.0000 -6.0000 9.0000 0 -5.0000 Consider now the following matrix:

» M=[3 5 ; 7 -1] The eigenvalues of M can be computed by command eig.

» e=eig(M) e =

7.2450 -5.2450 Taking the above values as roots of a polynomial into account the related polynomial can be calculated by

» poly(e) ans =

1 -2 -38 The above polynomial, i.e. x2-2x-38 is the so called characteristic polynomial of the M matrix and it is defined as det(xI-M) . The characteristic polynomial can be directly calculated from the M matrix:

» poly(M) ans =

1 -2 -38 As seen, sometimes commands can be called in different ways. MATLAB help of the particular command will provide all the possibilities how to call it.

Page 10: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Introduction to Matlab Control System Toolbox .

10

2. Introduction to Matlab Control System Toolbox Consider a single-input, single-output (SISO), continuous-time, linear, time invariant (LTI) system defined by its transfer function:

( )( )

( )Y S num

H sU s den

= =y(t)u(t)Y(s)U(s)

Using MATLAB calculate the step response of the system if 22( )2 4

H ss s

=+ +

. Recall that the step response is

defined as the output y(t) of the system applying unity step function input u(t)=1(t) assuming zero initial conditions. The transfer function can be defined in MATLAB by its numerator and denominator in a polynomial form:

2num = , 2 2 4den s s= + + . The polynomials are defined by their coefficients put in a vector by descending order of s :

» num=2 » den=[1 2 4]

The step response of the system can be displayed directly by the MATLAB step command:

» step(num,den); Note that equivalently, the compact form of

» step(2,[1 2 4]); is also applicable. Observe that the time scale is automatically selected by MATLAB. Expanding the above command by a left-hand side argument it is possible to store the values of the step response function in an array:

» [y,x,t]=step(num,den) % or simpler » y=step(num,den)

Note that no plot is generated in this case. If a semicolon (;) terminates the line the numerical values are not displayed either. The left-hand side variables are the output variables, y is the output of the step response, t gives the time points where it has been calculated, while x provides two so-called inner variables. The values stored in a variable can be displayed any time by typing the name of the variable:

» y The result is a column vector whose elements are the calculated samples of the step response function. The sampling time applied by MATLAB can be calculated from the time interval 0 6t≤ ≤ and the size of the vector:

» n=length(y) n = 109

» T=6/n T = 0.055

The calculated sampling time: T=6/109=0.055 sec. The help command shows further possible forms of the step command:

» help step It is seen then that there are other ways to use the step command. E.g. if the time interval 0 10t≤ ≤ and the sampling time 0.1T = are explicitly selected by

»t=0:0.1:10 the following form is applicable:

» y=step(num,den,t) The output vector can now be displayed with the plot command:

» plot(t,y); or adding the grid option to support the easy reading of the plot

» plot(t,y),grid; As far as the visualization is concerned, the plot command uses linear interpolation between the calculated samples. To avoid this interpolation the

» plot(t,y,'.'); command displays only the calculated samples. The maximum of the step response (more exactly the largest calculated sample) can be determined by

0 1 2 3 4 5 60

0.1

0.2

0.3

0.4

0.5

0.6

0.7Step response

Page 11: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Introduction to Matlab Control System Toolbox .

11

» ym=max(y)

ym = 0.5815 The steady state value of the step response is obtained as

» ys=dcgain(num,den) ys = 0.5

and the percentage overshoot of the output is » yovrsht=(ym-ys)/ys*100 yovrsht = 16.2971

Inverse Laplace Transforms: MATLAB supports a number of control-related analytical calculations. One example is to derive analytical solutions for inverse Laplace transforms. Calculate the inverse Laplace transform of Y(s) in analytical form:

2

23s +13s+16Y(s)=(s+2)(s+3)

The function has to be converted to a sum of components whose inverse Laplace transform are known, e.g. 1

1( )Lk k t−

→ 1 ptLr

res p

− −

+→

2

1

( )ptLr

rtes p

− −

+→

This partial fraction expansion conversion can be done by the residue command. Define the function in polynomial form:

» num=[3 13 16]; » den=poly([-3 -3 -2]);

The partial fraction expansion is obtained by » [r,p,k]=residue(num,den) r = 1.0000 -4.0000 2.0000 p = -3.0000 -3.0000 -2.0000 k = [] The partial fraction form in the Laplace domain

2 2(1) (2) (3) 1 4 2( )

(1) (3) 3 2( (2)) ( 3)r r rY s k

s p s p s ss p s= + + + = − +

− − + +− +

and in time domain: 3 3 2( ) 4 2t t ty t e te e− − −= − + , 0t ≥ Notice the form of the double poles. The time function can be calculated from the analytical expression:

» t=0:0.05:6; » y=r(1)*exp(p(1)*t)+r(2)*t.*exp(p(2)*t)+r(3)*exp(p(3)*t);

(The ’.*’ means element-by-element type multiplication). The analytical expression can be verified by numerical simulation. Then the two curves can be plotted in the same diagram.

» yi=impulse(num,den,t); » plot(t,[y,yi]),grid;

Page 12: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Introduction to Matlab Control System Toolbox .

12

LTI model structures (sys): In order to simplify the commands the Control System Toolbox can also use data-structures. There are three basic forms to describe linear time-invariant (LTI) systems in MATLAB:

• transfer function form: 1 2

1 2 1 01 2 2

1 2 1 0

.... 2( ).... 3 2

m mm

tf n nn n

s b s b s b s bH s

a s a s a s a s a s s

−−

−−

+ + + + += =

+ + + + + + +

• zero-pole-gain form: 1 2

1 2

( )( )...( ) 2( )( )( )...( ) ( 1)( 2)

mzpk

n

s z s z s zH s k

s p s p s p s s− − −

= =− − − + +

• state space model form: x = Ax + Buy = Cx + Du

[ ]3 1 1, , 0 1 , 0

2 0 0− −

= = =

A = B C D . .

Using the MATLAB commands tf, zpk and ss, the transfer function H(s) can be defined as an LTI data-structure:

» num=2 » den=[1, 3, 2] » H=tf(num,den) Transfer function: 2 ------------- s^2 + 3 s + 2

or directly » Htf=tf(2,[1, 3, 2])

The other models can be defined in a similar way: » Hzpk=zpk([],[-1, -2],2) Zero/pole/gain:

2 ----------- (s+1)(s+2) » A=[-3, -1; 2, 0]; B=[1; 0]; C=[0, 1]; D=0; » Hss=ss(A,B,C,D);

Conversions between a pair of the models are available as follows: » Hzpk1=zpk(Htf) » Hss1=ss(Htf) » Htf1=tf(Hss)

The models contain parameters. These parameters together with the data-structure can be listed by » get(Htf) » get(Hzpk) » get(Hss)

The parameters (properties) in an LTI structure can be accessed. The 'v' flag means that the result is in vector format: » [num1,den1]=tfdata(Htf,'v') num1 = 0 0 2 den1 = 1 3 2 » [z,p,k]=zpkdata(Hzpk,'v')

or they can be accessed directly » num2=Htf.num{1} num2 = 0 0 2

The term {1} has to be used since the transfer function can represent MIMO (multiple input-multiple output) systems, in general. Also, {1} identifies cell-array type. The cell-array is a matrix with matrices of variable size. For example

» ca={1, [1,2],[1,2,3]} ca = [1] [1x2 double] [1x3 double] » ca{2} ans = 1 2

Page 13: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Introduction to Matlab Control System Toolbox .

13

The other models can be accessed in a similar way: » Hzpk.k=2; Hzpk.z=[]; Hzpk.p=[-1, -2]; » Hzpk

k: 2 z: [] p: [-1 -2]

» Hss.a ans = -3 -1

2 0 . Symbolic data input can also be used if the s variable is defined

» s=tf('s') » H=1/((s+1)*(s+2))

You can apply arithmetic operators to LTI models. The defined operators are: +, - , / , \ , ' , inv, ^ . For example a resulting transfer function Hcl can be given by the following symbolic calculation:

» Hcl=H/(1+H) There is a hierarchy of the LTI structures: tf -> zpk -> ss. If in an operation different structures are used the result is stored in the highest hierarchy structure. For example the result of

» Htf*Hzpk is stored in zpk form. Time domain analysis: The Control System Toolbox contains several commands that provide basic tools for time domain analysis.

Define the system 22( )2 4

H ss s

=+ +

and a time horizon for the analysis:

» H=2/(s^2+2*s+4) » t=0:0.1:10;

• Step response: All the previously discussed versions of the step command can be used. Additionally, we have

» step(H); • Impulse response: The impulse response is the output of the system in case of u(t)= ( )tδ (Dirac impulse) input.

» impulse(H); » yi=impulse(H,t); » plot(t,yi)

• Nonzero initial condition: The system behavior can also be analyzed for nonzero initial conditions. Nonzero initial conditions can only be taken into account if state space models are used. Accordingly, to apply the initial command the system has to be transformed into state space representation.

» H=ss(H) » x0=[1, -2] » [y,t,x]=initial(H,x0); » plot(t,y),grid

Note that the above commands result in y as a column vector and x as a matrix having as many columns as dictated by the number of the state variables (2 in this case), and as many rows as dictated by the time instants (109 in this case). Just to check: » size(y)

ans = 109 1 » size(x)

ans = 109 2 The state trajectory can also be calculated and plotted. The first column of the x matrix contains the first state variable, while the second state variable will show up in the second column. » x1=x(:,1); x2=x(:,2); The state trajectory can then be plotted by » plot(x1,x2)

Frequency (rad/sec)

Pha

se (d

eg);

Mag

nitu

de (d

B)

Bode Diagrams

-40

-30

-20

-10

0From: U(1)

10-1 100 101-200

-150

-100

-50

0

To: Y

(1)

Page 14: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Introduction to Matlab Control System Toolbox .

14

• Output response to an arbitrary input: The output can also be calculated for any input signal. Calculate the system response, if the input is u(t)= 2*sin(3*t).

» usin=2*sin(3*t); » ysin=lsim(H,usin,t);

Plot both the input (red) and output (blue): » plot(t,usin,'r',t,ysin,'b'), grid;

Frequency domain analysis: The system behavior can also be analyzed in frequency domain. • Bode diagram of the system can be calculated by the bode command. There are several ways to use this command. The gain and phase shift of the system can be calculated at a fixed frequency point. For a given system calculate the gain and the phase shift at the frequency of w=5:

» w=5; » [gain,phase]=bode(H,w);

The calculations can be repeated for a selected frequency range (logarithmic scale is used for better visualization). A logarithmic frequency vector can be generated by the logspace command.

» w=logspace(-1,1,200); This creates 200 logarithmically equidistant frequency points between 10-1=0.1 and 101=10.

» [gain,phase]=bode(H,w); Just to plot (not to calculate and store as above) the gain and phase functions: » bode(H,w); The Bode diagram can also be displayed directly. In this case the MATLAB automatically calculates a frequency vector based on the system dynamics:

» bode(H),grid; • Nyquist diagram of the system can similarly be generated, except that the transfer function is displayed on the

complex plain: » nyquist(H);

• Margin command is an important tool to check the stability margins (GainMargin, PhaseMargin) of a system. » margin(H);

• Zeros, poles: The rootsof the transfer function are the poles of the system. This is how to find them:

» [num,den]=tfdata(H,'v'); » poles=roots(den);

The system zeros are the roots of the numerator of the transfer function:

» zeros=roots(num); The zeros and poles can be immediately gained from the zpk model:

» [z,p,k]=zpkdata(H,'v'); The zeros and poles can also be plotted on the complex plain by the pzmap command:

» subplot(111); » pzmap(H);

The damp command lists all the poles and (in case of complex pole-pairs) the natural frequencies and the damping factors:

» damp(H); The DC (zero frequency) gain of the system can also be calculated:

» K=dcgain(H); LTI Viewer: A linear system can be analyzed in details by the LTI Viewer. The LTI Viewer is a graphical user interface for analyzing the system response in time and frequency domain. The systems and the curves can be manipulated from menus or by the right mouse button:

» ltiview % or

Real Axis

Imag

inar

y A

xis

Nyquist Diagrams

-1 -0.5 0 0.5-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6From: U(1)

To: Y

(1)

Page 15: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Introduction to Matlab Control System Toolbox .

15

» ltiview('bode',H); Simulink: SIMULINK is a graphical software package supporting block-oriented system analysis. SIMULINK has two phases, model definition and model analysis. First a model has to be defined than it can be analyzed by running a simulation. SIMULINK represents dynamic systems with block diagrams. Defining a system is much like drawing a block diagram. Instead of drawing the individual blocks, blocks are copied from libraries of blocks. The standard block library is organized into several subsystems, grouping blocks according to their behavior. Blocks can be copied from these or any other libraries or models into your model. SIMULINK block library can be opened from the MATLAB command window by entering command “ simulink ”. This command displays a new window containing icons for the subsystem blocks. Constructing your model select New from the File menu of SIMULINK to open a new empty window in which you can build your model. Open one or more libraries and drag some blocks into your active window. To build your model you can drag the appropriate blocks by the left mouse button from their libraries to your file to the required position where you release the button. To connect two blocks use the left mouse button to click on either the output or input port of one block, drag to the other block's input or output port to draw a connecting line, and then release the button. By clicking on the block with the right button you can duplicate it. The blocks can be increased, decreased, rotated. Open the blocks by double clicking to change some of their internal parameters. Save the system by selecting Save from the File menu. Run a simulation by selecting Start from the Simulation menu. Simulation parameters can also be changed. You can monitor the behavior of your system with a Scope or you can use the To Workspace block to send data to the MATLAB workspace and perform MATLAB functions (e.g. plot) on the results. Parameters of the blocks can be referred also by variables defined in MATLAB. Simulation of SIMULINK models involves the numerical integration of sets of ordinary differential equations. SIMULINK provides a number of integration algorithms for the simulation of such equations. The appropriate choice of method and the careful selection of simulation parameters are important considerations for obtaining accurate results. To get yourself familiarized with the flavour of the the options offered by SIMULINK consider the following example:

Create a new file and copy various blocks. The block parameters should then be changed to the required value. Change the Simulation–>Parameters–>Stop time parameter to 50 from the menu. SIMULINK uses the variables defined in the MATLAB workspace. H(s): Control System Toolbox –>LTI system : H Difference: Simulink–>Math–>Sum: +- Dead time, delay: Simulink–>Continuous–>Transport Delay: 1 Gain: Simulink–>Math–>Gain: 1 Step input: Simulink–>Sources–>Step Scope: Simulink–>Sinks–>Scope Clock: Simulink–>Sources–>ClockOutput, time: Simulink–>Sinks–>To Workspace: y,t

The result can be analyzed directly by the Scope block or it can be send back to the MATLAB workspace by the To Workspace output block . The results there can be further processed and displayed graphically. Change the Gain parameter between 0.5 and 2. Determine the parameter value for which the system produces constant oscillation.

t

timey

output

TransportDelay

Step Input

Scope1

H

LTI SystemPs

1.5

Gain

Clock

Page 16: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

The Frequency Function .

16

3. The Frequency Function A basic property of a stable linear system is that for sinusoidal input it responds with a sinusoidal signal of the same frequency in steady (quasi-stationary) state. Applying the input signal

u t A tu u( ) sin( )= +ω ϕ , t ≥ 0 The output signal is

( ) ( ) ( )steady state transienty t y t y t−= + In steady state:

( ) sin( )steady state y yy t A tω ϕ− = +

( )H s( ) sin( )u uu t A tω ϕ= + ( ) sin( )y y transienty t A t yω ϕ= + +

The frequency function defines the amplitude ratio Ay/Au and the phase shift (ϕy-ϕu) versus the frequency. Utilising the amplitude ratio and the phase shift within one single function the frequency function has been derived as a complex function. It can be proven that formally the frequency function can be obtained from the transfer function by substituting s=jω . So the frequency function is

H j H s M es jj( ) ( ) ( ) ( )ω ωωϕ ω= =

=

where M(ω) is the amplitude-frequency function or magnitude function, and ϕ(ω) is the phase-frequency or phase function:

)()(

)()(ωω

ωωu

y

AA

jHM == { } )()()(arg)( ωϕωϕωωϕ uyjH −==

The frequency function can be depicted in a given frequency range by plotting M(ω) and ϕ(ω) functions versus the frequency. The frequency scale is logarithmic. This technique exhibits the Bode diagram. A second possibility is to plot the points of the frequency function calculated for various ω values on the complex plain, while ω changes from zero to infinity. Connecting these points results the contour of the so-called Nyquist diagram. Example: The transfer function of a linear system is

210( )2 10

H ss s

=+ +

Lets calculate the output of the system, if the input is u(t)= 2*sin(3*t). » num=10; » den=[1, 2, 10]; » H=tf(num,den); » t=0:0.05:10; » u=2*sin(3*t); » yl=lsim(H,u,t);

Plot both the input (red) and output (blue) in the same diagram: » plot(t,u,'r',t,yl,'b'), grid;

In steady state the amplitude and the phase of the output signal is changing with the frequency applied. This change can be calculated from the frequency function ( )H s jω= . In MATLAB the bode command calculates these variables for a range of frequencies or just at a given frequency, say 3ω = :

» [gain,phase]=bode(H,3); Investigate the system behavior for different frequencies: u(t)= sin(ω t), 1 2 3 41, 2, 5, 10ω ω ω ω= = = = .

» w1=1; w2=2; w3=5; w4=10; » u1=sin(w1*t); u2=sin(w2*t); u3=sin(w3*t); u4=sin(w4*t); » y1=lsim(H,u1,t); y2=lsim(H,u2,t); y3=lsim(H,u3,t); y4=lsim(H,u4,t); » plot(t,y1,'r',t,y2,'g',t,y3,'b',t,y4,'m'), grid;

Calculate the gain and phase values for the different frequencies.

Page 17: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

The Frequency Function .

17

» [gain1,phase1]=bode(H,w1); » [gain2,phase2]=bode(H,w2); » [gain3,phase3]=bode(H,w3); » [gain4,phase4]=bode(H,w4);

For comparison, create a table with the above gain and phase values. The gain and phase values can be displayed simpler if vectors are used. Create a linear frequency vector.

» w=1:0.1:10; » [gain,phase]=bode(num,den,w);

If both the amplitude and the phase diagrams are needed, the subplot command sets up the figure window for several simultaneous graphs. (2 x 1 graph and first window is selected by 211)

» subplot(211), plot(w,gain) » subplot(212), plot(w,phase)

This is the Bode diagram of the system. » subplot(111) % setting again one figure window

The same data can be also displayed on the complex plain. That is the Nyquist diagram.

» clf % clears the figure window » re=real(gain.*exp(j*phase*pi/180)); » im=imag(gain.*exp(j*phase*pi/180)); » plot(re,im)

This can be calculated directly by the nyquist command. » [re,im]=nyquist(num,den,w) » plot(re,im)

In practice, you may want to visualize or to calculate the frequency function. Visualization: The bode command without output argument displays the curve immediately.

» clf % clears the figure window » bode(H),grid

Observe that logarithmic scaling is used for both the frequency and the magnitude function. Similarly, the Nyquist curve can be displayed:

» nyquist(H) Calculation: The magnitude and the phase values can be calculated directly. For direct calculation the transfer function (num,den) format should be used, since the LTI structure command produces a 3-dimensional array.

» [gain,phase,w]=bode(num,den) Display the result in a log-log diagram. The MATLAB uses the loglog command to do this. This command is the same as plot except it uses logarithmic scale for both the x and y axis.

» loglog(w,gain),grid If both the amplitude and the phase diagrams are needed, use again subplot commands.

» subplot(211) » loglog(w,gain) » subplot(212) » semilogx(w,phase)

The logarithmic frequency vector can be generated directly by the logspace command. » w=logspace(-2,2,100)

This creates 100 logarithmically equidistant frequency points between 10-2=0.01 and 102=100. With this the Bode diagram can be calculated again.

» [gain,phase]=bode(num,den,w) » subplot(111) » loglog(w,gain)

Notice that this time the frequency range has been changed. Exercise 1: The system transfer function is: H(s)=10/(s^2+2s+5) The input is: u(t)=A*sin(2t), t ≥ 0 The output in steady-state is: y(t)=5*sin(2t+phase)

Page 18: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

The Frequency Function .

18

Calculate the A and phase parameters (use the MATLAB bode command) The shape of the Nyquist diagram is characteristic of the system. Analysing it one can characterize important properties of the system. The Bode diagram is advantageous when multiplying two transfer functions: because of the logarithmic scale the Bode diagrams are just added. In most cases approximate Bode diagrams, given by asymptotes of the magnitude curve provide a good approximation of the frequency characteristics. By sketching these approximate curves a quick evaluation of the system behaviour can be given. The next example illustrates that in a wide frequency range the approximate Bode amplitude diagram is really close to the accurate one. Bode and Approximated Bode Plots: Compute the approximated and exact Bode plots for

2

10( )(1 )(1 10 )

H ss s s

=+ +

Observe that H(s) is given in time-constant form. The system in zero-pole-gain form is

2

1 1 1( ) 0.1(0.1 ) 1

H ss s s

=+ +

» s=zpk(‘s’) » H=10/(s*(1+s)*(1+10*s)*(1+10*s)) » [num,den]=tfdata(H,’v’) » p=roots(den)

The poles of the system are 0, - 0.1, - 0.1, -1. Also, these are the break frequencies of the Bode plot. Introduce appropriate scaling for the following frequency ranges: w1:0.02-0.1; w2:0.1-1; w3:1-4

» w1= logspace (log10(0.02),-1,10); » w2=logspace(-1,0,10); » w3=logspace(0,log10(4),10);

The full frequency range: » w= [w1 w2 w3];

1. Calculate the approximated amplitude values for 1s

» gain1=1./w;

2. Calculate the approximated amplitude values for 2

1(0.1 )s+

. Below the break frequency (low frequency

approximation) the term is approximated by constant value 2

10.1

. Above the break frequency (high frequency

approximation) it is approximated by 2

1s

» w2L=w1; w2H=[w2 w3]; » gain2L=1./((0.1+0*w2L).^2); gain2H=1./(w2H.^2); gain2=[gain2L gain2H];

3. Calculate the approximated amplitude values for 1

1 s+ similarly.

» w3L=[w1 w2]; w3H=w3; » gain3L=0*w3L+1; gain3H=1./w3H; » gain3=[gain3L gain3H];

Calculate the gain value of the full system. » gainappr=0.1*gain1.*gain2.*gain3;

Calculate the exact bode amplitude values. » gainexact=bode(num,den,w);

Page 19: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

The Frequency Function .

19

10-2

10-1

100

101

10-4

10-2

100

102

104

Plot the two curves to check the approximation: » loglog(w, gainexact,’b’,w,gainappr,’r’),grid

It is seen that the approximation is acceptable, the biggest deviation is obtained at frequency 0.1ω = , which is the breakpoint of the double pole. Note that the deviation can be much larger in case of lightly damped poles ( 0.3ζ < ).

Page 20: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Elements of a Linear System .

20

4. Elements of a Linear System In general, a linear system can be written in the

2 20 0

1 1

2 20 0

1 1

(1 ) (1 2 )( )

(1 ) (1 2 )

D

c d

j j j j

fi e

j j j j

sTs s s

kH s es sT T s s T

τ ζ τ τ

ζ

−+ + +

=+ + +

∏ ∏

∏ ∏

form, where k is the gain, i is the number of integrators, DT is the dead time (time-delay). Note that the above form is called as time-constant form, contrary to the zero-pole form. In the sequel a set of fundamental system elements will be derived applying particular parameterization of the time-constant form. Specifically, the following elements will be discussed: proportional, integrating, derivative, first order lag, second order lag (or second order oscillating element), dead time (or time-delay). Step responses and frequency responses will be analyzed. 1. Gain: ( )H s k= In terms of the frequency function the gain of the system is k and the phase is zero for all frequencies.

2. Integrator: ( ) kH ss

=

Investigate the behavior of a simple integrator ks

for 1k = and 5k = , respectively.

1 21 5( ) , ( )H s H ss s

= =

» clear % just to clear workspace (deletes all the previously defined variables) » s=zpk(‘s’) % s is defined as a symbolic variable in zpk form » H1=1/s » H2=5/s

Step response: » figure(1), step(H1,’r’,H2,’g’), grid Bode diagram: » figure(2), bode(H1,’r’,H2,’g’), grid Nyquist diagram: » figure(3), nyquist (H1,’r’,H2,’g’),grid The steady state values are: » y1inf=dcgain(H1) » y2inf=dcgain(H2) It is seen that the DC (zero frequency) gain of an integrator is infinitely large (this is why it is typically used in closed-loop control systems), while its phase is -90º for all frequencies. As far as the time-domain behaviour of an integrator is concerned, note that the output of an integrator remains constant if its input is zero (zero detection property).

Page 21: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Elements of a Linear System .

21

3. Proportional element and lag: ( )1

kH sTs

=+

Examine the Bode and Nyquist diagrams and the step response of the following first order lag term:

12( )

1 1 10kH sTs s

= =+ +

Define the system then display its step response. Using the symbolic variable s as introduced earlier the transfer function gets created in zpk form, too:

» H1=2/(1+10*s) or equivalently, a transfer function form can be obtained by » H1=tf(2,[10, 1]) The step response

» t=0:0.1:50; » y1=step(H1,t); » plot(t,y1),grid or simply » step(H1) Now discuss the meaning of k and T. The steady-state value, ( )y t →∞ of the system can be calculated by the final value theorem

0 0( ) lim ( ) lim ( ) ( )

s sy t sY s sH s U s

→ →→∞ = =

where ( )U s is the Laplace transform of the input applied. Assuming a unit step input the above relation simplifies to

0 0 0

1( ) lim ( ) ( ) lim ( ) lim ( )s s s

y t sH s U s sH s H ss→ → →

→∞ = = =

Specifically, for 1( ) ( )H s H s=

0

2( ) 21 10 s

y ts =

→∞ = =+

By MATLAB: » y1inf=dcgain(H1) To see the impact of the time constant T on the transient behaviour repeat the » y1=step(2,[T 1],t); MATLAB command for various T values. Systems also can be described by the zero-pole form:

12 0.2H (s)=

10(0.1 ) 0.1pk

s p s s= =

− + +.

where 1 , p

kp kT T

= − =

This form is more descriptive in the frequency domain. The absolute value of the pole can be interpreted as the corner frequency of the element. Also, according to

0( ) lim ( )

sy t H s

→→∞ =

derived earlier for the step response you may conclude that the magnitude function value at low frequency is identical to the value of the steady-state step response. The transfer function ( )H s , as well as the and the frequency function ( )H jω are both complex functions. The Bode diagram exhibits this complex function by the absolute value (magnitude function) and phase angle (phase function). The Nyquist diagram is an alternative technique to visualize the complex frequency function on the complex plane.

Page 22: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Elements of a Linear System .

22

» bode(H1); » nyquist(H1); Similarly, investigate the following systems:

1 2 32 2 2; ;

1 10 (1 10 )(1 2 ) (1 10 )(1 2 )(1 0.1 )H H H

s s s s s s= = =

+ + + + + +

Display the step response, Bode diagram and Nyquist diagrams of the three systems. (1-red, 2-green, 3- blue)

» H2=2/((1+10*s)*(1+2*s)) » H3=2/((1+10*s)*(1+2*s)*(1+0.1*s))

Step responses: » figure(1), step(H1,’r’,H2,’g’,H3,’b’),grid

Bode diagrams: » figure(2), bode(H1,’r’,H2,’g’,H3,’b’), grid

Nyquist diagrams: » figure(3), nyquist(H1,’r’,H2,’g’,H3,’b’),grid

Note that it is possible to magnify a portion of the curves by the zoom menu command of the figure window.

4. Integrator and lag: ( )(1 )

kH ss Ts

=+

1 2 32 2 2( ) , ( ) ,

(1 10 ) (1 10 )(1 2 )H s H s H

s s s s s s= = =

+ + +

» H1=2/s » H2=2/(s*(1+10*s)) » H3=2/(s*(1+10*s)*(1+2*s))

Step responses: » figure(1), step(H1,’r’,H2,’g’,H3,’b’),grid

Bode diagrams: » figure(2), bode(H1,’r’,H2,’g’,H3,’b’),grid,

Nyquist diagrams: » figure(3), nyquist (H1,’r’,H2,’g’,H3,’b’),grid

5. Second order element: 2 20 0

1( )2 1

H ss T T sζ

=+ +

Investigate the following system:

2 2 20 0

1 1( )9 2 1 2 1

H ss s s T T sζ

= =+ + + +

where 00

1T

ω = is the natural frequency and ζ is the damping factor of the system ( 00

1 3Tω

= = , ζ =1/3).

» num=1; » den=[9, 2, 1] » H=tf(num,den) Calculate the poles of the system. » roots(den) or by » damp(H)

The two poles are complex conjugates and can be given as 1 2, p a jb p a jb= + = −

The tv overshoot of the system is calculated by

Page 23: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Elements of a Linear System .

23

2 2 20 , aa b

bω ζ= + = − ,

21t

abv e eπ

ζπζ −

−−= =

The oscillation frequency is 2

0 1p bω ω ς= = − and the time of the first maximum (peak time) is

pp

T πω

= .

» zeta=1/3 » vt=exp(-zeta *pi/sqrt(1- zeta * zeta)) The step response: » [y,t]=step(H); » plot(t,y), grid Calculate the maximum value: » ym=max(y) The steady state value » ys=dcgain(H) The overshoot again » yo=(ym-ys)/ys Examine the Bode and Nyquist diagrams and the step response of the system for various damping factors ζ =0.3, 0.7, 1 .

» zeta1=0.3, zeta2=0.7, zeta3=1 » T0=3 » H1=1/(s*s*T0*T0+2*zeta1*T0*s+1) » H2=1/(s*s*T0*T0+2*zeta2*T0*s+1) » H3=1/(s*s*T0*T0+2*zeta3*T0*s+1)

Step response: » figure(1), step(H1,’r’,H2,’g’,H3,’b’),grid

Bode diagram: » figure(2), bode(H1,’r’,H2,’g’,H3,’b’),grid

Nyquist diagram: » figure(3), nyquist(H1,’r’,H2,’g’,H3,’b’),grid

The zero-pole map » pzmap(H1) » pzmap(H2) » pzmap(H3)

It is seen that for damping factor 0.3 the step response is the most oscillating, the maximum amplification in the Bode amplitude diagram is the highest, and the Nyquist diagram crossing the imaginary axis gives the biggest magnitude for this case. The imaginary value of the complex conjugate poles providing the frequency of oscillation in the time response is also the highest. High amplification in the Bode amplitude diagram indicates high overshoot in the step response. Damping factor 0.7 provides a slight overshoot. Control systems can be designed for similar behaviour. 6. Derivative element: ( ) dH s sT=

1 2 3 42 2 2( ) 2 , ( ) , ,

1 10 (1 10 )(1 2 ) (1 10 )(1 2 )(1 0.1 )ds s sH s sT s H s H H

s s s s s s= = = = =

+ + + + + +

Investigate again the step response, the Bode and the Nyquist diagram of the system.

Page 24: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Elements of a Linear System .

24

» H1=2*s » H2=(2*s)/(1+10*s) » H3=(2*s )/((1+10*s)*(1+2*s)) » H4=(2*s )/((1+10*s)*(1+2*s)*(1+2*s))

Step response of 1( )H s : » figure(1), step(H1) The MATLAB can not evaluate this system, since the transfer function is not proper, the degree of the numerator is higher than the degree of the denominator. (The answer should be a Dirac function). Step responses:

» figure(1), step(H2,’r’,H3,’g’,H4,’b’),grid Bode diagrams:

» figure(2), bode(H2,’r’,H3,’g’,H4,’b’),grid, Nyquist diagrams:

» figure(3), nyquist(H2,’r’,H3,’g’,H4,’b’),grid

7. Zeros: 1 2( )( )...( )( )( )

Mk s z s z s zH sD s

− − −=

Analyse the effect of zeros to the step and frequency responses in case of the following transfer function:

( )( )

1( )

1 1 10

sH s

s s

τ+=

+ +

τ , the time constant in the numerator (the zero is 1/τ− ) changes between values –4 and 4. In case of a positive zero the transfer function describes a so-called non-minimum-phase element.

» s=tf('s') » tau=[-4 -2 0 2 4]; » D=50*s*s+11*s+1;

» for i=1:5, » H(i)=(s*tau(i)+1)/D

» end » t=0:0.1:60; » Y1=step(H(1),t); Y2=step(H(2),t); Y3=step(H(3),t); » Y4=step(H(4),t); Y5=step(H(5),t); » plot(t,[Y1,Y2,Y3,Y4,Y5]),grid,shg Note that non-minimum-phase systems may show unexpected behaviour, e.g. the step response with one zero on the right half plane takes an initial slope not in the direction of the steady state value. A positive zero, however, accelerates the system. Bode diagrams:

» figure(1),bode(H(1),’r’,H(2),’g’,H(3),’k’,H(4),’y’,H(5),’b’),grid Nyquist diagrams: » figure(2),nyquist(H(1),’r’,H(2),’g’,H(3),’k’,H(4),’y’,H(5),’b’),grid Evaluate the effect of zeros in the Bode and Nyquist diagrams! 8. Delay (dead time): ( ) DsTH s e−= The description of the delay term in the time and the Laplace operator domain:

( ) ( )Dy t y t T→ −

( ) ( ) DsTY s Y s e−→ The transfer function of a system with delay:

( ) ( ) DsTDH s H s e−=

In the frequency domain:

{ }1, argD Dj T j TDe e Tω ω ω− −= = −

Page 25: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Elements of a Linear System .

25

gain: DH H=

phase: arg( ) arg( )D DH H Tω= −

Investigate the frequency functions of the following transfer functions:

11( )

1 10H s

s=

+, 2

21( )

(1 10 )sH s e

s−=

+

The gain value and the phase of the delay term:

1 2H H= , gain2=gain1

2 1arg( ) arg( ) DH H Tω= − , phase2= phase1 DTω−

» Td=2 » num1=1 » den1=[10, 1]

Now calculating the Bode diagram the num, den format should be used. Create a logarithmic frequency vector first. » w=logspace(-2,0,100) » [gain1,phase1]=bode(num1,den1,w)

» delay=180/pi*Td*w' % the phase angle caused by the dead time ( DTω− ) is to be converted from radians to degrees) The magnitude and the phase with the delay:

» gain2=gain1 » phase2=phase1-delay » subplot(211),loglog(w, gain1,’r’,w, gain2,’b’),grid; » subplot(212),semilogx(w, phase1,’r’,w, phase2,’b’),grid

The linearity of the phase curve can be seen well if the linear plot command is used instead of semilogx. » figure(2),subplot(111),plot(w, phase1,’r’,w, phase2,’b’),grid

Display the Nyquist curve: Calculate the complex values first.

» h1= gain1.*exp(j*phase1*pi/180) » h2= gain2.*exp(j*phase2*pi/180) » plot(real(h1),imag(h1),’r’, real(h2),imag(h2),’b’)

The high frequency behaviour can be investigated by selecting a higher frequency range with the logspace command. The time domain behaviour can be investigated better in SIMULINK, because the time-delay is offered as a single building block. Nevertheless the transfer function of the dead time can be approximated by a non-minimum-phase rational fraction where the first elements of its Taylor expansion are the same as of the exponential transfer function characterizing the dead time. These rational fractions are called Pade functions. The higher is the degree of the Pade function, the better is the approximation of the dead time element. It has to be mentioned that with this approximation the step response starts with +1 or –1 instead of zero. In Matlab the pade command calculates the approximation. Demonstrating the use of Pade approximation use 5-th order approximation.

( ) DsTdeadtimeH s e−=

» H1=tf(num1,den1) » [numpade,denpade]=pade(Td,5) » Hdeadtime=tf(numpade,denpade) » H2=H1* Hdeadtime

Step response: » figure(1), step(H1,’r’,H2,’g’),grid

Bode diagram: » figure(2), bode(H1,’r’,H2,’g’),grid

Page 26: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Elements of a Linear System .

26

Nyquist diagram: » figure(3), nyquist(H1,’r’,H2,’g’),grid

Exercise: Analyse how good is the Pade approximation building up a SIMULINK diagram for the first order lag element above with a transport delay as a block provided by SIMULINK, and considering the dead time approximated by the Pade rational fraction.

9. Double Integrator: 2( ) kH ss

=

1 2 3 42 2 2 2

4 4 4 4( ) , ( ) , ,

(1 10 ) (1 10 )(1 2 ) (1 10 )(1 2 )(1 0.1 )s H s H H

s s s s s s s s s sH = = = =

+ + + + + +

Exercise: Calculate the step responses, the Nyquist and Bode diagrams of the given elements. Summary: Step responses in steady state ( t →∞ ) and amplitude response of the frequency function for 0ω → behave in a similar way. Nyquist diagrams of proportional elements at 0ω = start from a point of the positive real axis, which characterizes the gain of the element. The Nyquist diagram of an integrating element starts from the infinity direction of the negative imaginary axis. That of the double integrating elements starts from infinity of the negative real axis. Nyquist diagrams of derivative elements are initiated from the zero point of the complex plain and start in the direction of the positive imaginary axis. In case of transfer function containing only lags (no zeros) the Nyquist diagram covers as many quarters in the complex plain as many is the number of the time lags. Zeros deteriorate the monotonic change of the phase angle. Bode amplitude diagram of a proportional element starts parallel to the frequency axis with zero phase angle, Bode amplitude diagram of a system containing one integrator starts with 20 /dB decade− slope with

090− phase angle, while that of a system with double integrators starts with 40 /dB decade− slope with 0180− phase angle. Time lags break down the slope of the Bode amplitude diagram, while zeros break the slope up.

Page 27: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Feedback and Closed Loop .

27

5. Feedback and Closed Loop Feedback is the most important structure in control systems. The overall transfer function from the reference input (set point) to the process output (also called resulting transfer function) can be calculated by the well known relationships. Also, the related frequency function is immediately obtained by substituting s=jω. MATLAB supports calculation of the various transfer functions in the closed-loop: series connection, parallel connection or feedback. Let us summarize the most important commands. C - controller, P - plant, F – feedback element

( )C se(t) y(t)u(t)r(t)

- Y(s)U(s)E(s)( )P s

( )F s

R(s)

The following transfer functions can be calculated: Loop transfer function

( ) ( ) ( ) ( )CL s s P s F s= Closed-loop transfer functions (error, control input, output, respectively)

( ) 1( )

( ) 1 ( )e

E sW s

R s L s= =

+,

( ) ( )( )

( ) 1 ( )u

U s C sW s

R s L s= =

+,

( ) ( ) ( )( )

( ) 1 ( )Y s C s P s

T sR s L s

= =+

The forward path transfer function is E=CP: » E=series(C,P); or » E=C*P;

The loop transfer function is L=CPF=EF » L=series(E,F); or » L=C*P*F;

The output closed-loop transfer function: » T=feedback(E,F,-1);

If the feedback is unity (F=1), the closed-loop transfer function can be calculated by the cloop command: » T=cloop(E,-1);

The closed-loop transfer function can be calculated directly with the LTI structures: » T=C*P/(1+C*P*F)

The minreal comand cancels the common zero-pole pairs. » T=minreal(T)

For the cancellation a tolerance can also be specified. The default value for the tolerance is is sqrt(eps)=1.4901e-008. » T=minreal(T,0.001)

In this case the zero-pole pair is cancelled if the difference is less than 0.001. The frequency functions are then calculated by the bode or nyquist commands. The frequency function: Compare the frequency functions of the open-loop and closed-loop systems. Examine the step response of the closed- loop and find out how it is related to the closed-loop frequency function. Exercise1. The open loop transfer function is

A unity negative feedback is applied. The closed-loop transfer function is 1

( )(1 )

KL ss sT

=+

Page 28: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Feedback and Closed Loop .

28

22 11

1( ) 11

KT s Ts T s K s sK K

= =+ + + +

It is a second order term. The general form of a second order element is: 2 20 0

11 2 T s T sς+ +

Matching the coefficients suggests

01

1

1 ,

2T

TK KT

ς= =

Show the open-loop and closed-loop Bode amplitude diagrams for T1=1 and K=0.1 and K= 4 in one figure. Calculate the significant points of the open loop frequency function.

» s=tf('s') » T1=1 » K1=0.1 » K2=4 » L1=K1/(s*(s+1)) » L2=K2/(s*(s+1))

The output closed-loop transfer function can be calculated by

( )num

sden

L = , ( )( )

1 ( )num

snum den

L sTL s

=+

=+

» T1=L1/(1+L1) » T1=minreal(T1) %cancels the identical zero-pole pairs

or » T1=feedback(L1,1) » T2=feedback(L2,1)

Calculate the open-loop and closed-loop frequency functions. » figure(1) » step(T1,'r',T2,'y') » figure(2) » bode(L1,'b',L2,'c',T1,'r',T2,'y')

With unity feedback the amplitude-frequency function of the closed-loop in the low frequency domain is approximately one, while in the high frequency domain it runs close to the open loop amplitude function. For large values of K at the cut-off frequency the amplitude of the closed-loop can be high, indicating high overshoot in the unit step response. It is seen that the higher the closed-loop amplification is the higher is the overshoot in the step response. Let us determine the damping factor of the closed-loop.

» damp(T1) Eigenvalue Damping Freq. (rad/s) -1.13e-001 1.00e+000 1.13e-001 -8.87e-001 1.00e+000 8.87e-001

» damp(T2) Eigenvalue Damping Freq. (rad/s) -5.00e-001 + 1.94e+000i 2.50e-001 2.00e+000 -5.00e-001 - 1.94e+000i 2.50e-001 2.00e+00

or with variables » [w01,zeta1]=damp(T1) » [w02,zeta2]=damp(T2)

The different gains result significantly different behaviour. In the first case the poles are real variables, in the second example the poles are complex numbers (second order oscillating element).

Page 29: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Feedback and Closed Loop .

29

Exercise2. Investigate the open-loop and closed-loop behaviour of the system

10( )(1 )(1 5 ) (1 )(1 5 )

kL ss s s s

= =+ + + +

» s=zpk('s') » L=10/((1+s)*(5*s+1)) » T=feedback(L,1)

Calculate the steady-state value of the step responses of the open-loop and closed-loop system.

The final value theorem for step response is 1( ) 1( ), ( )r t t R ss

= =

0 0 0

1( ) lim ( ) ( ) lim ( ) lim ( )s s s

y t sR s H s s H s H ss→ → →

→∞ = = =

The steady-state value for the open-loop and closed-loop step responses is

0( ) lim ( ) 10open s

y t L s k→

→∞ = = =

0

( ) 10( ) lim ( )1 ( ) 1 1 10

closedclosed s

closed

y t ky t T sy t k→

→∞→∞ = = = =

+ →∞ + +

The steady-state error: 1 1( ) 1 ( )

1 11closede t y tk

→∞ = − →∞ = =+

Display the step response of the open- and closed-loop:

» step(L,’r’,T,’b’) The steady state values can be read from the curves or can be calculated by

» yos=dcgain(L) » ycs=dcgain(T)

Display the open-loop and closed-loop Bode diagrams.

» bode(L,’r’,T,’b’)

Calculate the steady state error for k=1, 20, 100.

Page 30: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Stability .

30

6. Stability Consider the following typical closed-loop control configuration with unity feedback gain.

( )L se(t) y(t)u(t)r(t)

- Y(s)U(s)E(s)( )T s

y(t)r(t)Y(s)≡

where ( )L s denotes the loop (or open-loop) transfer function. The closed-loop transfer function is calculated by

( )( )1 ( )

L sT sL s

=+

The stability of closed-loop systems: The system is stable (in BIBO=Bounded Input Bounded Output sense) if it produces bounded output for any bounded input. 1. Stability analysis based on the location of the closed loop poles: The stability of the closed-loop system can easily be determined by analyzing the location of the poles of the closed-loop transfer function. A system is stable if the real parts of the closed-loop poles are negative, i.e. all the poles are in the left-hand complex s-plane. Exercise 1. The closed-loop (overall) transfer function of a system is

5 4 3 2

5( )3 4 10 5 10

sT ss s s s s

+=

− + + + −.

Is the system stable?

» num=[1, 5] » den=[1, -3, 4, 10, 5, -10] » T=tf(num,den) » poles=roots(den) poles = 2.1150 + 2.1652i 2.1150 - 2.1652i -0.9824 + 0.7214i -0.9824 - 0.7214i 0.7348 Note that the same result is obtained using the LTI structure » [z,p,k]=zpkdata(T,'v') The system is unstable, since there are poles with positive real part. Plot the pole locations in the complex s-plane: » pzmap(T) Again, the system is unstable, since there are poles on the right-hand side of the complex plane.

2. Apply the Nyquist stability criterion: The stability of a feedback system can also be determined by the behaviour of the open-loop: a. The open-loop does not have unstable poles; all poles are in the left-hand s-plane. The closed-loop system is stable if the Nyquist curve of the open-loop system does not encircle the (–1+0j) point. b. The open-loop does have unstable poles: The closed-loop system is stable if for the Nyquist curve of the open-loop system, the number of counterclockwise encirclements of the (–1+0j) point is equal to the number of unstable open-loop poles.

Page 31: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Stability .

31

Exercise 2. The loop transfer function of a system is

10( )(1 10 )(1 )

L ss s

=+ +

.

The system is in a negative unity feedback control loop. Determine the stability of the closed-loop based on the Nyquist criterion. » s=tf('s') » L=10/((1+10*s)*(1+s)) » [z,p,k]=zpkdata(L,'v') Does the open-loop have unstable poles? Does the Nyquist diagram ecircle the (–1+0j) point? Is the closed-loop system stable? What happens with stability if the gain 10 in the numerator of the above transfer funcion is increased? » nyquist(L),grid Verify the result by calculating the poles of the closed-loop system. In the feedback command 1 means unity feedback and -1 indicates the negative feedback. (The -1 can be ignored since that is the default value) » T=feedback(L,1,-1) or » T=L/(1+L); T=minreal(T) The minreal command cancels the zero-pole pairs: » [z,p,k]=zpkdata(T,'v') Plot the pole locations: » pzmap(T) As seen the system is structurally stable. The poles are left-side poles, the Nyquist diagram does not encircle the (–1+0j) point even with increased gains. Exercise 3. The loop transfer function of a system is

5( )(1 10 )(1 0.1 )

L ss s−

=− +

.

The system is in a negative unity feedback control loop. Determine the stability of the closed-loop based on the Nyquist criterion. » L=-5/((1-10*s)*(1+0.1*s)) » [z,p,k]=zpkdata(L,'v')

Does the open-loop have unstable poles? (Yes, 2 0.1p = ) » nyquist(L) In which direction the curve encircles (–1+0j) point? (CCW) Is the system stable? (Yes) Verify the result by calculating the poles of the closed-loop system. » T=feedback(L,1) » step(T) » [z,p,k]=zpkdata(T,'v') » pzmap(T) Examine the system if the polarity of the poles are changed to

5( )(1 10 )(1 0.1 )

L ss s−

=+ −

In which direction the Nyquist curve circles the -1 point? Is the system stable?

Page 32: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Stability .

32

Exercise 4. The loop transfer function of a system is

1( )(1 )(1 0.5 )

sL s ks s−

=+ +

.

The system is in a negative unity feedback control loop. Determine the range for the k parameter for which the open- loop is stable. a. k=1 is assumed:

» L=(1-s)/((1+s)*(1+0.5*s)) » [z,p,k]=zpkdata(L,'v') Does the open-loop have unstable poles? » nyquist(L),grid Determine the point where the Nyquist curve intersects the real axis (0.666). The system can be multiplied by the gain k=1/0.666 to be marginally stable. The system is stable if 0< k<1.5 (for k>0). » zoom b. k=-1 is assumed: » nyquist(-L), grid Determine again the point where the Nyquist curve intersects the real axis (-1); find k for stability (closed-loop system is stable if k>-1>0). Putting together the two intervals: The system is stable if –1<k<1.5 The stability can also be determined by the rlocus command, which plots the locus of the roots [gyökhely-görbe] supposing a parameter (generally the gain) changing its value from zero to infinity.

» help rlocus » rlocus(L) » rlocfind(L)

(We can use the mouse to find the gain value at a given point). Phase margin, Gain margin: If the system is stable the degree of stability is an important system property. The phase margin and gain margin tells how far is the system from being marginally stable. The phase margin can be calculated from the phase at the cut-off frequency cω .

( ) 180m cϕ ϕ ω= + ° At the cut-off frequency the absolute value of the open-loop frequncy function is 1:

( ) 1:cc L ω ωωω = =

If the phase margin is positive, the system is stable. For example, if the phase is 120ϕ = − ° , then the phase margin is 180 120 180 60mϕ ϕ= + ° = − °+ ° = ° , that is the system is stable. By multiplying the gain of the system with the gain margin the system becomes marginally stable.

( )1

gmL πω

= , where ( ) 180πϕ ω = − °

where 180: ( )

ππ ω ωω ϕ ω = = − The phase margin can be demonstrated both on the Nyquist plot and the Bode diagram. The MATLAB margin command helps to directly calculate the phase margin. Exercise 5. The transfer function of a system is

2

1( )(0.5 )( 2 1)

L ss s s

=+ + +

.

The system is in a negative unity feedback control loop. Calculate the phase margin, the gain margin and the cut-off frequency of the system: » L=1/((0.5+s)*(s^2+2*s+1))

Page 33: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Stability .

33

Frequency (rad/sec)

Phas

e (d

eg);

Mag

nitu

de (d

B)

Bode Diagrams

-80

-60

-40

-20

0

20Gm=13.064 dB (at 1.4142 rad/sec), Pm=72.227 deg. (at 0.56754 rad/sec)

10-1 100 10 1 -300

-200

-100

0

» [gm,pm,wg,wc]=margin(L) gm is the gain margin, pm is the phase margin, wc is the cut-off frequency and wg is the frequency where the phase is -180º. These values can be displayed graphically too. » margin(L); Note that in case of graphic display the Gm value is obtained in decibels: Gm=20*log10(gm) The amplitude, phase and frequency values can be looked at directly by arranging them into table format: » w=logspace(-1,1,100); » [num,den]=tfdata(L,'v') » [mag,phase]=bode(num,den,w); » Tabl=[mag, phase, w’]

mag phase w ……. 1.1123 -99.5242 0.5094 1.0643 -103.0406 0.5337 1.0158 -106.6104 0.5591≈wc 0.9669 -110.2286 0.5857 0.9178 -113.8900 0.6136 ……. 0.2706 -173.3384 1.2915 0.2449 -176.7848 1.3530 0.2211 -180.1658 1.4175≈wg 0.1991 -183.4774 1.4850 0.1789 -186.7160 1.5557 …….

The phase margin can be read from this table by finding the phase value belonging to the 1.0 magnitude value: pm=180-106.6=73.4. The cut-off frequency: w=wc=0.77. The gain margin can be calculated from the gain belonging to the 180− ° phase value: gm=1/0.221=4.52.

Page 34: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Series PID Compensation .

34

7. Series PID Compensation Consider the following closed-loop control system formed by a series compensator ( )C s and a process ( )P s :

( )C s )(sPe(t) y(t)u(t)r(t)

- Y(s)U(s)E(s)R(s)

Related to the above configuration a fundamental problem set up is to design a series compensator ( )C s for which the closed-loop system is stable and the design specifications are met. First discuss some practical design and quality specifications, then a couple of design procedures will be performed. Design and quality specifications: The aim of a control system is to ensure good reference signal tracking and disturbance rejection properties, meeting given quality specifications. Specifications - what is considered as "good" - have to be formulated. First of all a control system has to be stable. Stability has different formulations. Bounded input -bounded output (BIBO) stability means that every bounded input results in bounded output. Asymptotic stability means that the transients of the system are decreasing, tending to zero. Stability has to be ensured even in cases when system parameters may change within a given range. In other words a good design should be robust with respect to the parameter variations exhibited by the process. Another important requirement is static (or steady-state) accuracy. In steady-state the output signal has to approximate its prescribed reference value within a given accuracy. The control system also has to be able to reject disturbances within the specified static accuracy. Static accuracy depends both on the system structure and the input /disturbance signals. Transient response of the control system exhibits an important quality of the system. It can be formulated in the time domain with properties of the unit step responses of the control system for the reference input signal or for the disturbances. Such properties are the overshoot and the settling time. (The settling time is defined as the time necessary to reach the steady value within 1-2 %). Generally a small overshoot can be tolerated, but there are applications where aperiodic transients are required. A good approximation of the transient properties can also be obtained from system characteristics in the frequency domain. The overshoot observed in the time domain relates to the maximum amplitude of the closed-loop frequency function or to the phase margin calculated from the open-loop frequency response. The settling time can be estimated from the cut-off frequency of the open-loop. Introducing ( ) ( ) ( )L s C s P s= as the loop transfer function the closed-loop system can be characterized by the following transfer functions:

( ) 1( )

( ) 1 ( ) ( )e

E sW s

R s C s P s= =

+,

( ) ( )( )

( ) 1 ( ) ( )u

U s C sW s

R s C s P s= =

+,

( ) ( ) ( )( )

( ) 1 ( ) ( )Y s C s P s

T sR s C s P s

= =+

where r(t) is the reference (input) signal, u(t) is the control signal (the input of the process) and y(t) is the output signal. In order to meet the design specifications the parameters of the controller have to be adjusted accordingly. As mentioned earlier, the time domain specifications have corresponding specifications in the frequency domain.

- The output overshoot depends on the phase margin. For typical systems, if the phase margin is approximately 60°, then the overshoot of the step response is around 5-10%.

- The settling time depends on the cut-off frequency and it can be approximated by 3 10

s

c c

tω ω

≤ ≤ .

- The maximum of the control signal depends on the controller gain and PD pole replacement ratio (see the examples later on).

As far as the structure of the series compensators are concerned, the following controllers will be considered:

Page 35: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Series PID Compensation .

35

( )P cC s A k= =

1( ) (1

1 ) iPI c

i

T sC s A k

ssT+

= + =

1 1

1( ) (1

1)

1d

PD c cT s

C s k kT s

sT sτ +

= ++

=+

1 1

1 1( ) ( ) ( ) (1

11 )

1i d

PID PI PD ci

T s T sC s C s C s A k

s T ss

sT T sτ + +

= = ++

+ ≈+

, (only if 1iT Tτ> > )

PI controller is used, when zero steady-state error is required in the closed-loop step response, therefore an integrator has to be included in the control loop. PD controller is used if the system needs to be accelarated. In case of an ideal PD controller the value of the T1 parameter is zero, however an ideal PD controller can not be realized. Clearly, a PID structure is to be used if both steady-state and transient performances are to be met. It is seen that in a PID controller there are four design parameters. We can choose these parameters in the case of pole cancellation in the following way. The iT parameter is chosen for the largest time constant of the process and

the dT parameter is equal to the second largest time constant. This way the terms in the numerator of the controller

will cancel the poles of the plant. The T1 parameter is calculated in the 1d

p

TT

n= form, where pn is the pole

replacement ratio. It is a good practical rule that pn is between 5 and 10. If it is selected higher then the system

becomes faster, but the maximum of the control signal increases. Since the ck parameter does not influence the phase of the open loop, it can be used to set the phase margin. The steps of the series P, PI, PD, PID controller design will be shown for the following process:

1( )

(1 10 )(1 )(1 0.2 )P s

s s s=

+ + +

Design series P,PI,PD,PID type controllers for 60° phase margin. Calculate the quality parameters. Display the step response and the control signal. P type controller design: The controller is in the ( ) cC s k= form. Only the ck parameter has to be calculated. Define the transfer function

» s=tf('s') » P=1/((1+10*s)*(1+s)*(1+0.2*s)) » P=zpk(P)

First select the gain kc=1. » kc=1 » C=kc » L=C*P

Display the loop Bode diagram and calculate the important parameters (phase margin, gain margin, cut-off frequency) with the margin command. » margin(L) The system has significant phase and gain margin. Since the phase decreases from 0° to -270°, the phase margin can be set by changing the gain. The gain parameter of the controller can be calculated from the amplitude parameter belonging to the 180mϕ ϕ= − ° phase. This value can be read from a table or can be calculated by the margin command. The margin command can immediately calculate the required gain (gm) value. If we substract the phase margin value from the phase of the system, then the margin command calculates the required gain as follows:

» [mag,phase,w]=bode(L); » gm=margin(mag,phase-60,w)

Page 36: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Series PID Compensation .

36

» kc=gm The controller is: ( ) 7.51P cC s k= = Equivalently, the kc parameter can be calculated from a table as follows:

» w=logspace(-1,1,100); » [num,den]=tfdata(L,’v’) » [mag,phase]=bode(num,den,w); » Table=[mag, phase, w’]

mag phase w 0.1527 -115.4479 0.5591 0.1442 -117.3498 0.5857 0.1361 -119.2727 0.6136 0.1283 -121.2166 0.6428

kc will be the reciprocal of the magnitude belonging to phase angle -120°. The frequency belonging to this value will be the cut-off frequency:

kc=1/0.1361=7.3475, wc=0.6136 Refining the resolution in the frequency vector w, it can be seen that both solutions will lead to the same result. As always, it is important to verify the behaviour of the closed-loop system.

» C=kc » L=kc*L

Verify the stability-related parameters (phase and gain margin): » margin(L) » [gm,pm,wg,wc]=margin(L)

The phase margin is really 60°. The cut-off frequency is cω =0.6245. Calculate the closed-loop transfer function: » T=feedback(L,1)

Compare the Bode diagram of the open-loop and closed-loop: » bode(L,'r',T,'b') Display the step response of the closed-loop system:

» step(T) Also, calculate the step response:

» t=0:0.05:10; » y=step(T,t);

The maximum value can be calculated. » ym=max(y)

The steady state value of the step response is equal to the DC (zero frequency) gain. » ys=dcgain(T)

From these values the percentage overshoot can be calculated. » yt=(ym-ys)/ys

The steady state error » es=1-ys

The behaviour of the u(t) control signal also has to be examined. This is important because this is the input of the process and generally physical limitations exist in practice for this signal. Calculate the transfer function between the reference signal and control signal.

» U=feedback(C,P) or

» U=C/(1+C*P) In case of step reference:

» u=step(U,t); » plot(t,u)

The most common limitations are given for the maximum of the control signal. Let’s calculate it: » um=max(u)

Page 37: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Series PID Compensation .

37

P,PI,PD,PID type controller design: Create an m file to calculate all the performance related parameters. Herewith along the results of the design are summarized in a table format: ( )C s ( ) ( ) ( )L s C S P s= ck cω yt es um ~ ts

Plant

( )( )( )1

1 10 1 1 0.2s s s+ + +

0 0 0.5 2 12

P ck

( )( )( )1 10 1 1 0.2ck

s s s+ + +

7.51 0.62 0.153 0.117 7.51 8

PI ( )1 10c

sk

s+

( )( )1 1 0.2

cks ss + +

0.504 0.46 0.078 0 5.16 9

PD ( )( )

11 0.1c

sk

s+

+ ( )( )( )

k1 10 1 0.1 1 0.2

c

s s s+ + +

21.69 1.98 0.103 0.044 217 2

PID ( )( )( )

1 10 11 0.1c

s sk

s s+ +

+

( )( )k

1 0.1 1 0.2c

s ss + +

19.34 1.79 0.076 0 193 2

The primary requirements for the control system were good reference signal tracking and fast transient response. It is seen that P compensation does not meet any of them. The settling process is quite slow, and the output signal does not reach the required steady value y=1. With PI compensation the steady state error is zero, but the system is still slow. With PD compensation the control system has been accelerated, but it tracks the step reference signal with steady state error. This acceleration effect is reached by a significantly increased value of the control signal (manipulated variable) u(t). With the PID controller the behaviour of the control system became faster accompanied by zero steady state error. Write a MATLAB program (create an m file, a text file with extension m). Open a new m-file from MATLAB file menu. Write the required MATLAB commands into the empty file. Save the file: Save As, C:/Matlab/work/myfile.m To activate your program just type the file name with no extension in the MATLAB Command Window:

0 1 2 3 4 5 6 7 8 9 100

0.2

0.4

0.6

0.8

1

1.2

1.4

PI

PPD

PID

Step response

0 2 4 6 8 10-2

0

2

4

6

8Control signal, u(t)

P

PI

0 2 4 6 8 10-50

0

50

100

150

200

250Control signal,

PD

PID

Page 38: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Series PID compensation .

38

» myfile The following MATLAB commands calculate the parameters associated with the controller design: The control performance can be analysed also by building a SIMULINK block-diagram and running it with the given plant and the designed controllers. Compensating complex poles (second order oscillating element): If the plant has a complex pole pair,

2 21 2 0 0

( )( )( ) 2 1

A AP ss p s p s T T sζ

= =− − + +

, where 1,2p a jb= ±

its Bode diagram has a break frequency at 0

1T

frequency, where the slope of the asymptotic Bode amplitude diagram

changes from 0 to –40dB/decade. In this case a possible pole-cancellation PID controller design strategy can be

clear s=tf('s'); P=1/((1+10*s)*(1+s)*(1+0.2*s)) P=zpk(P) Cp=1 Cpi=(1+10*s)/(10*s) Cpd=(1+s)/(1+0.1*s) Cpid=Cpi*Cpd Cpid=zpk(Cpid) [mag,phase,w]=bode(Cp*P); kp=margin(mag,phase-60,w) Cp=kp*Cp; [mag,phase,w]=bode(Cpi*P); kpi=margin(mag,phase-60,w); Cpi=kpi*Cpi; [mag,phase,w]=bode(Cpd*P); kpd=margin(mag,phase-60,w); Cpd=kpd*Cpd; [mag,phase,w]=bode(Cpid*P); kpid=margin(mag,phase-60,w); Cpid=kpid*Cpid; Tp=feedback(Cp*P,1); Tpi=feedback(Cpi*P,1); Tpd=feedback(Cpd*P,1); Tpid=feedback(Cpid*P,1); Up=feedback(Cp,P); Upi=feedback(Cpi,P); Upd=feedback(Cpd,P); Upid=feedback(Cpid,P);

figure(1),step(Tp,'r',Tpi,'b',Tpd,'g',Tpid,'y') figure(2),step(Up,'r',Upi,'b') figure(3),step(Upd,'g',Upid,'y') t=0:0.05:10; yp=step(Tp,t); ypi=step(Tpi,t); ypd=step(Tpd,t); ypid=step(Tpid,t); ysp=dcgain(Tp) yspi=dcgain(Tpi) yspd=dcgain(Tpd) yspid=dcgain(Tpid) ep=1-ysp epi=1-yspi epd=1-yspd epid=1-yspid ytp=(max(yp)-ysp)/ysp ytpi=(max(ypi)-yspi)/yspi ytpd=(max(ypd)-yspd)/yspd ytpid=(max(ypid)-yspid)/yspid up=step(Up,t); upi=step(Upi,t); upd=step(Upd,t); upid=step(Upid,t); upim=max(upi) updm=max(upd) upidm=max(upid)

Page 39: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Series PID compensation .

39

setting the time constants in the numerator of the PI and PD terms of the controller to the natural frequency of the

plant, that is 0iT T= and 0dT T= , 0 0

1

1 11

( ) cT s T s

ks T s

C s + +

+= .

Another possibility is just to use a pure integrator as a controller setting the phase margin for about 60º. Sensitivity The parameters of a plant are not exact values, generally they are measured quantities. For example measuring the step response we can characterize the type of the element (e.g. first order lag with dead time or second order oscillating element). Supposing this type for the element structure the parameters can be estimated also from the measured input-output data (system identification). The parameters of the model of the element obtained in this way are not accurate values, their values can be given around a nominal value between a minimum and a maximum. Analysis of sensitivity of the control system to plant parameter uncertainties is an important question. Designing a controller we have to consider these parameter uncertainties. The control system has to behave according to the required performance for the nominal parameter values and still in an acceptable way if the real parameters differ from their nominal values in the given band. Different rubust control design techniques address the solution of this problem. To demonstrate controller design for a second-order oscillating element and the effect of parameter uncertainties let us design a PID controller for the following plant:

2

1( )4 4 1

P ss sς

=+ +

, and the damping factorς changes between 0.2 and 1.

Design the controller for phase margin 60º. The MATLAB commands:

» clear » s=tf('s');

Define the plant: » P1=1/(4*s*s+0.8*s+1) %zeta=0.2 » P2=1/(4*s*s+2.8*s+1) %zeta=0.7, nominal » P3=1/(4*s*s+4*s+1) %zeta=1 » P=zpk(P); P1=zpk(P1); P2=zpk(P2); P3=zpk(P3);

The controller with gain kp=1: » Cpid=(1+2*s)*(1+2*s)/((2*s)*(1+0.2*s)) » Cpid=zpk(Cpid)

The Bode diagram for the nominal plant P2: » [mag,phase,w]=bode(Cpid*P2);

Set the controller gain ensuring 60º phase margin: » kp=margin(mag,phase-60,w) » Cpid=kp*Cpid; » figure(1); bode(Cpid*P2) % show the Bode diagram » Tpid=feedback(Cpid*P2,1); » Upid=feedback(Cpid,P2);

Calculate the resulting transfer functions » t=0:0.05:10; » ypid=step(Tpid,t) » figure(2); plot(t,ypid),grid,shg » upid=step(Upid,t); » figure(3); plot(t,upid),grid,shg

Calculate and plot the output and the control signal » Tpid1=feedback(Cpid*P1,1); » Tpid3=feedback(Cpid*P3,1);

Calculate and show the output signal with the nominal plant and with the modified damping factors

Page 40: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Series PID compensation .

40

» ypid1=step(Tpid1,t); » ypid3=step(Tpid3,t); » figure(4); plot(t,[ypid,ypid1,ypid3]),grid

The figure below shows the output of the control system with the controller designed for the nominal system ( 0.7ς = ), and applying the controller also for the plant with changed damping factors. It is seen that the overshoot is much higher for the smaller damping factor. The control system is sensitive for the uncertainties in this parameter.

0 1 2 3 4 5 6 7 8 9 100

0.2

0.4

0.6

0.8

1

1.2

1.4

1

0.7 0.2

Page 41: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Series Compensation in Case of Dead Time .

41

8. Series Compensation in Case of Dead Time Consider the following closed-loop system:

( )C s ( )dP se(t) y(t)u(t)r(t)

- Y(s)U(s)E(s)R(s)

where ( )P s is the transfer function of the process without dead time, ( )C s is the controller and

( ) ( ) ( )dL s C s P s= is the open loop transfer function with

( ) ( ) 1 20d

ssTd

eP s P s e s−

−= =+

.

The ( )C s controller has to be designed such that the performance of the whole system satisfy the design specifications. The closed-loop system should have zero steady state error. Select a PI compensator.

1 20( ) csC s k

s+

=

The closed-loop transfer function: 1 20( ) ( ) ( )

1 20

s s

c cs e eL s C s P s k k

s s s

− −+= = =

+

ck has to be calculated to achieve 60° phase margin. The magnitude and phase values of the open-loop can be calculated from the system with no delay, since

( ) ( ) ( )dd

j Tj j jP P Pe ωω ω ω−== , since 1;dj Te ω− =

{ } { } { } { }( ) ( ) ( )d ddj TArg P j Arg P j Arg Arg P j Te ωω ω ω ω= +

− = −

» s=zpk(‘s’) » P=1/(1+20*s) » Td=1 » kc=1 » C=kc*(1+20*s)/s

The loop transfer function » L=C*P » L=minreal(L)

The magnitude and phase values of the loop can be calculated for the system without the delay: » [num,den]= tfdata(L,’v’) » [mag,phase,w]=bode(num,den); » magd=mag; » phased=phase-w*Td*180/pi;

The ck gain can be calculated in several ways: Method 1. Use the margin command: The gain margin for -120° phase angle is

» gm=margin(magd,phased-60,w) This is the value for kc

» kc=gm 0.5229

Page 42: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Series Compensation in Case of Dead Time .

42

0 5 10 15 20 25 300

0.2

0.4

0.6

0.8

1

1.2

1.4

Method 2. Use a table: » w=logspace(-2,1,100); » [mag,phase]=bode(num,den,w); » magd=mag » phased=phase-w’*Td*180/pi Now create a table

» T=[ phased, magd, w’] -116.5943 2.1544 0.4642 -118.5162 2.0092 0.4977 -120.5770 1.8738 0.5337 <= -122.7868 1.7475 0.5722 -125.1562 1.6298 0.6136 The mag value for 120phased = − ° is mag ( 120phased = − ° )=1.8738 . From here kc=1/1.8738

» kc=1/1.8738 0.5337

Calculate again the loop by

» C=kc*(1+20*s)/s Verify that the phase margin is 60°. The system can be simulated by the following SIMULINK model (recall that SIMULINK offers the option to easily add dead time to the process):

TransportDelay

Step Scope2

Scope1

P

LTI System1

C

LTI System

The scope blocks can be used to transfer the results of the simulation to the Matlab workspace. Change the

parameters in the Scope graphic window ‘properties’ menu. Data history: Save data to workspace Variable name: ty (tu for the control signal) Matrix format

The time and output vectors can be gained easily after the simulation.

» t=ty(:,1) » y=ty(:,2) » plot(t,y),grid

Similarly, the control signal u can be generated. The u, y vectors can be used to verify further design requirements (overshoot, settling time, maximum control effort, etc.). (To workspace blocks from the sinks library can alternatively be connected to signals to be saved.)

Page 43: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Series Compensation in Case of Dead Time .

43

Pade approximation: The design can be done also with the help of the Pade approximation. The delay term is

approximated by a rational fraction: ( ) dsTPADEP s e−≈

( )C s ( )P se(t) y(t)u(t)r(t)

- Y(s)U(s)E(s)R(s)( )PADEP s

In Matlab the pade command calculates the approximation. Use 5-th order approximation,

» [numpade,denpade]=pade(Td,5) » Ppade=tf(numpade,denpade) » Pd=P*Ppade

With this transfer function the kc gain then can be calculated the same way as for a system with no delay. » [mag,phase,w]=bode(Pd); » kc= margin(magd,phased-60,w) 0.5229

It has to be emphasized that the previous solution and simulation is the more accurate and therefore it is preferred.

Page 44: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Controlling Unstable Processes

44

Frequency (rad/sec)

Pha

se (d

eg);

Mag

nitu

de (d

B)

Bode Diagrams

-100

-80

-60

-40

-20From: U(1)

10-1 100 101 102-180

-170

-160

-150

To: Y

(1)

Frequency (rad/sec)

Pha

se (d

eg);

Mag

nitu

de (d

B)

Bode Diagrams

-100

-80

-60

-40

-20From: U(1)

10-1 100 101 102150

160

170

180

To: Y

(1)

9. Controlling Unstable Processes Exercise 1. Consider the following unstable process:

1( ) ( 2)( 5)

P ss s

=+ −

Question: Can the system be stabilized with a proportional (P) controller, ( ) cC s k= ?

» s=zpk('s') » P=1/((s+2)*(s-5)) » figure(1); nyquist(P); » figure(2); » figure(3);rlocus(P); It is seen that stability is hopeless. The generalized Nyquist plot will never encircle the (-1+j0) point counter-clockwise [óramutató járásával ellenkezõ irányban]. Just to check this: the poles of the closed-loop control system are determined by the roots of s2-3s-10+kc=0. It is well known that the necessary condition for closed-loop stability is that all the coefficients in the above characteristic equation must have identical sign. This condition can not be met since kc does not have an influence on the coefficient (-3). This can also be verified by looking at the root locus (location of the closed-loop poles while 0 ≤ kc < ∞). Exercise 2. As a second example consider the following variation of the above process:

1( ) ( 2)( 5)

P ss s

=− +

Is there a stabilizing proportional controller, ( ) cC s k= ? » clear

» s=zpk('s') » P=1/((s-2)*(s+5)) » figure(1); nyquist(P); » figure(2); bode(P); » figure(3);rlocus(P); This time the Nyquist plot is rather promising. It is seen that increasing the ck gain will result in satisfying the generalized Nyquist criterion for stability. Specifically, ck >10 will stabilize the closed loop system. Select a gain value to achieve maximum phase margin. First calculate the magnitude and phase values of the open-loop for kc=1. » C=1; » L=C*P; » [num,den]=tfdata(L,’v’) » [mag,phase,w]=bode(num,den); Method 1. Read the values from a table. » T=[ phase, mag, w] -155.9825 0.0613 2.2122 -154.7797 0.0506 2.8072 -154.6231 0.0452 3.1623 -154.7797 0.0399 3.5622 -155.9825 0.0300 4.5204 The Bode plot phase curve has a maximum value at

= -154.62 mag=0.045 =3.16ϕ ω . The maximum phase margin that can be achieved with proportional compensation is pm=180-154.6=25.8°. For the maximum phase margin the gain should be selected to kc=1/0.045=22.22 » kc=22.22 Method 2. The maximum can be found also with the max command.

Page 45: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Controlling Unstable Processes

45

» [maxphase,index]=max(phase) » kc=1/mag(index) Recalculate the system with the new gain. » C=kc; » L=C*P; The margin command calculates the phase margin. » margin(L); The system has quite low phase margin ( 25.4Pm = ° ). Look at the closed loop performance: » T=feedback(L,1) » step(T) Stability is demonstrated, however, the steady-state error is close to 100%. A PID compensator is necessary to improve the performance. Exercise 3. Design a PID compensator to reduce the steady state error.

( 2) ( 5)( ) 50c

s sC s ks s+ +

=+

.

The unstable pole 1 2p = can not be compensated directly with an unstable zero, because in case of parameter change the system becomes unstable. The 1 2p = unstable pole, instead is compensated by a stable PI term. The

1 5p = − pole is moved to higher frequency by the PD term (p=-50, the pole replacement ratio is 10). The ck gain can be calculated again by finding the maximum phase value. Close all the figure windows.

» clear » s=zpk('s') » P=1/((s-2)*(s+5)) » C=((s+2)*(s+5))/(s*(s+50)) » L=C*P » L=minreal(L) » bode(L) » [mag,phase,w]=bode(L); Calculate the gain for the maximum phase. (kc=760, pm=180-121=59) » [maxphase,index]=max(phase) » kc=1/mag(index) The gain is kc=760.26 and the phase margin is pm=180+maxphase =59. Verify the system behaviour. » kc=760.26 » C=kc*((s+2)*(s+5))/(s*(s+50)) » L=C*P, L=minreal(L) » margin(L) Look at the closed loop performance: » T=feedback(L,1) The steady state error is reduced to zero. » es=1-dcgain(T) Verify also the u control signal. » U=feedback(C,P); » step(U) » u=step(U)

» um=max(u) The maximum of the control signal, um is quite high. It can be reduced by reducing the pole replacement ratio

Time (sec )

Am

plitu

de

Step Response

0 0.2 0.4 0.6 0.8 1 1.20

0.5

1

1.5From: U(1)

To: Y

(1)

Frequency (rad/sec)

Pha

se (d

eg);

Mag

nitu

de (d

B)

Bode Diagrams

-100

-50

0

50

100Gm=-17.25 dB (at 2.0851 rad/sec), Pm=58.122 deg. (at 14.596 rad/sec)

10-2 10-1 100 101 102 103-300

-250

-200

-150

-100

Page 46: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Discrete-time Systems .

46

10. Discrete-time Systems z-transforms In computer controlled systems signals in the digital controller are stored and processed in digital form. Also, due to the nature of the digital computers the processing takes place at discrete time events. Consequently, analog continuous-time signals involved in a closed-loop control system have to be sampled and converted to digital form. The digital form of the ( )y t analog signal can be derived by applying a train of shifted unit pulses:

{ }( ) ( ) (0) ( ) ( ) ( ) (2 ) ( 2 ) (3 ) ( 3 ) ...d s s s s s s sy t y nT y t y T t T y T t T y T t Tδ δ δ δ= = + − + − + − +

The Laplace-transform of ( )dy t is 2 3( ) (0) ( ) (2 ) (3 ) ...s s ssT sT sT

d s s sy s y y T e y T e y T e− − −= + + + + Introducing

1,s ssT sTz e z e−−= =

1 2 3

0( ) (0) ( ) (2 ) (3 ) ... ( ) k

d s s s sk

y z y y T z y T z y T z y kT z∞

− − − −

=

= + + + + =∑

This is the well-known z-transform of the sampled signal, where 1z− is frequently interpreted as a shift operator. Exercise 1. The z-transform of a signal is

2

2

20.24d

z zyz z

−=

− +, 0.5sT =

Calculate the first 5sN = samples of the inverse z-transform of the signal. a/ Matlab commands:

» num=[2, -1, 0] » den=[1, -1, 0.24] » Ns=5; » yd=dimpulse(num,den,Ns); » plot(1:Ns,yd,'*')

Alternatively, symbolic input and LTI structure can also be used. In this case, similarly to the s variable, the z variable should be defined, however, also the sT sampling time has to be specified for the definition:

» Ts=0.5; » z=tf(‘z’,Ts); » Y=(2*z^2-z)/(z*z-z+0.24);

One advantage of using the LTI structure is that the very same MATLAB command impulse can be used both for continuous-time and discrete-time systems. If the sampling time is zero, then the system is considered as a continuous time system. Citing the MATLAB Help we have IMPULSE(SYS,TFINAL) simulates the impulse response from t=0 to the final time t=TFINAL.

To obtain the same output samples we calculated earlier 2tfinal = is to be assigned for the final time:

» tfinal=2; » Yd=impulse(Y,tfinal); » plot(Yd,’*’);

(The first value belongs to the first sample at t=0.) b/ Partial-fraction expansion The z-transform of an exponential component is

Page 47: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Discrete-time Systems .

47

( ) , ( ) s

s

anT Zatd s aT

zy t e y nT ez e

−−−= = →

The signal can be converted to the

1 20

1 2

1( )dnum num r ry z z z kden den z p z p

= = = + + − −

partial fraction expanded form by the MATLAB residue command.

» num1=[2, -1] » den=[1, -1, 0.24] » [r,p,k0]=residue(num1,den) r = 1 1 p = 0.6000 0.4000 k0 = []

» Ts=0.5

1 2

1 2

1 1( )0.6 0.4 0.6 0.4d

r r z zy z z zz p z p z z z z

= + = + = + − − − − − −

{ } { }( ) ( ) s sanT bnTd sy t y nT e e= = + , where 0.6, 0.4s saT bTe e= =

» a=log(0.6)/Ts » b=log(0.4)/Ts

ln(0.6) ln(0.4)1.02, 1.83s s

a bT T

= = − = = −

1.02 1.83 ( ) , t 0t ty t e e− −= + ≥

» t=[0:Ts:2]’ » yd=exp(a*t)+exp(b*t) » plot(t,yd,’*’);

Pulse transfer function A continuous-time system together with a zero-order hold on the input can be characterized by its pulse transfer function, which is the ratio of the z-transform of the sampled output and the discrete-time input signal, where u(kTs)=u[k].

)(sPAD /u[k] y(t)u(t) y[k] ( )( )

( )dY zP zU z

=U(z) Y(z)Y(s)ZOH ≡U(s)

U(z) Y(z)

Exercise 2. Calculate the pulse transfer function of the continuous-time system with zero order hold on the input.

1 5( ) , 1(1 10 )(1 8 )(1 4 )(1 2 ) s

sP s Ts s s s

+= =

+ + + +

» s=zpk(‘s’) » P=(1+5*s)/((1+10*s)*(1+8*s)*(1+4*s)*(1+2*s))

Page 48: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Discrete-time Systems .

48

The continuous-time system is obtained in zero-pole form:

0.2( ) 0.0078( 0.5)( 0.25)( 0.125)( 0.1)

sP ss s s s

+=

+ + + +

» [z,p,k]=zpkdata(P,’v’) The poles of the continuous-time system: -0.5, -0.25, -0.125, -0.1 The zero of the continuous-time system: -0.2

The pulse transfer function of the system with zero order hold can be calculated by the c2d command.

» Ts=1; » Pd=c2d(P,Ts)

( 3.088)( 0.8187)( 0.2198)( ) 0.0011( 0.9048)( 0.8825)( 0.7788)( 0.6065)d

z z zP zz z z z

+ − +=

− − − −

The discrete zeros and poles: » [zd,pd,kd]= zpkdata(Pd,’v’)

The poles of the discrete system: 0.9048, 0.8825, 0.7788, 0.6065 The zeros of the discrete system: -3.088, 0.8187, -0.2198 Notice that the discrete poles are resulted from the ssTz e= transformation.

» exp(-0.5) 0.6065 Similarly

» exp(p) The relationships between the continuous and discrete zeros are more complicated. Final value theorems The initial value of a discrete signal is obtained by

0lim ( ) lim ( )sn z

y nT y z→ →∞

=

The final value is obtained by relationship 1

1lim ( ) lim(1 ) ( )sn z

y nT z y z−

→∞ →= −

Exercise 3. The input of the plant in exercise 2. is a unit step. In the discrete case after sampling we get a pulse train with unity

amplitude whose z-transform is 1

zz −

.

Calculate the initial and final value of the output signal of the discrete system.

( ) ( )1 d

zy z P zz

=−

The initial value is 0, as the degree of the denominator is higher than the degree of the numerator. The final value is obtained substituting z=1 in the expression of ( )dP z . The final value of the step response is the gain of the pulse transfer function, which can be calculated by the dcgain command the same way as for continuous systems (the ddcgain(numd,dend) command can also be used). The commands of the Control System Toolbox determine that the system is continuous or discrete based on the sampling time parameter. If the sampling time parameter of an LTI system is set to zero than the system is considered as continuous otherwise it is assumed discrete.

» A=dcgain(P) » Ad=dcgain(Pd)

Both A (continuous) and Ad (discrete) give values of 1, as expected.

Page 49: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Discrete-time Systems .

49

Real Axis

Imag

Axi

s

Pole-zero map

-2.5 -2 -1.5 -1 -0.5 0 0.5 1-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Time (sec )

Am

plitu

de

Step Response

0 1 2 3 4 5-10

-5

0

5

10

15

20From: U(1)

To: Y

(1)

Stability The discrete closed-loop control system is stable, if the roots of its characteristic equation (the poles of the denominator of the closed-loop pulse transfer function are inside of the unit circle. Exercise 4. Determine if the following discrete transfer function is stable.

1 + z 2.5 + z 3 + z0.1 - z 0.3 - z(z)P 23

2

d = , 1=sT

Define the system in matlab:

» Ts=1 » z=tf(’z’,Ts) » Pd=(z*z-0.3*z-1)/(z^3+3*z^2+2.5*z+1)

Calculate its poles: » [z,p,k]=zpkdata(Pd,’v’)

The absolute value of the poles: » abs(p) ans =

2.0000 0.7071 0.7071 The system is unstable, since one of the values is larger than 1. The stability can also be determined by visualizing the locations of the discrete poles.

» pzmap(Pd) » zgrid

The system is unstable again because the -2 pole falls outside of the unity circle. The zgrid command displays the unity circle and the constant damping lines for second complex pole pairs. The stability can be determined in the time domain by looking at the step response.

» step(Pd) The output is not bounded therefore the system is unstable.

Page 50: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Discrete PID Control .

50

11. Discrete PID Control

This demo shows how to use MATLAB to design and simulate sampled-data control systems. The design uses frequency domain considerations leading to a pole-cancellation PID control method.

)(zC )(sPAD /

DA /

u[k]e[k] y(t)u(t)

y[k]

r[k]

-

( )( )( )

Y zP zU z

=

U(z)

Y(z)

Y(s)

The continuous-time process is given by

( ) ( )( ) 1( )1 10 1 5

sseP s P s e

s s

−−= =

+ +

Observe that the system has a delay term of 1 sec. The sampling time is 1 sec. Design a series PID compensator to meet the following design specifications:

- Phase Margin≅60° - Settling time should be minimal - The closed-loop system should follow unit step reference signal without steady error (type one system).

Define the continuous-time process without the se− time delay. » s=zpk(’s’); » P1s=1/((1+10*s)*(1+5*s));

Find the discrete-time process model assuming zero-order hold (without delay):

( ) 1 11

( )(1 ) P sP z z Zs

− = −

By MATLAB: » Ts=1; » P1z=c2d(P1s,Ts,’zoh’);

Note that it is not necessary to include the default ‘zoh’ string. Add the time-delay to the process by multiplying 1( )P z with 1z− , since { } 1se zZ − −= .

The z variable can be defined similarly to the z variable. » z=zpk(‘z’,Ts) » Pz=P1z/z

( ) ( ) ( ) ( )( )( )

11 1

0.90481 0.009050.9048 0.8187

zP z z P z P z

z z z z− +

= ⋅ = ⋅ =− −

The zeros and poles of the discrete system are » [zd,pd,kd]=zpkdata(Pz,’v’)

PI term is necessary to achieve the steady state zero error requirement. PD term is used to accelerate the system response. The PI and PD break frequencies can be calculated similarly to the continuous system. iT is the largest

time constant of the system and dT is the second largest time constant.

PI : break frequency at 0.1 ⇒ 1

0.110s

i

TTe e e

− − −= = = 0.9048

PD : break frequency at 0.2 ⇒ 1

0.20.5s

d

TTe e e

− − −= = = 0.8187 The discrete controller is

Page 51: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Discrete PID Control .

51

0.9048 0.8187( )1c

z zC z kz z

− −=

The ck parameter is calculated to set the 60° phase margin.

First assume ck =1 : » kc=1; » Cz=((z-0.9048)*(z-0.8187))/((z-1)*z);

or with the poles of the discrete plant transfer function » Cz=((z-pd(1))*(z- pd(2)))/((z-1)*z)

Calculate the discrete-time loop transfer function ( ) ( ) ( )L z C z P z= ⋅ . » Lz=Cz*Pz; » Lz=minreal(Lz, 0.001); % cancel the zero-pole pairs

The ck parameter can be calculated by the margin command or read from a table.

a/ Use the margin command. The bode command tests the sT sampling time to see if the system continuous or

discrete. If 0sT = the system is considered to be a continuous-time system, if 0sT > positive than the system is considered to be a discrete-time system.

» [mag,phase,w]=bode(Lz); » kc=margin(mag,phase-60,w);

b/ Use a table » [numz,denz]=tfdata(Lz,’v’); » [mag,phase,w]=dbode(numz,denz,Ts); » T=[mag, phase, w] % setting up a table

T = 0.0781 -114.8936 0.2200 0.0697 -117.8611 0.2462 0.0622 -121.1822 0.2756 0.0555 -124.8991 0.3084 0.0495 -129.0589 0.3452 It is seen that the phase shift of about -120° (required by the specification of PM=60°) is achieved at a magnitude of 0.062. Consequently, gain by 1/0.0622 defines the proper gain ck as follows:

» kc=1/0.0622

The gain of the discrete-time controller is 16ck = . Notice that the margin has to forms; its input can be a transfer function or the bode amplitude and phase values. Verify now the system behaviour. Check the phase margin by the margin command.

» Cz=kc*((z-pd(1))*(z- pd(2)))/((z-1)*z); » Lz=Cz*Pz; » Lz=minreal(Lz); » margin(Lz);

The closed loop performance can be investigated by a Simulink model. » simulink % starts SIMULINK

Create a new file and copy the various blocks. The parameters of the block should be set to the required value. SIMULINK uses the variables defined in the MATLAB workspace. C(z), P1(s): Control System Toolbox –>LTI system :Cz, P1s Sum: Simulink–>Math–>Sum: +- Dead time, delay: Simulink–>Continuous–>Transport Delay: 1 Step input: Simulink–>Sources–>Step, Change the Step time parameter to zero Zero-Order-Hold: Simulink–>Discrete–> Zero-Order-Hold, Sampling time: Ts Scope: Simulink–>Sinks–>Scope The scope blocks can also be used to transfer the results of the simulation to the Matlab workspace. Change the parameters in the Scope graphic window ‘properties’ menu.

Page 52: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

Discrete PID Control .

52

Zero-OrderHold

TransportDelay

Step ScopeY

ScopeU

P1s

LTI System1

Cz

LTI System

Data history: Save data to workspace Variable name: My for ScopeY and Mu for ScopeU Matrix format

From the Menu change the Simulation–>Parameters–>Stop Time parameter to 20

After the simulation the time, the output and control vectors can be gained from the transferred matrix form.

» ty=My(:,1), y=My(:,2) » tu=Mu(:,1), u=Mu(:,2)

Plot the output, y(t) » subplot(211), plot(ty,y), grid

and the control signal u(t). The u(t) control signal is the output of the zero order hold. » subplot(212), stairs(tu,u) , grid

The discrete u[k] signal can also be ploted. » hold on, plot(tu,u,’*’)

The performance parameters (settling time, overshoot) of the system can be calculated from the y and u vectors.

0 2 4 6 8 10 12 14 16 18 200

0.5

1

1.5

0 2 4 6 8 10 12 14 16 18 20-5

0

5

10

15

20

Page 53: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

State Space Representation, Observability, Controllability .

53

12. State Space Representation, Observability, Controllability

Using State Models an { }, , ,A b c d set exhibits a Single Input/Single Output system representation with input u , output y and state vector x in the State Model:

x Ax buy cx du= += +

It is well known that there is an infinitely large number of Input/Output equivalent State Models associated with a given transfer function. MATLAB offers one possible way to get a State Model. Start our discussion with a transfer function of

2

1( )1

H ss s

=+ +

and transform it to a State Model: » num=1; » den=[1 1 1]; » [A,b,c,d]=tf2ss(num,den) % transform to state model » [num1,den1]=ss2tf(A,b,c,d) % just to check, transfer back to transfer function form

To verify the equivalence plot the step responses of the two Input/Output equivalent representations: » step(num,den); » step(A,b,c,d);

A different representation can be generated by a coordinate transformation in the state-space. The state variables in the new coordinate-system can be calculated by a linear transformation (called similarity transformation). In details, assuming P as a non-singular quadratic transformation matrix and x as the state variable in the new (transformed) system the similarity transformation can be summarized in the following set of equations:

x Ax buy cx du= +

= +

where -1

-1 1

=> , , ,

x Px x P xA PAP b Pb c cP d d−

= =

= = = =

Note that if 1P− is a matrix constructed by the eigenvectors of A as its column vectors, the new form becomes a diagonal form (also called as parallel realization). Example:

» A=[-1 –0.5 0.5; 2 –3 0; 2 –1 –2] » b=[2;3;1] » c=[0 0 1] » d=0 » H=ss(A,b,c,d)

Calculate the eigenvectors (V) and eigenvalues (ev). » [V,ev]=eig(A)

Transfer the system to diagonal form by the eigenvectors of the system. The inverse of the transformation matrix is V. » Pi=V; P=inv(V) » Ap=P*a*Pi » bp=P*b » cp=c*Pi » dp=d

Verify that V is diagonal. The same calculation can be done easier by

» [Ap,bp,cp,dp]=ss2ss(A,b,c,d,inv(V)) or just leaving the transformation matrix hidden:

» [Ap,bp,cp,dp]=canon(A,b,c,d,’modal’)

Page 54: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

State Space Representation, Observability, Controllability .

54

[ ]

1 1

2 2

3 3

1

2

3

1 0 0 1.730 3 0 00 0 2 2.23

0.57 0.707 0 0

x xx x ux x

xy x u

x

= − ⋅ + ⋅

− −

= − ⋅ + ⋅

Draw the block diagram of the system. This is a parallel representation of the system. Notice that the gain by

1 1 1.73 0.57 1b c⋅ = ⋅ = . It is clear that any 1 1 1b c⋅ = gives identical I/O equivalent state-space representations.

y

-1

1x 1x

-2

3x 3x

-3

2x 2x-0.707

0.57

u

1.73

-2.23

The above parallel structure allows us to directly read the observability and controllability conditions. Namely 3x is

not observable and 2x is not controllable. The observability and controllability of the system can be determined without converting a system to a diagonal representation. The controllability matrix of the system is 1... n

oC b Ab A b− = and can be obtained by » Co=ctrb(a,b)

or using an LTI structure: » Co =ctrb(H)

Then controllability can be judged by checking if oC has full rank: » rank(Co)

The system is controllable if the rank of the controllability matrix is equal to the number of state variables (n). In our case the system is not controllable since ( ) 2orank C n= < .

The observability matrix of a system is

1

...n

b

c

cAO

cA −

=

by MATLAB: » Ob=obsv(A,c) » Ob =obsv(H) » rank(Ob)

The system is observable if the rank of the observability matrix is equal to n. The system is not observable since ( ) 2brank O n= < .

Page 55: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

State Space Representation, Observability, Controllability .

55

The output controllability matrix of the system is *oy oc c C= . The system is output controllable if the ( )oyrank c equals to the number of outputs.

» rank(c*Co) Calculate the transfer function of the system:

» [num,den]=ss2tf(A,b,c,d) Calculate the transfer function in zero-pole form.:

» Hzpk=zpk(H) Observe, that two zeros cancel two poles:

» Hzpk=minreal(Hzpk) Information on system states is lost in the transfer function form. The fact of zero-pole cancellation explains why controllability and/or observability are lost.. The parallel representation can be created by partial fraction expansion, too:

» [num,den]=tfdata (H,’v’) » [r,p,k]=residue(num,den)

0 0 1( )3 2 1

H ss s s

= + ++ + +

Remark: it is seen that the transfer function 1

1s + describes only a subsystem of the complete system represented by

the State Model. This particular subsystem, however, is controllable and observable.

Page 56: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

State Feedback Control .

56

13. State Feedback Control A linear time invariant system can be described by its state matrices: A,B,C,D.

x = Ax + Buy = Cx + Du

State feedback modifies the dynamic and static behaviour of the system in terms of the relation between the reference signal and the output signal:

y∫ CB

x x

K

A

G ur

-

D

Using the K matrix in the state feedback path and the G matrix in the feed-forward path the state equation of the closed-loop system is

)( )

−−

x = (A BK x + GBry = C DK x + DGr

.

Introducing , , , F F F F= − = = − =A A BK B GB C C DK D DG we have

F F

F F

x = A x + B ry = C x + D r

for the closed-loop system. The characteristic equation of the closed-loop system is: det( ) det( ) 0Fs − = =I A sI - A + BK .

The state feedback control system can be designed in the following steps: - assign the poles for the closed-loop system - the feedback gain K is calculated with the Ackermann formula (use Matlab acker command) - calculate the static gain G to achieve the required steady-state behaviour.

Example. Consider the following system, given by its transfer function:

6( )( 1)( 2)( 3)

H ss s s

=+ + +

Give the poles of the system and transform it to state space representation. » po=[-1;-2;-3]; » [A,b,c,d]=tf2ss(6,poly(po))

[ ]6 11 6 1

1 0 0 , 0 , 0 0 6 , 00 1 0 0

A B C D− − − = = = =

Assign the poles for the closed-loop system » pc=[-6;-3+i*4;-3-i*4];

and find the feedback gain vector to realize the required pole-placement from [ ]1 2 3op = − − − to

[ ]6 3 4 3 4cp j j= − − + − − :

Page 57: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

State Feedback Control .

57

» k=acker(A,b,pc)

[ ]6 50 144=k » t=0:0.1:6;

» subplot(211),step(A,b,c,d,1,t); » subplot(212),step(A-b*k,b,c,d,1,t);

It is seen that the transient response has considerably been improved, though the steady-state behaviour of the closed-loop system is not acceptable. One way to achieve zero steady-state error is to apply a correction gain for the reference signal. The value of that gain is equal to the ratio of the open-loop DC gain over the gain of the closed-loop DC gain:

» GainOL=dcgain(A,b,c,d) GainOL = 1 » GainCL=dcgain(A-b*k,b,c,d) GainCL = 0.04 » G= GainOL/ GainCL » subplot(212),step(A-b*k,G*b,c,d)

The figure below shows the plant output and the outputs of the control system without and with gain compensation.

0 1 2 3 4 5 60

0.2

0.4

0.6

0.8

1

0 1 2 3 4 5 60

0.5

1

1.5

plant output

output without gain compensation

output with gain compensation

Due to the change in the location of the poles the closed-loop system became faster, as expected . Insert an integrator into the loop The state feedback itself adds a similar effect to the closed-loop as a serially connected PD compensator designed in the frequency domain. The static gain of the system, however, is set by the G parameter, which is out of the loop, i.e. this setting is sensitive with respect to the changes or uncertainties in the process parameters. Also, in case of disturbances the static gain will not change. Consequently, to eliminate the static error an integrator should be inserted into the loop. The modified control structure is presented in the figure below.

Page 58: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

State Feedback Control .

58

ixik

r∫

-ix y

∫ CBx x

K

A

u

-

D

The number of the state variables has been increased by a new state variable. Assuming a single-input single-output system with D = 0 the state model for the closed-loop system can be written as

0 1i

e c e ci i

kr r

x x

= = + = +

x xA - bk b 0x A x b

-c ,

where cA can further be decomposed with elements of extended dimensions:

[ ]0 0 0

ic i e e e

kk

= = − − = −

A - bk b A 0 bA k A b k

-c -c

The poles of the closed-loop system then are determined by 0e e es − + =I A b k

Describing the poles for the closed-loop system (i.e. for the characteristic equation above) the Ackermann’s formula can be applied to find the proper gain ek . Continuing the example enhance the system by the state variable of the integrating element. Create the state equation of the enhanced system:

» z=[0;0;0]; » Ae=[A z;c 0] Ae = -6 -11 -6 0 1 0 0 0 0 1 0 0 0 0 6 0 » be=[b;0] be = 1 0 0 0

Prescribing the closed-loop poles one more pole is to be given: » pce=[-9 -6 -3+i*4 -3-i*4]; » ke=acker(Ae,be,pce)

[ ]15 158 693 225=ke The first 3 components of the state feedback vector belong to the original state variables, while the forth is the state feedback coefficient for the integrator.

» k=ke(1:3)

Page 59: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

State Feedback Control .

59

k = 15 158 693 » ki=ke(4) ki = 225 » Ac=[A-b*k b*ki;-c 0] Ac = -21 -169 -699 225 1 0 0 0 0 1 0 0 0 0 -6 0 » bc=[z;1] bc = 0 0 0 1 » cc=[c 0] cc = 0 0 6 0 » dc=0; » subplot(111),step(Ac,bc,cc,dc,1,t)

0 1 2 3 4 5 60

0.2

0.4

0.6

0.8

1

1.2

1.4

It is seen that both the static and dynamic behaviour is good.

State estimation In most cases only the output of the system is measurable and the state variables are not available. In this case the state variables have to be estimated. For state estimation the Kalman filter can be used. Its structure is shown in the figure below. The model of the system is built and connected parallel to the system. The input for the system and its model is the same. The difference of the outputs of the system and the model is fed back to the state derivatives of the model via the gain vector L. The estimation circuit can be built easily in SIMULINK. The poles of the estimation circuit can be prescribed and the gain L ensuring these closed-loop poles can be calculated using the Ackermann formula. The prescribed poles of the estimation circuit have to ensure a faster behaviour for the estimation circuit than the transient behaviour of the system itself. With this estimation circuit the estimated state variables approximate the time course of the system state variables. State feedback control can be realised then from the estimated state variables.

Page 60: Matlab Exercises for Introductory Control Theoryavalon.aut.bme.hu/education/contheor/contheor2/ContTheor_2004.pdf · Matlab Exercises for Introductory Control Theory Jen ... Introduction

State Feedback Control .

60

-

y∫ CB x x

A

u

D

∫x x

L

yCB

D

A

e

Model

System