You are on page 1of 38

LAB MANUAL EE-319 LAB XI ( CONTROL SYSTEMS USING MATLAB)

FIFTH SEMESTER (ELECTRICAL ENGINEERING) PREPARED BY

DR. RAJ KUMAR BANSAL ELECTRICAL ENGG. DEPARTMENT CHITKARA INSTITUTE OF ENGG. AND TECHNOLOGY RAJPURA

EE-319 LAB XI ( CONTROL SYSTEMS USING MATLAB) LIST OF EXPERIMENTS/EXERCISES


Exercise No.1 : INTRODUCTION TO MATLAB Exercise No.2 MATLAB AS A CALCULATOR Exercise No.3 VECTORS AND MATRICES Exercise No.4 PARTIAL FRACTIONS, POLYNOMIALS, TRANSFER FUNCTIONS Exercise No.5 TIME RESPONSES OF CONTROL SYSTEMS Exercise No.6 MATLAB GRAPHICS Exercise No.7 CONTROL STRUCTURES Exercise No.8 ROOT LOCUS PLOT OF CONTROL SYSTEMS Exercise No.9 FREQUENCY RESPONSE OF CONTROL SYSTEMS Exercise No.10 LTI VIEWER Exercise No.11 CONTROL SYSTEM SIMULATION USING SIMULINK

Exercise No.1 : Introduction to MATLAB MATLAB


stands for , MATrix LABoratory MATrix LABoratory It is a product of The Mathworks, Incorporated , USA. It is a Software Package for : Numerical , Scientific and Engineering computations and visualization IT PROVIDES : -Interactive environment -Hundreds of in - built functions for computations , -2D and 3D graphics and animation. -Several toolboxes which are collections of functions written for special applications. -Ease to use -Shallow learning curve i.e. more learning with less effort. -High Speed of Computations -Supports almost every computational platform like WINDOWS, UNIX, HPUX, LINUX, Solaris Operating Systems etc STARTING AND QUITTING MATLAB SESSIONS MATLAB can be started by double clicking the MATLAB short cut icon on the desktop. When MATLAB starts , MATLAB desktop as shown in Fig .1 , given below , will appear on the screen.

Fig.1 MATLAB Desktop - MATLAB desktop contains tools for managing files etc. and applications related to MATLAB. - After the work being done in MATLAB is over , select File >Exit MATLAB on the MATLAB tool bar to quit the MATLAB session Or - Type quit in the command window. quit MATLAB WINDOWS There are three main windows : -Command Window -Graphics/Figure Window -Edit Window COMMAND WINDOW -It is a main window -It has a MATLAB Command Prompt >> -All MATLAB Commands are typed in this window and are typed after the prompt symbol >> - All variables are entered in this window -All functions and M-file scripts are run in this window -Press the enter key to run any statement in the command window, after typing it. -Various arrow and control keys can be used to recall, edit , and reuse statements which have been typed earlier. - Press the up arrow key to call back a previously typed statement . GRAPHICS / FIGURE WINDOW -The output of all Graphics/Plot Commands , typed in the Command window is shown/flashed in the Graphics/Figure window -Depending on the system memory, many figure windows can be created by the user. EDIT WINDOW In this window, user can write, edit and save his/her own programs in files called , Mfiles . 4

-To create an M-file, select File >New - To edit an M- file , select File >open or Use the edit function SUB WINDOWS MATLAB sub windows are: COMMAND HISTORY SUBWINDOW WORKSPACE SUBWINDOW / WORKSPACE BROWSER 1. COMMAND HISTORY SUBWINDOW Statements that are entered in the command window are logged in the command history sub window. -Previously run statements can be viewed ,copied, searched from the command history. -M-file can be created from a set of selected statements. -Select one or more entries and right click to copy, evaluate or create an M file from the selection Click on the tab for this sub-window, if it is not there already in the foreground. EXAMPLE Create an m-file from the command history window Method : Type the following commands as a sample in the command window : t = linspace (0, 2 * pi, 100); x = cos(t); y = sin(t); plot (x, y) Go to the command history window Select all the four commands (shown above) in the Command History Window Right click, POP UP MENU will appear , which has following options : Cut, copy, evaluate selection, create M-file, delete selection etc. Select create M-file from these options. Editor window will be opened and will have all these commands typed in that window Thus Commands in the command history window can be tested and can be turned in to M-files easily 2. WORK SPACE SUBWINDOW / WORKSPACE BROWSER -MATLAB workspace keeps/stores a set of variables (named as arrays),created during any MATLAB session. -Information about each variable or the Workspace can be viewed by using the Workspace Browser. Or By using the functions who or whos - The workspace contents get deleted automatically after the MATLAB session is over. - To save the workspace to a file that can be read later on , select File > Save.

If the values of any variable are to be seen, double click the variable in the workspace browser . or Use the command: openvar var name Array Editor sub window will be opened , where the values can be seen and edited.

Any value in the array can be changed here. Select any variable and right click the mouse. Pop-up-menu will be displayed. Pop-up-menu Select any option from the pop-up-menu You can edit, graph or save the variable with a click of the mouse. FILE TYPES MATLAB has three types of files for storing information : M-files Mat-files Mex-files M-FILES -These are standard ASCII text files . -These have .m extension to the files name These are further of two types : -Script files -Function files MAT-FILES - These are Binary data files -Have .mat files extension to the file name -Can be loaded into MATLAB with the load Command / function - To read in a MAT file , select File>Import Data MEX-FILES -These are MATLAB callable Fortran and C programs -Have .mex extension to the file name

COMMONLY USED USEFUL COMMANDS clc Clears the command window Home Clears the command window clf Clears figure window pwd Prints current working directory dir Lists contents of the current directory clock Gives clock time and date as a vector date Gives date as a string ver Gives license and version information about MATLAB installed on the respective computer. clock Gives [year ,month, day, hour, minute, seconds] in integer form. fix(clock) Rounds to integer display format.

Exercise No.2 MATLAB AS A CALCULATOR


1. All arithmetic operations like addition, subtraction, multiplication, division, exponentiation etc. can be done easily in MATLAB. 2 .Arithmetic operators used are : + for Addition for Substraction * for Multiplication / for Division ^ for Exponentiation Example 2.1: cd 2 Calculate ; f = (a + b )
e

for

a = 1, b = 2, c = 3, d = 4, e = 5

Solution : Following MATLAB commands will be used : a=1; b=2; c=3 ; d=4; e=5; f = (a + b- c*d / e)^2 Press enter key Following answer will be displayed : f = 0.3600 Complex Numbers Complex numbers consist of two parts i.e. a real part and an imaginary part. Imaginary parts use either i or j as a suffix. Both of these suffixes are accepted by MATLAB. MATLAB predefines i = j = 1 . Creation of complex numbers Suppose it is desired to create a complex number , x = - 4 + i 8 This complex constant can be easily created by using any of the following statements: x = -4+j*8 or x = -4+8 j or x = -4+8*j These statements will assign the complex constant -4 + j8 to the variable x, i.e. x = -4.0000 + 8.0000i The real and imaginary components of x can be separated by using the following commands: x_real = real(x); x_imag = imag(x); On execution, these will give the result as : x_real = -4 and x_imag = 8 The command conj(x) will produce the complex conjugate of x i.e. x = -4.0000 - 8.0000i (d) Magnitude and Angle of a Complex Number Following commands can be used to obtain the magnitude: (i) x_mag = sqrt (x_real^2 + x_imag^2) (ii) x_mag = abs(x) Phase angle of a complex number can be obtained by using angle command as follows and angle is obtained in radians: x_rad = angle(x) Angle of complex variable x can also be obtained using arc-tangent function as follows: x_rad=atan(x_imag/x_real) CONVERSION OF CO- ORDINATE SYSTEM The commands [theta, r] = cart2pol (x,y), converts the Cartesian coordinates x and y into polar coordinates ,angle theta and radius r, as explained below: Suppose Cartesian coordinates of a complex number are: x = 1 and y = 1 Then the command : [theta, r] = cart2pol (1,1) will produce the following result. theta = 0.7854 (in radians) r = 1.4142

The following command converts the polar coordinates into Cartesian coordinates : The command : [x, y] = pol2cart (0.7854, 1.4142) will produce the result: x=1 y=1

Exercise No.3

VECTORS AND MATRICES ENTERING OF VECTORS A row vector p = [1 2 4] can be entered as follows: p = [ 1 2 4] or p = [1, 2, 4] i.e. All the elements are enclosed in square brackets and are separated from each other by blank spaces or commas. A column vector ,

2 q = 4 is entered as : 100 q = [2 ; 4 ; 100] i.e. All the elements of the col. vector are separated by semi colons. ENTERING OF MATRICES Elements are entered row wise and the different rows are separated by semi colons. A given matrix A can be entered as follows : Suppose A is a 2 2 matrix and is equal to 5 4 A= 100 20 Then the MATLAB command. A = [4 5 ; 100 20] Will enter the elements of matrix A in the command window. It may be noted that these elements are entered row wise and the different rows are separated by semi colons. OPERATIONS ON VECTORS AND MATRICES Vector transpose The command y = x will transpose the given vector x into a transposed vector y. mean (x) Gives the average of the elements of a row/column vector, x. length (x) Gives the number of elements in the vector x. max (x) Gives the max. value in the row or col. Vector x. min (x) Gives the minimum value in the vector x. prod (x) Gives the product of the elements of the vector x. MATRIX RELATED COMMANDS 1. eye (n), produces identity matrix of order n. 2.zeros(n) produces (nn)matrix, 2.zeros(n) elements as zeros. 3.ones(n), produces (nn)matrix, 3.ones(n), elements as ones. 4. size (A) gives the dimensions of matrix A. 5. det (A) calculate the determinant of matrix A. 6. rank (A) calculate the rank of matrix A. 7. eig (A) calculate the eigen values of matrix A. with with all all

10

8.trace(A)calculate the sum 8.trace(A)calculate elements of matrix A. 9.diag(A) returns the diagonal 9.diag(A) matrix A. 10. inv (A) calculates the inverse of matrix A. 11. plus (A,B) adds two matrix A & B. 12. minus(A,B) subtracts matrix B from matrix A. 12. minus(A,B) 13. mtimes(A,B) multiplicity two matrix A and B. 13. 14. A Returns the transpose of the matrix A.

of elements

diagonal of

Exercise No.4
PARTIAL FRACTIONS , POLYNOMIALS AND TRANSFER FUNCTIONS Following MATLAB command can be used to obtain the partial fractions of a ratio of two polynomials n and d : [r, p, k] = residue (n, d) The residues are returned in column vector r , the pole locations in column vector p and the direct terms in row vector k. If k = 0, it means there is no direct term. Example 4.1 :

11

Obtain the partial fractions of the following : (s+ 1) G(s) = 3 (s + 7 s 2 + 16 s + 12) Solution Following MATLAB commands can be used : n = [1 1]; d = [1 7 16 12] [r, p, k] = residue (n, d); Following results will be displayed : r = [0.667 -0.75 0.5 0.0833], p = [-3 -2 -2 0], k = [ ]. Hence partial fractions of G(s) are = 0.667 0.75 0.5 0.0833 + + + 2 (s + 3) (s + 2) (s + 2) (s + 0)

POLYNOMIALS -It is represented as a row vector -It is entered with coeff. of s terms in descending order -Multiplication command to multiply two polynomials is : conv(p1, p2) -Given polynomials p1 and p2, multiply them to get p3 p3=conv(p1,p2) Example 4.2 : Given polynomial , p1 = (s+1) and polynomial , p2 = (s2 + 2s +1), multiply p1 and p2 to get resultant polynomial q Solution Following MATLAB commands can be used : p1=[1 1]; p2=[1 2 1]; q = conv(p1, p2) The results obtained will be : q= 1 3 3 1 i.e. polynomial q is: q = s3 +3 s2 +3 s +1 TRANSFER FUNCTIONS Transfer functions of control systems are represented as a ratio of two polynomials in s that is;

12

n (s) d (s) Hence MATLAB commands to represent transfer functions are : Any Variable name= tf (n, d) e.g. sys = tf (n, d) where sys is any variable name. However the command : [n,d] = tfdata (sys, v) will reproduce the numerator and denominator polynomials of the transfer function sys. ZEROS AND POLES OF TRANSFER FUNCTIONS zeros and poles of transfer functions can be obtained by the following command: G (s) = [z, p, k] = tf2zp(n, d) tf2zp(n, where z ,p,k represent zeros, poles and constant gain respectively. The command , [n, d] = zp2tf(z, p, k) will give numerator and denominator polynomials zp2tf(z, of the transfer function The command , pzmap(n, d) plots pole-zero map of the transfer function . The command , printsys(n, d, s) prints transfer function as a ratio of two polynomials in the variable s TWO SYSTEMS CONNECTED IN SERIES/PARALLEL/FEEDBACK Let the transfer functions of two systems be given by: n1 ( s ) n2 ( s) G1(s) = G 2(s) = d1 ( s ) d 2 ( s) SERIES CONNECTION [ns,ds]= series(n1, d1, n2, d2) printsys(ns,ds) PARALLEL CONNECTION [np,dp] = parallel(n1, d1, n2, d2) printsys(np,dp) FEEDBACK CONNECTION [nf,df] = feedback(n1, d1, n2, d2) printsys(nf,df) Example 4.3 : Transfer functions of two systems are given as follows. Find the overall transfer function ,when they are connected in ( i ) series( ii ) parallel (iii ) feedback s +1 4 G1 (s) = and G 2 (s) = 2 s +1 s + 2s + 4 SOLUTION Part (i) n1= 4; d1= [1 1]; sys=tf(n1,d1) 13

Transfer function: 4 ----s+1 n2=[1 1]; d2=[1 2 4]; sys=tf(n2,d2) Transfer function: s+1 ------------s^2 + 2 s + 4 [ns,ds]=series(n1,d1,n2,d2) ns = 0 0 4 4 i.e. 4s +4

ds = 1 3 6 4 i.e. s3 +3 s2 +6 s +4 Part (ii) [np,dp]=parallel(n1,d1,n2,d2) np = 0 5 10 17

dp = 1 3 6 4 Part (iii) [nf,df]=feedback(n1,d1,n2,d2) nf = df = 0 1 4 8 16 8

3 10

Exercise No.5
TIME RESPONSE OF CONTROL SYSTEMS Time response of a control system can be obtained by using the following test inputs : STEP IMPULSE RAMP STEP RESPONSE n (s) Given the open loop Tr.Function. , G(s) H(s) = , d (s)

Following MATLAB commands can be used to obtain step response: step(n,d) 14

or sys =tf(n, d); step(sys) If left hand arguments are used , [y,x,t]=step(n, d, t); plot(t, y) Example 5.1 Obtain the step response of the following system : 4 G(s)= 2 s + 2s + 4 Solution : Following MATLAB commands can be used : n=4; d=[1 2 4 ] ; step(n, d) grid title(response of 4/(s^2+2s+4)) Time response of the system as shown in the figure given below will be obtained :
s pre p n eo 4 te s o s f /(s 1 .4
2

+s 4 2 +)

1 .2

A plitude m

0 .8

0 .6

0 .4

0 .2

0 0

3 T e(s c im e )

Fig 5.1 Step response for Example 5.1 Use of plot command to plot the step response : n=4; d=[1 2 4 ] ; [y,x,t]=step(n, d, t); plot(t, y) grid title(time response for t=0 to 5 secs) Time response of the system as shown in the figure given below will be obtained

15

tim re p n ef rt= to5s c e s os o 0 es 1 .4

1 .2

0 .8

0 .6

0 .4

0 .2

0 0

0 .5

1 .5

2 .5

3 .5

4 .5

fig 5.2 step response for Example 5.1 EXAMPLE 5.2 Obtain the step response of the following system from t = 0 to 2 secs. in steps of 0.05, using (i) step command only (ii) step command and plot command 144 G(s) = 2 s + 12s + 144 Solution: Following MATLAB commands can be used:(i) n = 144; d = [1 12 144 ]; t = 0 : 0.05: 2; step (n, d, t) grid Time response of the system will be as shown in the Figure 5.3
Sp epn t R os e s e 1 . 4 1 . 2 1

A p d m litu e

0 . 8

0 . 6

0 . 4

0 . 2

0 0

0 . 2

0 . 4

0 . 6

0 . 8

1 Tesc i ( e) m

1 . 2

1 . 4

1 . 6

1 . 8

Fig 5.3 step response for Example 5.2 (ii) t = 0: 0.05: 2; n = 144 ; d = [1 12 144 ] [y, x, t] = step (n, d, t); [y, t] or [t, y] plot (t, y) grid xlabel (time secs) ylabel (amplitude) Time response of the system as shown in the figure given below will be obtained

16

1.4

1.2

amplitude y

0.8

0.6

0.4

0.2

0 0

0.2

0.4

0.6

0.8

1 1.2 time secs

1.4

1.6

1.8

Fig 5.4 step response for Example 5.2 STATE SPACE REPRESENTATION OF CONTROL SYSTEMS x = Ax + BU y = Cx + DU MATLAB command used is: step (A, B, C, D) or step (A, B, C, D,iu, t) or [y, x, t] = step (A, B, C, D, iu) or [y, x, t] = step (A, B, C, D, iu, t) Where t is to be specified by the user and iu is an index specifying which input is to be used for the response. i.e. iu= 1, 2, 3 etc. Example 5.3: A control system having 2 inputs and 2 outputs is described by the following state equations: 0 1 1 1 1 0 4 2 x + 0 2 u x = 0 1 1 0 10 1 0 1 D=0 2 1 3 x, Obtain the step responses for all the inputs Solution : Following MATLAB commands can be used: A = [-1 1 0; 0 4 2; 0 0 -10]; B = [1 1 ; 0 2 ; -1 1]; C= [ 1 0 1; 2 1 3]; D=0 step (A, B, C, D) grid It will give four figures corresponding to 2 inputs and 2 outputs as shown in the figure given below,i.e. (i) input 1/output 1 y= 17

(ii) input 1/output 2 (iii) input 2/output 1 (iv) input 2 /output 2


Sp epne t R os e s Fm( ) r :I 1 o n 2 1 . 5 T : O t(1 o u ) 1 0 . 5 A p d m litu e Fm( ) r :I 2 o n

0 4 3 T : O t(2 o u )

2 1

0 0

6 0 Tesc i ( e) m

Fig 5.5 step response for Example 5.3 IMPULSE RESPONSE Following MATLAB commands can be used to obtain Impulse Response : impulse (n, d) or [y, x, t]=impulse (n, d) EXAMPLE 5.4 Obtain the impulse response of the following system from t = 0 to 2 secs. in steps of 0.05, using impulse command . 144 G(s) = 2 s + 12s + 144 Solution : Following MATLAB commands can be used:(i) n = 144; d = [1 12 144 ]; t = 0 : 0.05: 2; impulse (n, d, t) grid Impulse response of the system as shown in the figure given below will be obtained
I pl e epne m s R os u s 7 6 5 4 A p d m litu e 3 2 1 0 1 2

0 .2

0 .4

0 .6

0 .8

1 T esc im( e)

1 . 2

1 .4

1 . 6

1 .8

Fig 5.6 impulse response for Example 5.4 18

RAMP RESPONSE No ramp command is available in MATLAB Divide the given transfer function by s and use step command i.e. G (s ) Find and use step command. s Example 5.5 : 30 Obtain ramp response of the system G(s)= 2 s + 5s + 30 Solution : 30 G (s ) 1 = 2 s s s + 5s + 30 G (s ) 30 i.e. = 3 s + 5s 2 + 30s s Following MATLAB commands can be used : n= [30]; d=[1 5 30 0] step (n, d) grid Ramp response of the system as shown in the figure given below will be obtained
Step Response 1500

1000

Amplitude 500 0 0

500 Time (sec)

1000

1500

Fig 5.7Ramp response for Example 5.5

Exercise No.6 MATLAB GRAPHICS


MATLAB has very good facility for 2-dimensional and 3-dimensional plots Two Dimensional Plots To draw a 2-dim. plot, following command is used : plot (x, y) Where x is the independent variable and y is the dependent variable. Labels on the graph can be printed by typing the following commands:

19

xlabel (character string containing the label to be given on x-axis.) ylabel (character string containing the label to be given on y-axis) title (character string containing the title of the plot) To give better illustration of the co-ordinates, grid can be plotted in the graph using the command : grid. Text can be entered in a plot using command: text (x-coordinate, y-coordinate, text to be entered) EXAMPLE 6.1 Draw a plot for the equation x = 10e-t, for t = 0 to 5. Give proper title, plot grid and label the axes . Enter the text Exponential decay at t=1.5 and x=3,on the graph. Solution : Following MATLAB commands can be used: t = 0: 0.1:5; x = 10*exp(-t); plot (t, x); xlabel ( Time (t) in secs ) ylabel (output Response x ) title (plot of an exponential function) grid on; text (1.5, 3, Exponential decay)
p t o a ep n n l f ntio lo f n x oetia uc n 1 0 9 8 7 o tp t re o se x u u sp n 6 5 4 3 2 1 0 0 e p nn l d c y x o etia e a

0 .5

1 .5

2 2 .5 tim ( ins c e t) es

3 .5

4 .5

Fig 6.1 Plot for Example 6.1

Exercise No.7
CONTROL STRUCTURES for LOOP STATEMENT - Used for unconditional looping - A group of statements are executed repeatedly for a fixed number of times , say n number of times. Its General Form is: for index = Initial value : incr : last value
statement 1;

20

statement 2; : : statement n;

end; Example7.1: Obtain the sum of even numbers from 0 to 8 using for loop. Solution: Following MATLAB commands can be used: sum = 0; for k = 0: 2 : 8 sum = sum + k; end; sum Upon execution , it will give the answer as: 20 if Control Structure - The statement allows some action to be taken only if the given logical condition is true: - A group of statements is executed if some condition is satisfied. General form of this structure is: if condition to be checked Statement 1 ------------statement n end; Example 7.2: Write a program to check whether the given number i.e. say 60 , is equal to or greater than 50. Solution: a = 60; if a>= 50 disp (yes, The number is greater than or equal to 50) end; disp (no, The number is less than 50) Upon execution , it will give the answer as: yes, The number is greater than or equal to 50
Example 7.3Write a program to evaluate y = 2x, if x < 4 other wise y = 2 +x , using if else- end statement:

21

Solution x = input(Enter the value of x:); if x < 4, y = 2*x else y = 2 +x; end; The statement y = 2x is executed if the condition is true and otherwise, the statement associated with else i.e. y = 2 +x is executed. If x = 2 is entered , then answer will be y = 4 If x = 6, is entered then answer will be y = 8 7.3 while LOOP STATEMENT A while loop is used for executing a group of statements repeatedly on the basis of a condition statement.. The general form of while loop is given as: while <condition>, statement 1; statement 2; : : statement n; end; The statements are executed repeatedly as long as the condition or expression remains true (non zero).. When the condition becomes false (zero), the program will come out of the loop and control will be transferred to the next statement after the end statement.

Example 7.4
Program to illustrate use of while loop for finding square of numbers less than 4: k = 0; while k < 4, k = k + 1; ns = k ^ 2; end; ns,k Following answer will be displayed: ns =16, k = 4 Example 7.5 Write a Program to add first 6 digits using while loop statement: n = 0; sum = 0; while n < 7 sum = sum + n; n = n + 1; end; sum Following answer will be displayed: ans. sum = 21

22

Exercise No.8

ROOT LOCUS Location of closed loop poles gives an idea about stability of a system. With the variation of system parameters, location of these poles changes. Location of these poles can be found by finding the roots of the system characteristic equation. Root- locus technique is a graphical method for finding the roots of a characteristic equation. Root locus may be defined as the plot of the closed loop poles, as a function of gain K, as K is varied from 0 to n (s) Given the open loop Tr.Fn. , G(s) H(s) = d (s) MATLAB commands to plot root-locus are:rlocus (n, d) or [r, k] = rlocus (n, d, k) Root locus using plot command : MATLAB commands are:r = rlocus (n, d) plot (r, O) EXAMPLE 8.1 : Plot root locus and examine the stability of the following system : 0 .4 K G(s) H(s) = 3 s + 2s 2 + 4s + 5 (a) (b) Solution part(a) part(a) n = 0.4 d = [1 2 4 5] rlocus (n, d) Root locus as shown in the figure given below will be obtained :
Ro L c s ot o u 1 0 8 6 4 Im agin ary A xis 2 0 -2 -4 -6 -8 -1 0 -1 0

if K is varied for 0 to K = 1 to 5.

-5 RaA is el x

Fig 8.1 Root locus plot for Example No. 8.1(a)

23

k=1:5 n = 0.4 d = [1 2 4 5] rlocus (n, d, k) Root locus as shown in the figure given below will be obtained :

(b)

Ro L c s o t ou 2 .5 2 1 .5 1 0 .5 0 -0 .5 -1 -1 .5 -2 -2 .5 -2

Im aginary A xis

-1 .5

-1 Ra A is el x

-0 .5

0 .5

Fig 8.2 Root locus plot for Example No. 8.1(b) Example 8.2 : G(s) H(s) = k (s + 1) s 2 (s + 2)

Solution : Following MATLAB commands can be used : n = [1 1] d = [1 2 0 0] rlocus (n, d) Root locus as shown in the figure given below will be obtained :
R tLcs o ou o 8 6

Im g a A a in ry xis

8 -. 2 5

-. 1 5

1 R lAis e x a

-. 0 5

0 . 5

Fig 8.3 Root locus plot for Example No. 8.2 If following commands are used : p= rlocus (n, d); plot (p) Following plot will be obtained:

24

150

100

50

-50

-100

-150 -2

-1.8

-1.6

-1.4

-1.2

-1

-0.8

-0.6

-0.4

-0.2

Fig 8.4 Root locus plot for Example No. 8.2 POLAR GRID LINES ON ROOT LOCUS Following MATLAB commands can be used to plot grid lines on the root locus: sgrid plots grid lines of constant damping ratio and constant natural freq. The command : sgrid ( , wn) plots grid lines for given damping ratio , and given natural freq, wn e.g. if 1 = 0.2 , 2 = 0.7 , wn1 = 0.5 , wn2 = 1, wn3 = 2 Then the command : sgrid ([0.2 0.7], [0.5 1, 2] ) Will plot grid lines for = 0.2 and 0.7 and for wn = 0.5, 1, and 2 and the command: sgrid (0.5, 1.5) Will plot grid lines for = 0.5 and wn = 1.5 FINDING GAIN K ON ROOT LOCUS Following MATLAB command can be used: [K, r] = rlocfind (n, d) where r is the column.-vector giving the location of roots corresponding to gain K. This command shifts the control to the root locus figure window and a cross- hair cursor will appear on the screen. This cursor can be used to select the exact point on the root locus, where value of K is to be obtained. Following answer will be displayed in the command window immediately after a point is selected on the root locus : Selected point: : K = R = EXAMPLE 8.3 K G(s) = 2 s(s + 2s + 3) Draw grid lines for = 0.4 and find gain K at the point on the grid line, intersecting the root locus Solution : Following MATLAB commands can be used : n = [0 0 0 1]; 25

d = [1 2 3 0]; rlocus (n, d) sgrid (0.4, [ ]) %only =0.4 Root locus as shown in the figure given below will be obtained :
Root Locus 8 0.4 6

2 Imaginary Axis

-2

-4

-6 0.4 -8 -10 -8 -6 -4 -2 Real Axis 0 2 4

Fig 8.5 Root locus plot for Example No. 8.3 [K, r] = rlocfind(n, d) On pressing the enter key , a cross hair will appear in the figure window. Select the desired point on the root locus with a mouse. Following answer will be displayed in the command window immediately after a point is selected on the root locus : Select a point in the graphics window selected_point = -0.5284 + 1.2671i k = 1.8463 r= -0.5399 + 1.3095i -0.5399 - 1.3095i ROOT LOCUS PLOT(STATE SPACE FORM) Following MATLAB commands can be used : rlocus (A, B, C, D) or [r, K] = rlocus (A, B, C, D, iu, K) Example 8.4 A control system is described by the following state equations:
0 = 0 120 1 0 40 0 1 x + 10

y = [1

0] x

0 1 1 0

D=0 26

Obtain the root locus. Solution : Following MATLAB commands can be used: A = [0 1 0; 0 0 1; -120 40 -10]; B = [0 ; 1 ; -10]; C = [ 1 0 0]; D=0 rlocus(A, B, C, D) sgrid Root locus as shown in the figure given below will be obtained :
R t Locus oo 40 0.19 30 0.3 20 0.55 0.13 0.095 0.065 0.04 40 0.018 35 30 25 20 15 10 Imaginary Axis 10 5 0 5 -10 0.55 10 15 -20 0.3 -30 0.19 -40 -8 -7 -6 0.13 -5 0.095 -4 -3 0.065 -2 0.04 20 25 30 0.018 35 -1 40 0 1

R Axis eal

Fig 8.6 Root locus plot for Example No. 8.4

Exercise No.9 FREQUENCY RESPONSE OF CONTROL SYSTEMS


Frequency response can be represented in any of the following forms: -Bode plots or logarithmic plot -Nyquist plot or polar plot -Nichols chart or log mag. v/s phase plot.

27

To plot the freq. response, a vector of frequencies is created in a given range and system response is obtained using the given open loop transfer function. BODE DIAGRAMS Bode diagrams are logarithmic plots. It has two graphs : (i) One is a plot of log of mag v/s freq on log scale (ii) Other is a plot of phase angle v/s freq. on log scale Following MATLAB command can be used to plot bode diagrams, for a given open loop transfer function : bode (n, d) Logarithmic freq. range can be obtained using the command: w= logspace (n1, n2, k) It will generate k values of w, logarithmically equally spaced between the values: 10 n1 and 10 n2 e.g. the command: w = logspace (-2, 3 , 100) will generate 100 points in the range of: 10-2 to 103 i.e. 0.01 to 1000 rad/sec The following commands will plot bode diagrams for given values of frequency: bode (n, d, w) The following command will not plot bode diagrams. However it returns the freq response in vectors containing mag., phase angle and freq. w [mag, phase, w] = bode (n, d, w) GAIN AND PHASE MARGIN Following MATLAB commands can be used to obtain the values of phase cross over freq., gain cross over freq., gain margin and phase margin: margin(n,d) [gm,pm,pcf,gcf]=margin(n,d) where, gm - gain margin , pm- phase margin pcf - phase cross over freq. , gcf - gain cross over freq.

Example 9.1 : A control system is described by the following transfer function. Obtain the bode diagrams in the freq range of .01to 1000 rad/sec. 10 i.e. G(s) = 2 s + 2s + 10 Solution : Following MATLAB commands can be used: w = logspace (-2, 3, 100) 28

n = 10; d = [ 1 2 10]; bode(n,d,w) grid margin(n,d) [mag,phase,w] = bode(n,d,w); [mag,phase,w] Following results will be obtained : ans = mag Phase w 1.0e+003 * 0.0010 -0.0001 0.0000 0.0010 -0.0001 0.0000 0.0010 -0.0001 0.0000 0.0010 -0.0002 0.0000 0.0010 -0.0002 0.0000 0.0010 -0.0002 0.0000 0.0010 -0.0002 0.0000 0.0010 -0.0003 0.0000 0.0010 -0.0003 0.0000 0.0010 -0.0003 0.0000 0.0010 -0.0004 0.0000 0.0010 -0.0004 0.0000 0.0010 -0.0005 0.0000 0.0010 -0.0005 0.0000 0.0010 -0.0006 0.0001 0.0010 -0.0007 0.0001 0.0010 -0.0007 0.0001 0.0010 -0.0008 0.0001 0.0010 -0.0009 0.0001 0.0010 -0.0010 0.0001 0.0010 -0.0012 0.0001 ---------------------------------------------------0.0000 -0.1799 0.8902 0.0000 -0.1799 1.0000 [gm,pm,pcf,gcf]= margin(n,d) gm = Inf pm = 53.1445

29

pcf = Inf gcf = 3.9995 Bode diagram as shown in the figure given below will be obtained :
Bode D iagram G = Inf dB (at Inf rad/sec) , P = 53.1 deg (at 4 rad/sec) m m 20

0 Magnitude (dB) Phase (deg)

-20

-40

-60 0 -45 -90 -135 -180 10


-1

10

10 Frequency (rad/sec)

10

Fig 9.1 Bode plot for Example No. 9.1 BODE DIAGRAMS FOR STATE SPACE REPRESENTATION Following MATLAB commands can be used: bode (A, B, C, D) bode(A,B,C,D,iu,w) Where w is user supplied freq. vector iu is an index specifying which input is to be used for the response. Example 9.2 Obtain the bode diagram for the following system given in state space form: x = 20
0 1 0 x + 20 u 2

y = [1 0] x Solution : Following MATLAB commands can be used: A = [0 1 ; -20 -2]; B = [0 ; 20]; C= [ 1 0 ]; D=0 bode(A, B, C, D) Bode diagram as shown in the figure given below will be obtained :

30

Bd D m o e iagra 20

0 M agnitude (dB) Phase (deg)

-2 0

-4 0

-6 0 0 -4 5 -9 0 -1 35 -1 80 1 0
-1

1 0

10 F que re ncy (ra d/sec)

10

Fig 9.2 Bode plot for Example No. 9.2 NYQUIST PLOT It is a plot of g(jw) v/s angle g(jw) for the freq. range <w < Following MATLAB commands can be used: nyquist (n, d) nyquist (n, d, w) To obtain the real and imaginary values of transfer function at different values of w ,following commands can be used: [re, im, w] = nyquist (n, d) [re, [re, im, w] = nyquist (n, d, w) where w varies over a given range Example 9.3 Consider the following open loop transfer function : 1 i.e. G(s) = 2 s + s +1 Draw the nyquist plot. Solution : Following MATLAB commands can be used: n = 1; d = [ 1 1 1]; nyquist(n,d) grid v=[-2 2 2 2]; axis(v) Nyquist plot as shown in the figure given below will be obtained :

31

N u Dg m yq ist ia ra 2 2d B 1 .5 4d B 1 6d B 0 .5 Im aginary Axis 1 d 0 B 2 d 0 B 0 -6d B -1 d 0 B -2 d 0 B -4d B 0d B -2d B

-0 .5

-1

-1 .5

-2 -2

-1 .5

-1

-0 .5

0 R a Axis el

0 .5

1 .5

Fig 9.3 Nyquist plot for Example No. 9.3 Example 9.4: Draw the Nyquist plot for the system described by the following state equations. x = x + u 10 20 4 y = [1 0] x Solution : Following MATLAB commands can be used: A = [0 1 ; -20 -4]; B = [0 ; 10]; C= [ 1 0 ]; D=0 nyquist(A, B, C, D) grid Nyquist Plot as shown in the figure given below will be obtained :
N yquist D iagram 0.8 4 dB 0.6 6 dB 2 dB 0 dB -2 dB -4 dB -6 dB

0.4

10 dB

-10 dB

0.2 Imaginary Axis 20 dB 0 -20 dB

-0.2

-0.4

-0.6

-0.8 -1

-0.8

-0.6

-0.4

-0.2 R Axis eal

0.2

0.4

0.6

Fig 9.4 Nyquist plot for Example No. 9.4 NICHOLS CHART Nichols co-ordinate system has gain in db on y-axis and phase angle in degrees on xaxis. 32

Origin is at mag.G= 0 db, and angle G= -180 deg. MATLAB command to be used is: nichols(n,d) Example9.5 : A control system is described by the following transfer function. Obtain the Nichols chart. 10(s + 1) i.e. G(s) = 3 s + 7s 2 + 10s + 6 Solution : Following MATLAB commands can be used: n = [10 10]; d = [ 1 7 10 6]; nichols(n,d) grid Nicholas chart as shown in the figure given below will be obtained :
Nh lsCa ic o h rt 4 0 0d B 0 5d .2 B 0 d .5 B 1d B 3d B 6d B O e -L o G in (d ) pn op a B 0

2 0

-1d B -3d B - d 6B -1 d 2B

-2 0

-2 d 0B

-4 0

-4 d 0B

-6 0

-6 d 0B

-8 0 -3 0 6

-8 d 0B -3 5 1 -2 0 7 -2 25 -1 0 8 -1 5 3 -9 0 -4 5 0 Oe - o pPa e( e ) p nL o h s d g

Fig 9.5 Nicholas chart for Example No. 9.5

33

Exercise No.10
LTI VIEWER It is a graphical user interface that simplifies the analysis of linear time invariant systems. Time and frequency response plots can be generated and performance specifications such as rise time , maximum overshoot and stability margins etc. can be inspected. Suppose the system to be studied is sys Type ltiview in the command window, an empty window will appear. Select import under the file menu ,LTI Browser dialog box will open . Select the system to be studied i.e. sys in this case, from the dialog box and click O.K. LTI Viewer will open and Default plot is a step response. Or For a given system , following MATLAB commands can be used in the command window : n = -----d = -----sys= tf(n,d) The command: ltiview(sys) will show a default plot, which is a step response. Or The command: ltiview(step,sys) will show a step response of the system sys.. USING THE RIGHT CLICK MENU Different controls and options available in lti viewer are: plot type - changes the plot type systems selects the model to be studied characteristics displays the response characteristics grid adds grid to the plot properties - opens the property editor Example 10.1 Obtain the different types of control system responses for the control system , whose transfer function is as given below:

34

G (s ) =

Solution : Following MATLAB commands can be used : n= 10; d=[1 2 10 ]; sys = tf(n,d) ltiview(sys) Default step response will be obtained as shown in the figure given below:

10 s + 2 s + 10
2

Fig 10.1 STEP RESPONSE plot for Example No. 10.1 Bode diagrams will be obtained as shown in the figure given below :

Fig 10.2 Bode plot for Example No.10.1 Nyquist plot will be obtained as shown in the figure given below:

35

Fig 10.3 Nyquist plot for Example No. 10.1

36

Exercise No.11 SIMULINK


SIMULINK is a software package used for modeling, simulation and analysis of dynamic systems. STARTING SIMULINK 1. Type : Simulink in the command window. Simulink library browser will open. Or 2. 3. Click : Simulink Icon in the MATLAB Toolbox.

(A) (B)

Click : MATLAB Start Button. Select : Simulink Library Browser. Opening / Creating a Model Select File New Model in the simulink library browser tool bar. An empty model window will open, where the desired model can be created. Creating A Simple Model 1. Select appropriate blocks one by one, as required, from the simulink library browser. 2. Drag them and drop them in the model window. 3. Unconnected blocks will appear in the model window. 4. Each block will have input / output ports as shown below :

Input Port (C)

Output Port

Fig 11.1 Drawing Lines Between Blocks/ Connecting blocks 1. Position the mouse pointer over the output port on the R.H.S. of a block. Pointer will change to a cross hair (+) shape, while it is on the port. 2. Drag a line from the output port of the first block to the input port of the next block. A dashed Line is drawn while you hold the mouse button down and pointer changes to double lined cross hair as it approaches the input port of the next block. 3. Release the mouse button. A solid line will be drawn connecting the two blocks. Shortcut Method : 37

(i) Select the block from where line is to be drawn. (ii) Press CTRL key. (iii) Click the block where the line is to be connected. A solid line will be drawn connecting the two blocks. (D) SETTING BLOCK PARAMETERS Double click different blocks and set their parameters , wherever required (E) Simulation Select SIMULATION from the model window toolbar and start simulation. OR Start simulation by selecting the start simulation icon , provided on the tool bar. (F) SIMULATION RESULTS Observe the system response on the scope by double clicking it. EXAMPLE 11.1 Simulate the control system whose block diagram is as given below :
1 s Step Integrator 4 s2 +4 +4s Trans Fcn fer Scope

1 Gain

Fig. 11.2 Block diagram of a control system SOLUTION Create the simulink model using the procedure described and set block parameters. Start simulation Upon simulation , following response will be displayed on the scope.

Fig. 11.3 Response of the system given in Example 11.1

38

You might also like