Вы находитесь на странице: 1из 205

MATLAB MODULE 1

MATLAB Window Environment and the Base Program

Starting MATLAB
On the Windows desktop, the installer usually creates a shortcut icon or starting MATLAB! dou"le#clicking on this icon opens MATLAB desktop$

The MATLAB desktop is an integrated development environment or working with MATLAB suite o tool"o%es, directories, and programs$ We see in &ig$ M'$' that there are our panels, which represent( 1. Command Window 2. Current Directory 3. Workspace 4. Command History A particular window can "e activated "y clicking anywhere inside its "orders$

Fig. M1.1 MATLAB Desktop !ersion ".#$ re%ease 14&

)esktop layout can "e changed "y ollowing )esktop ##* )esktop Layout rom the main menu as shown in &ig$ M'$+ ,)e ault option gives &ig$ M'$'-$

Fig. M1.2 C'an(in( Desktop Layout to History and Command Window option

Command Window
We type all our commands in this window at the prompt , ** - and press return to see the results o our operations$ Type the command ver on the command prompt to get in ormation a"out MATLAB version, license num"er, operating system on which MATLAB is running, .A/A support version, and all installed tool"o%es$ 0 MATLAB don1t regard to your speed o reading and lush the entire output at once, 2ust type more on "e ore supplying command to see one screen o output at a time$ 3licking the What1s 4ew "utton located on the desktop shortcuts tool"ar, opens the release notes or release '5 o MATLAB in 6elp window$ These general release notes give you a 7uick overview o what products have "een updated or 8elease '5$ Working with Command Window allows the user to use MATLAB as a versatile scienti ic calculator or doing online 7uick computing$ 0nput in ormation to "e processed "y the MATLAB commands can "e entered in the orm o num"ers and arrays$ As an e%ample o a simple

interactive calculation, suppose that you want to calculate the tor7ue , T - acting on 9$' kg mass , m - at swing o the pendulum o length , % - 9$+ m$ &or small values o swing, T is given $ This can "e done in the MATLAB command window "y typing( "y the ormula

>> torque = 0.1*9.8*0.2* i!" MATLAB responds to this command "y( torque = 0.102" MATLAB calculates and stores the answer in a varia"le torque ,in act, a array- as soon as the Enter key is pressed$ The varia"le torque can "e used in urther calculations$ is prede ined in MATLAB! so we can 2ust use i without declaring it to "e :$'5;$3ommand window indicating these operations is shown in &ig$ M'$:$

Fig. M1.# Command Window )or *uick scienti)ic ca%cu%ations , te+t in co%ored ,o+es corresponds to e+p%anatory notes -$

0 any statement is ollowed "y a semicolon, >> $ = 0.1%

>> & = 0.2% >> g = 9.8% the display o the result is suppressed$ The assignment o the varia"le has "een carried out even though the display is suppressed "y the semicolon$ To view the assignment o a varia"le, simply type the varia"le name and hit Enter$ &or e%ample( >> torque=$*g*&* i!"% >> torque torque = 0.102" 0t is o ten the case that your MATLAB sessions will include intermediate calculations whose display is o little interest$ Output display management has the added "ene it o increasing the e%ecution speed o the calculations, since displaying screen output takes time$ /aria"le names "egin with a letter and are ollowed "y any num"er o letters or num"ers ,including underscore-$ <eep the name length to :' characters, since MATLAB remem"ers only the irst :' characters$ =enerally we do not use e%tremely long varia"le names even though they may "e legal MATLAB names$ >ince MATLAB is case sensitive, the varia"les A and a are di erent$ When a statement "eing entered is too long or one line, use three periods, ' , ollowed "y to indicate that the statement continues on the ne%t line$ &or e%ample, the ollowing statements are identical ,see &ig$ M'$5-$ >> (=#)**+,10! i,-.".8,..890,2/2)1.89 >> (=#)**+,10! i,-.".8... ,..890,2/2)1.89 , addition, operators$ su"traction, ? multiplication, @ division, and A power are usual arithmetic

The "asic MATLAB trigonometric commands are 0in, 1o0, tan, 1ot, 0e1 and 101$ The inverses , etc$, are calculated "y a0in, a1o0, etc$ The same is true or hyper"olic unctions$ >ome o the trigonometric operations are shown in &ig M'$B$ /aria"les + C num"ers$ and i C are prede ined in MATLAB and are used to represent comple%

Fig. M1.* Command Window wit' e+amp%e operations

Fig. M1.5 Example trigonometric calculations

MATLAB representation o comple% num"er or

The later case is always interpreted as a comple% num"er, whereas, the ormer case is a comple% num"er in MATLAB only i + has not "een assigned any prior local value$ MATLAB representation o comple% num"er or or 0n 3artesian orm, arithmetic additions on comple% num"ers are as simple as with real num"ers$ 3onsider two comple% num"ers "y and $ Their sum is given (

&or e%ample, two comple% num"ers >> 21=#,*+% >> 22=1.8,2+% >> 2=21,22 2= *.8000 , ".0000i

and

can "e added in MATLAB as(

Multiplication o two or more comple% num"ers is easier in polar@comple% e%ponential orm$ Two comple% num"ers with radial lengths and rad$ We change and are given with angles radC is given "y rad$ The

to radians to give

comple% e%ponential orm o their product

This can "e done in MATLAB "y( >> t3eta1=4#-!1805* i% >> 21=2*e( 4t3eta1*+5% >> 22=2.-*e( 40.2-* i*+5% >> 2=21*22 2= 0.8"82 ) *.92*0+ Magnitude and phase o a comple% num"er can "e calculated in MATLAB "y commands a60 and ang&e. The ollowing MATLAB session shows the magnitude and phase calculation o comple% num"ers >> a604-*e( 40.19* i*+55 an0 = >> ang&e4-*e( 40.19* i*+55 an0 = 0.-9"9 >> a6041!42,0qrt4#5*+55 an0 = 0.#.80 >> ang&e41!42,0qrt4#5*+55 an0 = )0..1#. >ome comple% num"ered calculations are shown in &ig$ M'$D$ and $

Fig. M1." -+amp%e comp%e+ num,ered ca%cu%ations

The mathematical 7uantities &og4(5, respectively$

and

are calculated with e( 4(5, &og104(5, and

All computations in MATLAB are per ormed in dou,%e precision $ The screen output can "e displayed in several ormats$ The de ault output ormat contains our digits past the decimal point or nonintegers$ This can "e changed "y using the 7or$at command$ 8emem"er that the 7or$at command a ects only how num"ers are displayed, not how MATLAB computes or saves them$ >ee how MATLAB prints in di erent ormats$

&ormat command at MATLAB prompt 7or$at 03ort 7or$at 03ort e 7or$at &ong 7or$at &ong e 7or$at 03ort g 7or$at &ong g 7or$at 6an8

)isplay ormat :'$5'BE :$'5'DeF99' :'$5'BE+DB:BGEHE: :$'5'BE+DB:BGEHE:eF99' :'$5'D :'$5'BE+DB:BGEHE :'$5+

The ollowing e%ercise will ena"le the readers to 7uickly write various mathematical ormulas, interpreting error messages, and synta% related issues$

E%cersise i$ ii$ By using ar"itrary values o , check that that $ $

/eri y with a ew ar"itrary values o

iii$ iv$

/eri y with a ew ar"itrary values o

that

$ $

&or t C9, +, B, H, '+ and +B, ind the value o the unction

E(er1i0e M1.2 '$ Try entering comple% num"er in MATLAB as #,+* and check the answer$ 0nitialiIe

and then enter #,*+, #,+**, and #,**+ and check the various answers$ 0nterpret messages given "y MATLAB$ +$ 3alculate magnitude and phase o the ollowing comple% num"ers or using MATLAB$ a$

"$

:$ Jse MATLAB to calculate the magnitude and phase o

or

E(er1i0e M1.#

'$ 3alculate the 7uantity +$ 3alculate or

or $

9ote: ;n7, and 9a9 are prede ined in MATLAB$ 9a9 stands or 4ot#a#4um"er and results rom unde ined operations like 9@9$ ;n7 represents $

3urrent )irectory Window


This window ,&ig$ M'$H- shows the directory, and iles within the directory which are in use currently in MATLAB session to run or save our program or data$ The de ault directory is K3(LMATLABHLwork1$ We can change this directory to the desired one "y clicking on the s7uare "rowser "utton near the pull#down window$

Fig. M1.. Current directory window

One can also use command line options to deal with directory and ile related issues$ >ome use ul commands are shown in Ta"le M'$'$

Ta6&e M1.1 <o$$an= 1=> ?= cd $$ 1= @ 1= =irAna$e &0 or =ir To see the current directory To go one directory "ack rom the current directory To go "ack to the root directory To change to the directory named dir.name To see the list o iles and su"directories within the current U0age

directory ?3at $8=ir 4 arent=ir>=irAna$e5 $8=ir =irAna$e =e&ete 7i&eAna$e =e&ete *.$ )eletes ile rom the current directory$ )eletes all $# iles rom the current directory$ Lists MATLAB#speci ic iles in the directory$ MATLAB speci ic iles are with the e%tensions .$, .$at, .$=&, .$e(> and . . Makes new directory with the name dir.name in the parent directory speci ied "y parentdir $ When supplied with only dir.name, it creates new directory within the current directory

MATLAB desktop snapshot showing selected commands rom Ta"le M'$' are shown in &ig$ M'$G$

Workspace
Workspace window shows the name, siIe, "ytes occupied, and class o any varia"le de ined in the MATLAB environment$ &or e%ample in &ig$M'$E, K"1 is ' M 5 siIe array o data type =ou6&e and thus occupies :+ "ytes o memory$ )ou"le#clicking on the name o the varia"le opens the array editor ,&ig$ M'$'9-$ We can change the ormat o the data ,e$g$, rom integer to loating point-, siIe o the array , or e%ample, or varia"le A, rom : M 5 array to 5 M 5 arrayand can also modi y the contents o the array$

Fig. M1.8 -+amp%e directory re%ated commands

0 we right#click on the name o a varia"le, a menu pops up, which shows various operations or the selected varia"le, such as( open the array editor, save selected varia"le or uture usage, copy, duplicate, and delete the varia"le, rename the varia"le, editing the varia"le, and various plotting options or the selected varia"le$

Fig. M1.9 -ntries in t'e Workspace

Fig. M1.10 Array editor window

Workspace related commands are listed in Ta"le M'$+$ Ta6&e M1.2 <o$$an= ?3o ?3o0 1&ear 1&ear a&& 1&ear Bar1 Bar2 U0age Lists varia"les currently in the workspace Lists more in ormation a"out each varia"le including siIe, "ytes stored in the computer, and class type o the varia"les 3lears the workspace$ All varia"les are removed 8emoves all varia"les and unctions rom the workspace$ This can also "e done "y selecting Edit rom the main menu "ar and then clicking the option Clear Workspace $ 8emoves only !ar1 and !ar2 rom the workspace$

&or e%ample, see the ollowing MATLAB session or the use o ?3o and ?3o0 commands$ >> ?3o Cour Baria6&e0 are: A6 >> ?3o0 Name Size Bytes Class double A 3x4 96 array double b 1x4 3 array Dran= tota& i0 1" e&e$ent0 u0ing 128 6Ete0

Command History Window


This window ,&ig$ M'$''- contains a record o all the commands that we type in the command window$ By dou"le#clicking on any command, we can e%ecute it again$ 0t stores commands rom one MATLAB session to another, hierarchically arranged in date and time$ 3ommands remain in the list until they are deleted$

Fig. M1.11 Command 'istory window

3ommands can also "e recalled with the u )arro? commands$

key$ This helps in editing previous

>electing one or more commands and right#clicking them, pops up a menu, allowing users to per orm various operations such as copy, evaluate, or delete, on the selected set o commands$ &or e%ample, two commands are "eing deleted in &ig$ M'$'+$

Getting Help
MATLAB provides hundreds o "uilt#in unctions covering various scienti ic and engineering computations$ With numerous "uilt#in unctions, it is important to know how to look or unctions and how to learn to use them$ &or those who want to look around and get a eel or the MATLAB computing environment "y clicking and navigating through what catches their attention, a window# "ased help is a good option$ To activate the 6elp window, type 3e& ?in or 3e& =e08 on command prompt or start the 6elp Browser ,&ig$ M'$':- "y clicking the icon rom the desktop tool"ar$

Fig. M1.12 Command 'istory window wit' two commands ,ein( de%eted

0 you know the e%act name o a command, type 3e& commandname to get detailed task# oriented help$ &or e%ample, type 3e& 3e& ?in in the command window to get the help on the command 3e& ?in $ 0 you don1t know the e%act command, "ut ,atleast N- know the keyword related to the task you want to per orm, the &oo87or command may assist you in tracking the e%act command$ The 3e& command searches or an e%act command name matching the keyword, whereas the &oo87or command searches or 7uick summary in ormation in each command related to the keyword$ &or e%ample, suppose that you were looking or a command to take the inverse o a matri%$ MATLAB does not have a command named inBer0e! so the command 3e& inBer0e will not work$ 0n your MATLAB command window try typing &oo87or inBer0e to see the various commands availa"le or the keyword inBer0e$ MATLAB has a wonder ul demonstration program that shows its various eatures through interactive graphical user inter ace$ Type =e$o at the MATLAB prompt to invoke the demonstration program ,&ig$ M'$'5- and the program will guide you throughout the tutorials$

Fig. M1.1# He%p ,rowser

Fig. M1.1* Demonstration Window

Elementary Matrices
Basic data element o MATLAB is a matri% that does not re7uire dimensioning$ To create the matri% varia"le in MATLAB workspace, type the statement ,note that any operation that assigns a value to a varia"le, creates the varia"le, or overwrites its current value i it already e%ists-$ ** A=F8 1 " 2%# - . *%* 9 2 "G The "lank spaces ,or commas- around the elements o the matri% rows separate the elements$ >emicolons separate the rows$ &or the a"ove statement, MATLAB responds with the display A= 8 # * 1 9 " . 2 2 * "

/ectors are special class o matrices with a single row or column$ To create a column vector varia"le in MATLAB workspace, type the statement >> 6=F1% 1% 2% #G 6= 1 1 2 # To enter a row vector, separate the elements "y a space or comma 1 > 1$ &or e%ample( >> 6=F1>1>2>#G 6= 1 1 2 #

We can determine the siIe o the matrices ,num"er o rows, num"er o columns- "y using the 0i2e command$ >> 0i2e4A5 an0 = # *

The command 0i2e, when used with the scalar option, returns the length o the dimension speci ied "y the scalar$ &or e%ample, 0i2e 4A>15 returns the num"er o rows o A and 0i2e4A>25 returns the num"er o columns o A$ >> 0i2e4A>15 an0 = # >> 0i2e4A>25 an0 = *

&or matrices, the &engt3 command returns either num"er o rows or num"er o columns, whichever is larger$ &or e%ample, >> &engt34A5 an0 = * &or vectors, &engt3 command can "e used to determine its num"er o elements$ >> &engt3465 an0 = * The use o colon , : - operator plays an important role in MATLAB$ This operator may "e used to generate a row vector containing the num"ers rom a given starting value (i, to the inal value (7, with a speci ied increment =(, e$g$, (=F(i:=(:(7G >> (=F0:0.1:1G (= <o&u$n0 1 t3roug3 . 0 0.1000 0.2000 0.#000 0.*000 0.-000 0."000

<o&u$n0 8 t3roug3 11 0..000 0.8000 0.9000 1.0000

By de ault, the increment is taken as unity$ To generate linearly e7ually spaced samples "etween +1 and +2, use the command &in0 a1e4(1>(25 $ By de ault, '99 samples will "e generated$ The command &in0 a1e 4(1>(2> 95 allows the control over num"er o samples to "e generated$ >ee the e%ample "elow$ >> (=&in0 a1e40>1>115 (= <o&u$n0 1 t3roug3 " 0 0.1000 0.2000 0.#000 0.*000 0.-000

<o&u$n0 . t3roug3 11

0."000

0..000

0.8000

0.9000

1.0000

Learn how to generate logarithmically spaced vector using the command &og0 a1e $ The colon operator can also "e used to su"script matrices$ &or e%ample, A4:>+5 is the /th column o A, and A4i>:5 is the ith row o A$ O"serve the ollowing MATLAB session$ >> A=F8 1 " 2%# - . *%* 9 2 "G% >> A42>:5 an0 = # . *

>> A4#>2:*5 an0 = 9 2 "

>> A41>#5 an0 = " >> B=A41:#>2:#5 B= 1 9 " . 2

>> A4:>#5=F G A= 8 # * 1 9 2 * "

Manipulating matrices is almost as easy as creating them$ Try the ollowing operations(

>> A,# >> A)# >> A*# >> A!# When you add@su"tract@multiply@divide a vector@matri% "y a num"er ,or "y a varia"le with a num"er assigned to it-, MATLAB assumes that all elements o vector@matri% should "e individually operated on$ Ta"le M'$: provides the list o "asic operations on any two ar"itrary matrices A and B and their dimensional re7uirements$

Ta6&e M1.# Basic matri+ operations


Operation Plus Minus Multiply Multiply (element-byelement) Divide (element-by-element) Operato Example r + * .* A+B A-B A*B A.*B Notes Must be of same dimensions Must be of same dimensions Must be of compatible dimensions Must be of same dimensions; multiplies element aij with element bij Must be of same dimensions; divides element aij by element bij Must be of same dimensions; divides element bij by element aij % must be a constant& ' must be a s(ua"e mat"i#

A./B

Divide (element-by-element) Mat"i# powe" Mat"i# powe" (element-byelement)

.! $ .$

A.\B A^k A.^k

k is a constant, A can "e o any dimensions! gives ,ai2-k

E(a$ &e M1.1

To ind the solution o the ollowing set o linear e7uations(

we write the e7uations in the matri% orm as

where is the matri% o coe icients o +1$ +2 and +3 is the column vector which will contain the solutions +1$ +2 and +3 is the column vector o values on the right#hand side

The solution vector

where

stands or ad2oint o matri% matri%

and

stands or determinant o

The determinant o

is a scalar#valued unction o

$ 0t is ound through the use o minors and co actors$

The minor mi/ o the element ai/ is the determinant o a matri% o order o"tained rom "y removing the row and column containing ai/$ The co)actor ci/ o the element ai/ is de ined "y the e7uation

)eterminants can "e evaluated "y an e%pansion that reduces the evaluation o an determinant down to the evaluation o a string o co actors$ >electing an ar"itrary row k o matri% determinants, namely the or ar"itrary column % o matri% , we have

or

The ad2oint o matri% and then transposing$

is ound "y replacing each element ai/ o matri%

"y its co actor

&ollowing MATLAB commands solve the given set o simultaneous linear e7uations$ >> A = F2 - )#% # )2 *% 1 " )*G% >> 6 = F"% )2% #G% >> ( = inB4A5 * 6 (= *.8### )*.-8##

)".*1".

Exercise M .!
3onsider three matrices A> B> and 3 given "elow$ Per orm the ollowing operations( A,B> B)<> A*<> A.*B> A.!<> A.@B> A.!B> 4B*<5/#> and <./#. 3ountercheck MATLAB answers manually$ Try to interpret errors, i any$

E(er1i0e M1.-

3reate a vector t with '9 elements ',+,$,'9$ 3alculate

or

and

, where

Exercise M ."
3reate a vector t with initial time
i. ii.

and inal time

with an interval o 9$9B$ 3alculate

Flow Control Functions


There are many low control unctions in MATLAB$ The 7or unction in MATLAB provides a mechanism or repeatedly e%ecuting a series o statements a given num"er o times$ The 7or unction connected to an en= statement sets up a repeating circulation loop$ An important point is that each 7or must "e matched with an en= $ The 6rea8 statement provides e%it 2ump out o loop$

The ?3i&e unction in MATLAB allows a mechanism or repeatedly e%ecuting a series o statements an inde inite num"er o times, under control o a logical condition$ The unction i7 evaluates a logical e%pression and e%ecutes a group o statements "ased on the value o the e%pression$ The e&0e statement urther conditionaliIes the i7 statement$

H&otting
MATLAB is an outstanding tool or visualiIation$ 0n the ollowing, we will learn how to create and print simple plots$ We are going to plot sinusoidal oscillations with e%ponential decay$ To do this, irst generate the data , +# and y# coordinates-$ +0 coordinate in this case is time steps$ Let the initial time sec and inal time C9 C'9 sec with an interval o 9$9B sec$ y# coordinate is the value o sinusoidal $ This plot can "e generated "y entering the

oscillations represented "y ollowing commands$ >> t=0:0.0-:10% I Denerating ti$e 0te 0

>> Et=e( 4)t!25.*0in42* i*t5% >> &ot4t>Et5% IH&ot t B0. E4t 5 >> gri= on%

I<a&1u&ate E4t 5

IDenerating gri=0 on () an= E)1oor=inate0 ILa6e&ing ()a(i0 ILa6e&ing E)a(i0

>> (&a6e&4JTi$e Ste 0: t )))>J5%

>> E&a6e&4JSinu0oi= ?it3 e( onentia& =e1aE: E4t5 )))>J5% >> tit&e4JH&otting e( 4)t!25*0in42* i*t5J5%

IHut a tit&e on t3e &ot

8esponse is shown in graphics or igure window snapshot ,&ig$ M'$'B-$ Arguments o the (&a6e&, E&a6e&> and tit&e commands are te%t strings$ Te%t strings are entered within single#7uote characters$ Lines "eginning with I are comments! these lines are not e%ecuted$ The rint command sends the current plot to the printer connected to your computer$ 8ather than displaying the graph as a continuous curve, one can show the unconnected data points$ To display the data points with small stars, use &ot4t>Et>J*J5$ To show the line through the data points in red color as well as the distinct data points, one can com"ine the two plots with the

command &ot4t>Et>JrJ>t>Et>J*J5$ To learn more a"out plot options, type 3e& MATLAB prompt and hit return$

&ot on the

One can also produce multiple plots in a single window$ Enter the ollowing se7uence o commands to your MATLAB command window and o"serve the resultant igure ,&ig$ M'$'D-$

Fig. M1.1- 1%ottin( sinusoid wit' e+ponentia% decay

>> 0u6 &ot4#>1>15% &ot40in42* i*t55% >> tit&e4J &ot o7 0in42* i*t5J5% >> 0u6 &ot4#>1>25% &ot4e( 4)t!255%

>> tit&e4J &ot o7 e( 4)t!25J5% >> 0u6 &ot4#>1>#5% &ot4e( 4)t!25.*0in42* i*t55% >> tit&e4J$u&ti &E a6oBe t?o &ot0 to get t3i0J5%

Fig. M1.1" 1%ottin( mu%tip%e p%ots in a sin(%e )i(ure window

The command 0u6 &ot4$>n> 5 "reaks the igure window into an m#"y#n matri% o small a%es and selects the pth a%es or the current plot$ La"eling, title, and grid commands should "e given immediately a ter the particular 0u6 &ot command to apply them to that su"plot$ Learn more a"out su"plot using 3e& 0u6 &ot $ 3lick on the H&ot E=itor icon once and then dou"le click anywhere in the plot to open the Hro ertE E=itor ) A(e0 window ,&ig M'$'H-$ Jsing this property editor, title, a%es, scale etc$$$ o the plot can "e changed$

)ou"le clicking anywhere e%actly on the curve opens the Property Editor O Lineseries ,&ig M'$'G-$ &rom this, plot type can "e changed on the spot$ Availa"le plot options are( Line, Area, Bar, Stair0, and Ste$$ Line width and markers can "e changed "y pull down menu Line and Mar8er$

Fig. M1.1. A+es property editor

Fig. M1.18 Lineseries property editor

Exercise M .#

=enerate B9 linearly spaced time steps "etween 9 and '9$ 3alculate


). and &*& and +. Plot all the th"ee cu"ves in a sin,le fi,u"e. . Plot all the th"ee cu"ves in a sin,le fi,u"e.

or(

-. k .* and

Both the plots should "e with respect to time$ 0n "oth the plots, mark each curve with its k and values , Kint: Jse ;n0ert Te(t Bo( option rom main menu "ar-$ &rom the main menu "ar, choose Too&0 E=it H&ot and then click anywhere on a curve$ H&ot E=itor will open$ Try several availa"le options$ &urther to this, do the ollowing(
). /"eate le,ends fo" both the plots. -. 0se 1oom-in and 1oom-out tools. *. 2otate plots usin, *D "otation tool. 3. /lic% on the $ata %&rsor icon. Move mouse pointe" anywhe"e in the ,"aph sheet. ' c"oss-hai" cu"so" will appea". /lic%in, the c"oss-hai" on the cu"ve will ,ive co""espondin, and a#is values. 0se $ata %&rsor to obse"ve values at va"ious time steps.

Exercise M .'

Assign 9$B, , and or t C P9(9$'('9Q$ O"tain three plots or

to

, respectively$ 3alculate

$ Title the graph and la"el the )raw value$

all the three plots on the same graph sheet and mark each curve with appropriate

Exercise M .(
). 4tudy the commands semilogx& semilog)& and loglog usin, *elp command.

-. /onside" the comple# numbe" two plots on semilo, ,"aph sheet fo"

. 0sin, M'56'7& ,ene"ate the followin, . 0se s&+plot. 5itle both the

S1ri t 7i&e0 4M)7i&e05


Type edit on MATLAB prompt and hit enter ,or ollow Fi&e 9e? M)Fi&e option rom the main menu "ar or click on icon in main tool"ar-$ An E=itor!De6ugger window will open$ This is where you write, edit, create, can run rom, and save your own programs ,user created script iles with se7uences o MATLAB commands- in iles called M # )i%es $ An e%ample M0)i%e is shown in &ig$ M'$'E$ 3reate the same ile in your MATLAB editor and then use the option Fi&e SaBe or Fi&e SaBe A0 to save the ile with the name =e1aEe=A0in.$ in current working directory$ Rou can save all iles into your personaliIed directory$ 0 your personal directory is immediately "elow the directory in which the MATLAB application program is installed , e.(. , c(LMATLABHp9-, then all user written iles are automatically accessi"le to MATLAB$ 0 you want to store iles somewhere else, then you need to speci y the path to the iles using the at3 or a== at3 command, or change the current working directory to the desired directory "e ore you run the program$ &or e%ample, your script ile is in the directory my_dir> which is not the current working directory o the MATLAB$ 0 the location o my_dir is K 1:@=o1u$eL1@1ontro&@ my_dir 1, it can "e included in the MATLAB search path "y( >> at34 at3> M1:@=o1u$eL1@1ontro&@$EA=irJ5% or >> a== at3 M1:@=o1u$eL1@1ontro&@$EA=irJ% To remove speci ied directory rom the MATLAB search path, use the command r$ at3 $ Learn more a"out MATLAB search path through online help$ Type simply the name o the ile =e1aEe=A0in to e%ecute it rom the command window$ >cript can also "e saved and e%ecuted simultaneously "y clicking the icon in the main tool"ar$ To open the e%isting M0)i%e rom the MATLAB command window, type e=it filename ,or ollow Fi&e O en option rom the main menu "ar or click on icon in the main tool"ar-$ All varia"les created during the runtime o the script ile are le t in the workspace$ Jsing ?3o or ?3o0 > you can get in ormation a"out them, and also access them "y workspace window$

E(er1i0e M1.10 Modi y the script ile written in &ig$ M'$+9 in the ollowing way( '$ An error message should prompt, i inal time is less than initial time

+$ 0n addition to initial and inal time, and time constant, the program should prompt the user to enter the amplitude o the sine wave$ :$ 0t should plot the Rt curve! however, wherever Rt crosses the Iero#a%es, an indication through % #mark should appear$ 5$ )isplay current date and time at the end$ ,6int( Learn commands =ate and 1&o18 using online help-$ B$ 3alculate the total e%ecution time o the program$ ,6int( Learn ti1 and to1 commands-$

E(er1i0e M1.11 Learn more a"out '- For loops, +- N3i&e Loops, and :- ;7)E&0e)En= constructions using online help$

Fig. M1.19 -+amp%e M0)i%e

DeBe&o ing u0er)=e7ine= Fun1tion0


>uppose you want to write a unction to generate and plot 2 data points o the e%ponentially# decaying sinusoid o amplitude A, re7uency ), and e%ponential time#constant $ A MATLAB unction which can take all these parameters as arguments and provide decaying sinusoid as an output is shown in &ig$ M'$+9$ =enerate an M# ile with the code given in &ig$M'$+9$ When you attempt to save the ile, editor will automatically assign a unction name decayingSsin to your M# ile$ >ave the unction to the current working directory or include your personal directory into MATLAB search path "y using addpath command$ We must avoid duplicating unction names with "uilt#in MATLAB unctions or keywords$

A unction ile "egins with a unction de inition line, which contains the keyword unction, a well#de ined list o input and output arguments, and unction name$ >ome e%amples o unction de inition are given "elow ,e%ecute help unction or details-( 7un1tion F 3> $agG = 1o$ &e( 425 7un1tion Fr>t3etaG = o&arA7or$4a> 65

7un1tion =e1aEingA0in4 5 7un1tion 0E0Are0 on0e4 5 The irst commented line 2ust a ter the unction de inition is called the H1 %ine$ This line is automatically catalogued in the 1ontent0.$ ile o the directory in which unction ile resides$ This allows the line to "e searched "y the &oo87or command$ /ery care ully chosen keywords related to your unction should come in the H1 %ine$ 4ote that i there is any "lank space "e ore the T sign in the H1 %ine, then it is no longer H1 %ine NN All comment lines immediately ollowing the unction de inition line and immediately "e ore the irst e%ecuta"le statement o the unction are displayed "y MATLAB i 3e& is asked on the unction$ Type >> 3e& =e1aEingA0in and see what MATLAB displays$ 0nput#argument names used in the unction are local to the unction! so ar"itrary varia"le names can "e used to call the unction$ The name o another unction can also "e passed as an input varia"le$ The ollowing are e%amples o legal unction calls(

Fig. M1.20 D-CA3425.642 7unction

>> Ct = =e1aEingA0in 4ti$eA0 an> ti$eA1on0t> $ag> 7req> t05

0n this case, input varia"les ti$eA0 an> ti$eA1on0t> $ag> 7req, and t0 must "e de ined "e ore the unction call$ >> re0 = =e1aEingA0in 4F0 10G> tau> #> -0> 10005 6ere the input varia"le tau must "e de ined "e orehand! all other inputs have "een de ined in the unction call$ >> 0ig = =e1aEingA0in 4F0>10G> 2> #> -0> 1005 6ere all the inputs have "een speci ied in the call statement$ >> =e1aEingA0in 4F0>10G> #> 0.-> "0> 1005 0n this case, the output is assigned to generic varia"le ans$

Exercise M . ,
). 8#ecute -eca)ing.sin function with less than fou" and ,"eate" than five a"bit"a"y a",uments and inte"p"et the messa,es. 4tudy nargin and nargo&t commands th"ou,h online help. -. 8#ecute -eca)ing.sin function with tspan / 012 and tspan/03 12 and inte"p"et the messa,es.

*. 8#ecute the function as 4t / -eca)ing.sin501 627 37 1.67 618. 9hat is the len,th of the vecto" 4t : 3. ;n some applications we don<t want to ,ene"ate the plot eve"y time. 9e may need only output ,iven by the function. Modify the above function with one mo"e input a",ument =str< to p"ovide cont"ol ove" whethe" we want to ,ene"ate the plot o" not: ;f str / 94: o" 9):& then it should ,ene"ate the plot. ;f str / 9N: o" 9n:& then it should not. ;f any othe" cha"acte" is passed& then it should ,ive the e""o" messa,e 9;nrecogni<e- &ser inp&t: and te"minate the p"o,"am. >ou also need to modify p"ocessin, with the nargin command.

E(er1i0e M1.1# Write a unction named 0 e1i7i1ation0 with the ollowing input and output arguments( 0nput arguments( '$ +$ :$ 5$ vector t0 an o initial and inal times$ >calars E0 9, 2eta , ?n, and t3eta$

3haracter argument 0tr controlling whether to plot the inal result or not$ >calar 9 o num"er o data points re7uired to "e generated$

Output arguments(

'$

Ct calculated "y

+$

Tau calculated "y

:$

Tr calculated "y

5$

T calculated "y

B$

M calculated "y

MATLAB MODULE 2
3ontrol >ystem Tool"o% and >ym"olic Math Tool"o%

Control System Toolbox


3ontrol >ystem Tool"o% is a collection o commands to "e used or control systems1 analysis and design$ We will "e using only some o these commands, "ecause o the limited nature o course pro ile$ )escription o these commands will "e distri"uted in di erent modules$ 0n this module, we will present commands related to trans er unctions and system responses$ To see all the commands in the 3ontrol >ystem Tool"o% and their unctionalities, type 3e& 1ontro& in the MATLAB command window$ MATLAB will respond with
?? help cont"ol

<ontro& SE0te$ Too&6o( Oer0ion ".0 4P1*5 0-)MaE)200* =eneral$ 1tr& re7 # >et 3ontrol >ystem Tool"o% pre erences$ &ti$o=e&0 # )etailed help on the various types o LT0 models$ &ti ro 0 # )etailed help on availa"le LT0 model properties$ 3reating linear models$ t7 # 3reate trans er unction models$ 2 8 # 3reate Iero@pole@gain models$ 00> =00 # 3reate state#space models$ 7r= # 3reate a re7uency response data models$ 7i&t # >peci y a digital ilter$ &ti!0et # >et@modi y properties o LT0 models$ )ata e%traction$ t7=ata # E%tract numerator,s- and denominator,s-$ 2 8=ata # E%tract Iero@pole@gain data$ 00=ata # E%tract state#space matrices$ =00=ata # )escriptor version o >>)ATA$ 7r=ata # E%tract re7uency response data$ &ti!get # Access values o LT0 model properties$ 3onversions$ t7 # 3onversion to trans er unction$ 2 8 # 3onversion to Iero@pole@gain$ 00 # 3onversion to state space$ 7r= # 3onversion to re7uency data$ 13gunit0 # 3hange units o &8) model re7uency points$ 12= # 3ontinuous to discrete conversion$ =21 # )iscrete to continuous conversion$ =2= # 8esample discrete#time model$

>ystem interconnections$ a en= # =roup LT0 systems "y appending inputs and outputs$ ara&&e& # =eneraliIed parallel connection ,see also overloaded F-$ 0erie0 # =eneraliIed series connection ,see also overloaded ?-$ 7ee=6a18 # &eed"ack connection o two systems$ &7t # =eneraliIed eed"ack interconnection ,8edhe er star product-$ 1onne1t # )erive state#space model rom "lock diagram description$ >ystem gain and dynamics$ =1gain # )$3$ ,low re7uency- gain$ 6an=?i=t3 # >ystem "andwidth$ &ti!nor$ # 4orms o LT0 systems$ o&e> eig # >ystem poles$ 2ero # >ystem ,transmission- Ieros$ 2$a # Pole#Iero map$ io 2$a # 0nput@output pole#Iero map$ =a$ # 4atural re7uency and damping o system poles$ e0ort # >ort continuous poles "y real part$ =0ort # >ort discrete poles "y magnitude$ 0ta60e # >ta"le@unsta"le decomposition$ $o=0e # 8egion#"ased modal decomposition$ Time#domain analysis$ &tiBie? # 8esponse analysis =J0 ,LT0 /iewer-$ 0te # >tep response$ i$ u&0e # 0mpulse response$ initia& # 8esponse o state#space system with given initial state$ &0i$ # 8esponse to ar"itrary inputs$ gen0ig # =enerate input signal or L>0M$ 1oBar # 3ovariance o response to white noise$ &re7uency#domain analysis$ &tiBie? # 8esponse analysis =J0 ,LT0 /iewer-$ 6o=e # Bode diagrams o the re7uency response$ 6o=e$ag # Bode magnitude diagram only$ 0ig$a # >ingular value re7uency plot$ nEqui0t # 4y7uist plot$ ni13o&0 # 4ichols plot$ $argin # =ain and phase margins$ a&&$argin # All crossover re7uencies and related gain@phase margins$ 7reqre0 # &re7uency response over a re7uency grid$ eBa&7r # Evaluate re7uency response at given re7uency$ 7r=!inter # 0nterpolates re7uency response data$ 3lassical design$ 0i0otoo& # >0>O design =J0 ,root locus and loop shaping techni7ues-$ r&o1u0 # Evans root locus$

Pole placement$ &a1e # M0MO pole placement$ a18er # >0>O pole placement$ e0ti$ # &orm estimator given estimator gain$ reg # &orm regulator given state# eed"ack and estimator gains$ LU8@LU= design$ &qr> =&qr # Linear#7uadratic ,LU- state# eed"ack regulator$ &qrE # LU regulator with output weighting$ &qr= # )iscrete LU regulator or continuous plant$ kalman # <alman estimator$ 8a&$= # )iscrete <alman estimator or continuous plant$ &qgreg # &orm LU= regulator given LU gain and <alman estimator$ aug0tate # Augment output "y appending states$ >tate#space models$ r00> =r00 # 8andom sta"le state#space models$ 00200 # >tate coordinate trans ormation$ 1anon # >tate#space canonical orms$ 1tr6 # 3ontrolla"ility matri%$ o60B # O"serva"ility matri%$ gra$ # 3ontrolla"ility and o"serva"ility gramians$ 006a& # )iagonal "alancing o state#space realiIations$ 6a&rea& # =ramian#"ased input@output "alancing$ $o=re= # Model state reduction$ $inrea& # Minimal realiIation and pole@Iero cancellation$ 0$inrea& # >tructurally minimal realiIation$ Time delays$ 3a0=e&aE # True or models with time delays$ tota&=e&aE # Total delay "etween each input@output pair$ =e&aE22 # 8eplace delays "y poles at IC9 or &8) phase shi t$ a=e # Pade appro%imation o time delays$ Model dimensions and characteristics$ 1&a00 # Model type ,1t 1, 1Ipk1, 1ss1, or 1 rd1-$ 0i2e # Model siIes and order$ &ti!n=i$0 # 4um"er o dimensions$ &ti!i0e$ tE # True or empty models$ i01t # True or continuous#time models$ i0=t # True or discrete#time models$ i0 ro er # True or proper models$ i00i0o # True or single#input@single#output models$ re03a e # 8eshape array o linear models$ Overloaded arithmetic operations$ , an= ) # Add and su"tract systems ,parallel connection-$ * # Multiply systems ,series connection-$

@ # Le t divide ## sys'Lsys+ means inv,sys'-?sys+$ ! # 8ight divide ## sys'@sys+ means sys'?inv,sys+-$ / # Powers o a given system$ J # Pertransposition$ .J # Transposition o input@output map$ F..G # 3oncatenate models along inputs or outputs$ 0ta18 # >tack models@arrays along some array dimension$ &ti!inB # 0nverse o an LT0 system$ 1on+ # 3omple% con2ugation o model coe icients$ Matri% e7uation solvers$ &Ea > =&Ea # >olve Lyapunov e7uations$ &Ea 13o&> =&Ea 13o& # >7uare#root Lyapunov solvers$ 1are> =are # >olve alge"raic 8iccati e7uations$ g1are> g=are # =eneraliIed 8iccati solvers$ 6=013ur # Block diagonaliIation o a s7uare matri%$ )emonstrations$ Type VdemoV or Vhelp ctrldemosV or a list o availa"le demos$ control is "oth a directory and a unction$ ### help or modeldev@control$m ### MO)EL)E/@3O4T8OL 0n this module, we will learn how to represent trans er unctions in the MATLAB, partial raction e%pansion o rational e%pressions, representation o trans er unctions as LT0 o"2ects, and to o"tain time domain responses o LT0 systems$ 0mportant commands or this module are( root0 O &ind polynomial roots o&E O 3onvert roots to polynomial o&EBa& O Evaluate polynomial value 1onB O 3onvolution and polynomial multiplication =e1onB O )econvolution and polynomial division re0i=ue O Partial# raction e%pansion ,residuest7 O 3reation o trans er unctions or conversion to trans er unctions o&e O 3ompute the poles o LT0 models 2ero O Transmission Ieros o LT0 systems t7=a=a O Uuick access to trans er unction data 2 8=ata O Uuick access to Iero#pole#gain data 2$a O Pole#Iero map o LT0 models 2 8 O 3reate Iero#pole#gain models or convert to Iero#pole#gain ormat 0te O >tep response o LT0 models i$ u&0e O 0mpulse response o LT0 models &0i$ O >imulate time response o LT0 models to ar"itrary inputs gen0ig O Periodic signal generator or time response simulations with lsim

Ho&Eno$ia&0

3onsider a polynomial Ks : F: s + F51, to which we attach the varia"le name $ MATLAB can interpret a vector o length n F' as the coe icients o an n th #order polynomial$ 3oe icients o the polynomial are interpreted in descending powers$ Thus, i the polynomial is missing any coe icient, we must enter Ieros in the appropriate places in the vector$ &or e%ample, polynomial can "e represented "y the vector F1 # 0 *G in MATLAB$ &or e%ample( >> =F1 # 0 *G = 1#0* 8oots o the polynomial can "e o"tained "y root0 command$ >> r=root04 5 r= )#.#--# 0.1... , 1.0..#i 0.1... ) 1.0..#i =iven roots o a polynomial in a vector, a vector o polynomial coe icients can "e o"tained "y the command o&E$ >> = o&E4r5 = 1.0000 #.0000 0.0000 *.0000 at ar"itrary

Jse the command o&EBa&4 > 05 to evaluate the polynomial represented "y vector value o 0$ &or e%ample, to evaluate the polynomial 1s F: s F51 at >> o&EBa&4 >0qrt4255 an0 = 12.828*
: +

, type

The product o two polynomials is ound "y taking the convolution o their coe icients$ The unction 1onB will do this or us$ 3onsider an e%ample o multiplying polynomial Ks : F: s + F51 with Ks F+1(

>> 1=F1 # *G% >> 2=F1 2G% >> #=1onB4 1> 25 #= 1 10 8

The unction =e1onB divides two polynomials and returns 7uotient as well as the remainder polynomial$ >> Fq>rG==e1onB4 1> 25 q= 1 r= 0 0 2 1

where q is the 7uotient and r is the remainder polynomial$

E(er1i0e M2.1 /eri y the deconvolution result given in vectors q and r$ 6int( 3heck whether 1 C 1onB4q> 25 F r or notW E(er1i0e M2.2

Let

and

$ O"tain

3onsider the rational ractions o the orm(

where the coe icients and are real constants, and and are integers$A raction o the orm 5,s- can "e e%panded into partial ractions$ To do this, irst o all we actoriIe the denominator polynomial D,s- into irst#order actors$ The roots o D,s- can "e real or comple%! distinct or repeated$ Let, vectors 9 and D speci y the coe icients o numerator and denominator polynomials and respectively$ The command FA> >QG=re0i=ue49>D5 returns residues in column vector A, the roots o the denominator in column vector , and the direct term in scalar Q$ 0 there are no multiple roots, the raction can "e represented as(

0 there are roots o multiplicity mr , i.e. , terms o the orm(

, then the e%pansion includes

, 8 is empty ,Iero-$

>upplying : arguments A> > and Q to re0i=ue converts the partial raction e%pansion "ack to the polynomial with coe icients in 9 and D. 3onsider the rational raction(

MATLAB solution to partial raction pro"lem can "e given "y( >> 9=F10 *0G% >> D=F1 * # 0G% >> FA> >QG=re0i=ue49>D5 A=

1.""". )1-.0000 1#.#### = )# )1 0 Q= FG

E(a$ &e M2.1 3onsider the unction

The ollowing MATLAB session evaluates the residues$ >> 9 = 1#% >> D = F1 " 22 #0 1# 0G% >> FA> >QG=re0i=ue49>D5 A= 0.0200 ) 0.0-".i 0.0200 , 0.0-".i )1.0*00 )1.#000

1.0000 = )2.0000 , #.0000i )2.0000 ) #.0000i )1.0000 )1.0000 0 Q= FG

E(er1i0e M2.# 8epresent the matrices A, , and Q o"tained in E%ample M+$' in partial raction orm and convert "ack to the polynomial orm$ 3ounter check your answer with MATLAB$ E(er1i0e M2.* 3onsider the rational raction(

O"tain partial raction orm in terms o 8. >olve using MATLAB or countercheck your answer$ E(er1i0e M2.-

and

3onsider the rational raction( 0denti y the points where( '$ +$ and

Note: The roots o the numerator polynomial, i.e. , o and the roots o the denominator polynomial, i.e. ,

, are known as the 9eros , are known as

the poles o

Transfer Functions
Trans er unctions can "e represented in MATLAB as LT0 ,Linear Time 0nvariant- o"2ects using numerator and denominator polynomials$ 3onsider the trans er unction given "y 0t can "e represented in MATLAB as(

>> nu$ = F1 1G% >> =en = F1 # 1G% >> D = t74nu$>=en5

Tran07er 7un1tion: ..0 , 1 ))))))))))))))))) 0/2 , # 0 , 1

E(a$ &e M2.2 The unction 1onB has "een used to multiply polynomials in the ollowing MATLAB session or the trans er unction

>> n1 = F- 1G% >> n2 = F1- 1G% >> =1 = F1 0G% >> =2 = F# 1G% >> =# = F10 1G% >> nu$ = 100*1onB4n1>n25% >> =en = 1onB4=1>1onB4=2>=#55% >> DK = t74nu$>=en5

Tran07er 7un1tion:

.-00 0/2 , 2000 0 , 100 ))))))))))))))))))))))))))))))))))) ....#0 0/# , 1# 0/2 , 0 To learn more a"out LT0 o"2ects given "y t7, type &ti$o=e&0 t7 in MATLAB command window$ Type &ti ro 0 t7 on MATLAB prompt to learn the properties associated with an LT0 o"2ect represented "y t7$ Trans er unctions can also "e entered directly in polynomial orm as we enter them in the note"ook using LT0 o"2ects$ &or e%ample, o"serve the ollowing MATLAB session$ >> 0=t74J0J5 IDe7ine J0J a0 an LT; o6+e1t in o&Eno$ia& 7or$ Tran07er 7un1tion: 0 >> D1=1-0*40/2,2*0,.5!F0*40/2,-*0,*5G I For$ D1405 a0 an LT; tran07er 7un1tion I in o&Eno$ia& 7or$. Tran07er 7un1tion: 1-0 0/2 , #00 0 , 10-0 ))))))))))))))))))))))))))))))))) ......0/# , - 0/2 , *0

>> D2=20*40,25*40,*5!F40,.5*40,85*40,95G I For$ D2405 a0 an LT; tran07er I 7un1tion in o&Eno$ia& 7or$. Tran07er 7un1tion: .....20 0/2 ,120 0 , 1"0 )))))))))))))))))))))))))))))))))))) 0/# , 2* 0/2 , 1910 , -0* The commands o&e and 2ero calculate the poles and Ieros o LT0 models$ >> o&e4D15 an0 = 0 )*

)1 >> 2ero4D15 an0 = )1.0000 , 2.**9-i )1.0000 ) 2.**9-i To e%tract numerator and denominator polynomials, use the unction t7=ata $ >> Fnu$>=enG=t7=ata4D>JBJ5 nu$ = 011 =en = 1#1 To e%tract Ieros and poles o trans er unction simultaneously, use the unction 2 8=ata $ >> F2> G=2 8=ata4D>JBJ5 2= )1 = )2."180 )0.#820 0 we know Ieros and poles o the system with gain constant, the trans er unction o LT0 system can "e constructed "y 2 8 command$ &or e%ample, to create a unity gain trans er unction 5:,swith Iero at #' and two poles at #+$D'G and #9$:G+, ollow the MATLAB session given "elow$ >> D#=2 84)1>F)2."18 )0.#82G>15 Rero! o&e!gain: ,sF'########################### ,sF+$D'G-,sF9$:G+-

The polynomial trans er unction created with t7 can "e converted to Iero#pole#gain model "y the command 2 8 and !ice !ersa $ The ollowing MATLAB session gives the Iero#pole#gain ormat o LT0 system represented "y 5,s-$ >> 2 84D5 Rero! o&e!gain: ,sF'########################### ,sF+$D'G-,sF9$:G+To o"serve the polynomial orm o the trans er unction 5:,s-, enter >> t74D#5 Tran07er 7un1tion: sF' )))))))))))))))))))))) 0/2 , #0 ,1 To learn more a"out LT0 o"2ects given "y 2 8, type &ti$o=e&0 2 8 in MATLAB command window$ Type &ti ro 0 2 8 on MATLAB prompt to learn the properties associated with an LT0 o"2ect represented "y 2 8$ The unction 2$a 4D5 plots the poles and Ieros o the trans er unction 5 s& on comple% plane$ When used with two le t hand side arguments, F >2G = 2$a 4D5, the unction returns the poles and Ieros o the system in two column vectors and 2$ &or e%ample( >> F >2G= 2$a 4D5 = )2."180 )0.#820 2= )1

SE0te$ Pe0 on0e


>tep and impulse responses o LT0 o"2ects can "e o"tained "y the commands 0te and i$ u&0e $ &or e%ample, to o"tain the step response o the system represented in LT0 o"2ect 5, enter

>> 0te 4D5 The MATLAB response to this command is shown in &ig$ M+$'$

Fig. M2.1 To o"tain the impulse response, enter >> i$ u&0e4D5 The MATLAB response to this command is shown in &ig$ M+$+$

Fig. M2.2

>tep and impulse response data can "e collected into MATLAB varia"les "y using two le t hand arguments$ &or e%ample, the ollowing commands will collect step and impulse response amplitudes in Et and time samples in t$ FEt> tG = 0te 4D5 FEt> tG = i$ u&0e4D5 8esponse o LT0 systems to ar"itrary inputs can "e o"tained "y the command &0i$$ The command &0i$4D>u>t5 plots the time response o the LT0 model D to the input signal descri"ed "y u and t$ The time vector t consists o regularly spaced time samples and u is a matri% with as many columns as inputs and whose ith #row speci ies the input value at time t4i5$ O"serve the ollowing MATLAB session to o"tain the time response o LT0 system D to sinusoidal input o unity magnitude$ >> t=0:0.01:.% >> u=0in4t5% >> &0i$4D>u>t5 The response is shown in &ig$ M+$:$

Fig. M2.#

E(er1i0e M2."

i. ii.

@btain the "esponse of @btain the "esponse of

to "amp and pa"abolic inputs usin, lsim command. to "amp and pa"abolic inputs usin, step command.

The unction gen0ig generates periodic signals or time response simulation with &0i$ unction$ 0t can generate sine, s7uare, and periodic pulses$ All generated signals have unit amplitude$ O"serve the ollowing MATLAB session to simulate 5 , s - or +9 seconds with a sine wave o period B seconds$ >> Fu>tG=gen0ig4 J0inJ >->205% ISine ?aBe ?it3 erio= - 0e1 an= =uration 20 0e1 >> &0i$4D>u>t5 ISi$u&ate D405 ?it3 u an= t. The response is shown in &ig$ M+$5$

Fig. M2.*

E(er1i0e M2..

=enerate s7uare and pulse signals with the period o 5 seconds and o"tain time response o or a duration o :9 seconds$

E(a$ &e M2.# The ollowing MATLAB script calculates the step response o second#order system

with

and various values o

t=F0:0.1:12G% nu$=F1G% 2eta1=0.1% =en1=F1 2*2eta1 1G% 2eta2=0.2% =en2=F1 2*2eta2 1G% 2eta#=0.*% =en#=F1 2*2eta# 1G% 2eta*=0..% =en*=F1 2*2eta* 1G% 2eta-=1.0% =en-=F1 2*2eta- 1G% 2eta"=2.0% =en"=F1 2*2eta" 1G% FE1>(G=0te 4nu$>=en1>t5% FE2>(G=0te 4nu$>=en2>t5% FE#>(G=0te 4nu$>=en#>t5% FE*>(G=0te 4nu$>=en*>t5% FE->(G=0te 4nu$>=en->t5% FE">(G=0te 4nu$>=en">t5% &ot4t>E1>t>E2>t>E#>t>E*>t>E->t>E"5 (&a6e&4 JtJ 5> E&a6e&4 JE4t5J 5 gri= 8esponse through the a"ove MATLAB script is shown in &ig M+$B$

Fig. M2.-

The ollowing MATLAB script calculates the impulse response o second#order system

with

and various values o

t=F0:0.1:10G% nu$=F1G% 2eta1=0.1% =en1=F1 2*2eta1 1G% 2eta2=0.2-% =en2=F1 2*2eta2 1G% 2eta#=0.-% =en#=F1 2*2eta# 1G% 2eta*=1.0% =en*=F1 2*2eta* 1G% FE1>(>tG=i$ u&0e4nu$>=en1>t5% FE2>(>tG=i$ u&0e4nu$>=en2>t5% FE#>(>tG=i$ u&0e4nu$>=en#>t5%

FE*>(>tG=i$ u&0e4nu$>=en*>t5% &ot4t>E1>t>E2>t>E#>t>E*5 (&a6e&4 JtJ 5> E&a6e&4 JE4t5J 5 gri= 8esponse through the a"ove MATLAB script is shown in &ig M+$D$

Fig. M2."

8ight#clicking away rom the curves o"tained "y 0te , i$ u&0e> and &0i$ commands "rings up a menu$ &rom this menu, various time#response characteristics can "e o"tained and plotted on the graph , )iscussion on time#response characteristics will appear later in Module B-$

SE$6o&i1 Mat3 Too&6o(

MATLAB1s >ym"olic Math ,SE$6o&i1 Mat3 ematics- tool"o% allows users to per orm sym"olic mathematical computations using MATLAB$ The only "asic re7uirement is to declare sym"olic varia"les "e ore they are used$ &or control systems analysis and design, sym"olic math tool"o% is particularly important "ecause o the ollowing( '$ Trans er unctions and other e%pressions can "e entered in sym"olic orm as we write them in the note"ook$ +$ >ym"olic e%pressions can "e manipulated alge"raically and simpli ied$ :$ 0t is straight orward to convert sym"olic polynomials to the vectors o corresponding power#term coe icients$ 5$ E%pressions can "e Kpretty printed1 or clarity in the MATLAB command window$ Type 3e& 0E$6o&i1 on the MATLAB command prompt to see all the unctionalities availa"le with >ym"olic Math tool"o%$ 0n this section, we will learn commands o >ym"olic Math tool"o% particularly use ul or control engineering$ &irst we demonstrate the power o >ym"olic Math tool"o% "y calculating inverse Laplace trans orm$ The ollowing MATLAB session gives the steps per ormed during the calculation o inverse Laplace trans orm o using >ym"olic Math$

E(er1i0e M2.8

0nitialiIe s and T as sym"ols$ Jsing >ym"olic Math tools, ind the response o the irst# order system ,with the step e%citation o strength A $

6int( &ind the inverse Laplace trans orm o E(er1i0e M2.9

&ind manually the Laplace trans orm o $ Jsing >ym"olic Math tools, declare t as sym"olic varia"le and countercheck your result$ Jse the unction laplace,g- to calculate the Laplace trans orm$

The unction 0i$ &e4D5 inds simplest orm o 5 s- with the least num"er o terms$ 0i$ &i7E4D5 can "e used to com"ine partial ractions$ >ym"olic Math tool"o% also contains other commands that can change the look o the displayed result or reada"ility and orm$ >ome o these commands are( 1o&&e1t4D5 # collects common#coe icient terms o 5,s-! e( an=4D5 ) e%pands product o actors o 5,s-! 7a1tor4D5# actors 5,s-! B a4D> &a1e05 # stands or varia"le precision arithmetic ,this command converts ractional sym"olic terms into decimal terms with a speci ied num"er o decimal places-$

3onsider the unction o

$ MATLAB response to the simpli ication

using the unction simpli y is shown "elow$

** syms s ** = C ,'@s-F,'@:-?,'@,sF5--#,5@:-?,'@,sF'-D= 1!0,1!#!40,*5)*!#!40,15 >> rettE4D5 ...................1 ....................1 1!0 , 1!# ))))))) ...) *!#...))))))) ................0 , *...............0 , 1 >> rettE40i$ &i7E4D55 .............* )))))))))))))))))))) 0 40 , *5 40 , 15

0n the a"ove e%ample, the sym"olic ractions '@: and 5@: will "e converted to 9$::: and '$:: i the argument &a1e0 in Ba 4D> &a1e05 is set to :$ >> rettE4B a4D>#55 ............0.### ....1.## 1!0 , )))))))))) ) )))))))))) ........... 0 , *. ....0 , 1.

E(er1i0e M2.10

3onsider the unction orm o its Laplace trans orm is Basic mathematical operators F, , , and

$ >how using >ym"olic Math tools that the simpli ied $ are applica"le to sym"olic o"2ects also$ &or orward#path trans er , is given "y

e%ample, simpli ication o the closed#loop system with orward gain unction , and eed"ack#path trans er unction

$ This can "e done using >ym"olic Math tool"o% as ollows >> 0E$0 0 Q% >> D = 2.-!40*40,-55% >> K = 1!40.1*0,15% >> M = Q*D!41,D*K5 M= -!2*Q!0!40,-5!41,-!2!0!40,-5!41!10*0,155 >> rettE4M5
K 5/2 -----------------------------------------/ 1 s (s + 5)| 1 + 5/2 ---------------------\ s (s + 5) (1/10 s + 1)

\ / |

>> rettE40i$ &i7E4M55

5/2

(s + 10) K ------------------------3 2 s + 15 s + 50 s + 25

With >ym"olic Math tool"o%, sym"olic trans er unctions can easily "e converted to the LT0 ,Linear Time#0nvariant- trans er unction o"2ects$ This conversion is done in two steps$ The irst step uses the command numden to e%tract the sym"olic numerator and denominator o 5 ,s-$ The second step converts, separately, the numerator and denominator to vectors using the command sym+poly $ The last step consists o orming the LT0 trans er unction o"2ect "y using the vector representation o the trans er unction1s numerator and denominator$ The command sym+poly doesn1t work on sym"olic e%pressions with more than one varia"le$ As an e%ample, we orm the LT0 o"2ect rom o"tained in the a"ove e%ample with $

The command o&E20E$ converts polynomial coe icient vectors to sym"olic polynomial$ Learn more a"out o&E20E$ using online help$

MATLAB MODULE #
>imulink O6+e1tiBe0:

Building simple >imulink simulations$ 8unning >imulink simulation to predict a system1s "ehaviour$

The MATLAB 3ontrol >ystem Tool"o% o ers unctions or inding the trans er unctions rom a given "lock diagram$ 6owever, as we shall shortly see, the simulation environment provided "y MATLABXs >imulink Toolkit o"viates the need or "lock diagram reduction$ The >imulink model mimics the "lock diagram o a eed"ack control system and is used to evaluate the response o controlled varia"le to any test input$ 0t also provides the response o any internal varia"le o the control system ,output varia"le o a su"system "lock- without the need or "lock diagram reduction$ Let us reiterate the act we have emphasiIed earlier( a good plant@process model is the "ack"one o any realistic control design$ A >imulink model "ased on the structure and parameters o the system model is constructed$ The responses o the actual system and its >imulink model are o"tained using a set o test inputs$ 0 the actual responses to the test inputs were signi icantly di erent rom the >imulink responses, certain model parameters would have to "e revised, and@or the model structure would have to "e re ined to "etter re lect the actual system "ehaviour$ Once satis actory model per ormance has "een achieved, various control schemes can "e designed and implemented$ 0n practice, it is "est to test a control scheme o #line "y evaluating the system per ormance in the Ysa etyZ o the >imulink environment$ The key components o a control system include actuators, sensors, and the plant@process itsel $ A decision to include all aspects such as ampli ier saturation, riction in the motor, "acklash in gears, dynamics o all the devices, etc$, may improve the model, "ut the comple%ity o the model may result in a more complicated controller design, which will ultimately increase the cost and sophistication o the system$ The design is usually carried out using an appro%imated model! the evaluation o the design is done on the YtrueZ model, which includes nonlinearities, and other aspects neglected in the appro%imate model$ >imulink is an e%cellent tool or this evaluation$ >0MJL04< ,>0MJlation L04<- is an e%tension o MATLAB or modeling, simulating, and analyIing dynamic, linear@nonlinear, comple% control systems$ =raphical Jser 0nter ace ,=J0and visual representation o simulation process "y simulation "lock diagrams are two key eatures which make >0MJL04< one o the most success ul so tware packages, particularly suita"le or control system design and analysis$ >imulation "lock diagrams are nothing "ut the same "lock diagrams we are using to descri"e control system structures and signal low graphs$ >0MJL04< o ers a large variety o ready#to# use "uilding "locks to "uild the mathematical models and system structures in terms o "lock

diagrams$ Block parameters should "e supplied "y the user$ Once the system structure is de ined, some additional simulation parameters must also "e set to govern how the numerical computation will "e carried out and how the output data will "e displayed$ Because >0MJL04< is graphical and interactive, we encourage you to 2ump right in and try it$ To help you start using >0MJL04< 7uickly, we descri"e here the simulation process through a demonstration e%ample with MATLAB version H$9, >0MJL04< version D$9$ To start >0MJL04<, enter simulink command at the MATLAB prompt$ Alternatively one can also click on >0MJL04< icon shown in &ig$ M:$'$

Fig. M#.1 MATLAB Desktop main menu and 64M:L428 icon

A >0MJL04< Li"rary Browser ,&ig$ M:$+- appears which displays tree#structured view o the >0MJL04< "lock li"raries$ 0t contains several nodes! each o these nodes represents a li"rary o su"system "locks that is used to construct simulation "lock diagrams$ Rou can e%pand@collapse the tree "y clicking on the "o%es "eside each node and "lock in the "lock set pan$

Fig. M#.2 64M:L428 Li,rary Browser

E%pand the node la"eled Si$u&in8$ >u"nodes o this node , <o$$on&E U0e= B&o180, <ontinuou0> Di01ontinuitie0, Di01rete, Logi1 an= Bit O eration0, etc;- are displayed$ 4ow or e%ample, e%panding the Sour1e0 su"node displays a long list o >ources li"rary "locks$ >imply click on any "lock to learn a"out its unctionality in the description "o% ,see &ig$ M:$:-$

Fig. M#.# B%ocks in 6ources su,node

Rou may now collapse the Sour1e0 su"node, and e%pand the Sin80 su"node$ A list o Sin80 li"rary "lock appears ,&ig$M:$5-$ Learn the purpose o various "locks in Sin80 su"node "y clicking on the "locks$

Fig. M#.* B%ocks in 6inks su,node

E(er1i0e M#.1 E%pand the <ontinuou0, Di01ontinuitie0, Di01rete, and Mat3 O eration0 su"nodes$ >tudy the purpose o various "locks in these su"nodes in description "o%$ We have descri"ed some o the su"system li"raries availa"le that contain the "asic "uilding "locks o simulation diagrams$ The reader is encouraged to e%plore the other li"raries as well$ Rou can also customiIe and create your own "locks$ &or in ormation on creating your own "locks, see the MATLAB documentation on YWriting ># &unctionsZ$ We are now ready to proceed to the ne%t step, which is the construction o a simulation diagram$ 0n the >0MJL04< li"rary "rowser, ollow &ile 4ew Model or hit 3trlF4 to open an

Kuntitled1 workspace ,&ig$M:$B- to "uild up an interconnection o >0MJL04< "locks rom the su"system li"raries$

Fig. M#.- :ntit%ed workspace

Let us take a simple e%ample$ The "lock diagram o a dc motor ,armature#controlled- system is shown in &ig$ M:$D

Fig. M#." B%ock dia(ram o) a dc motor armature0contro%%ed& system where

is the resistance o the motor armature ,ohms- C '$HB is the inductance o the motor armature ,6- C +$G: is the tor7ue constant ,4m@A- C 9$9E+5 is the "ack em constant ,/ sec@rad- C 9$9E+5

is the inertia seen "y the motor ,includes inertia o the load- ,kg#m+ - C is the mechanical damping coe icient associated with rotation ,4m@,rad@sec--C B$9 is the applied voltage ,volts- C B volts We will implement the model shown in &ig$ M:$D in the untitled work space ,&ig$ M:$B-$ Let us irst identi y the >0MJL04< "locks re7uired to implement the "lock diagram o &ig$ M:$D$ This is given in &ig$ M:$H$

Fig. M#.. 64M:L428 ,%ocks re*uired )or imp%ementation

0denti ying the "lock,s- re7uired or simulation purpose is in act the irst step o the construction o simulation diagram in >0MJL04<$ The ne%t step is to Ydrag and drop S the re7uired "locks rom >0MJL04< "lock li"raries to untit&e= workspace$ Let us put the very irst "lock or applied voltage ,-a- to workspace$

E%pand the Sour1e0 su"node, move the pointer and click the "lock la"eled <on0tant, and while keeping the mouse "utton pressed down, drag the "lock and drop it inside the >imulation Window! then release the mouse "utton ,&ig$ M:$G-$ 8ight clicking on the "lock will provide various options to users rom which one can cut, copy, delete, ormat ,su"menu provides acilities or rotation o the "lock, lipping, changing the ont o "lock name,$$$-, etc$$$

E(er1i0e M#.2 )rag and drop all the "locks we have identi ied ,&ig$ M:$H- rom the Li"rary Browser to the untit&e= Workspace them as shown in &ig$ M:$E$

Fig. M#.8 Dra( and drop ,%ocks to Workspace )rom Li,rary Browser

Fig. M#.9 :nconnected ,%ocks in Workspace 0t is visi"le that all the "lock parameters are in their de ault settings$ &or e%ample, the de ault trans er unction o Trans er &cn "lock is and de ault signs o >um "lock are F F$ We need to con igure these "lock parameters to meet our modeling re7uirements$ 0t is straight orward$ )ou"le click the "lock to set up its parameters$ &or e%ample, dou"le clicking the Trans er &cn "lock opens the window titled B&o18 Hara$eter0: Tran07er F1n> shown in &ig$ M:$'9$

Fig. M#.10 Trans)er )unction ,%ock parameters window

&or armature circuit trans er unction, no need to change the numerator parameter$ &or denominator parameters, enter >0MJL04< as $ or , which will "e interpreted "y

To enhance the interpreta"ility o simulation diagram, we can also change the "lock identi ication name$ >imply click on the te%t Tran07er F1n to activate the small window around the te%t to change the "lock name$ &or our simulation "lock diagram, the suita"le te%t or Tran07er F1n "lock may "e Ar$ature 1ir1uit. Be ore we move to the last step o interconnecting the "locks as per the desired structure, 2ust inish E%ercise M:$:$ 4ote that the De1i$ation parameter value "y de ault is '$ 0ncreasing this value reduces the num"er o data samples taken over the simulation time$ We have used the de ault value o '$

E(er1i0e M#.# Modi y all the "lock parameters as per system parameters given or &ig$ M:$H, and give appropriate names to the "locks$

Lines are drawn to interconnect these "locks as per the desired structure$ A line can connect output port o one "lock to the input port o another "lock$ A line can also connect the output port o one "lock with input ports o many "locks "y using "ranch lines$ We suggest readers to per orm the ollowing line@"lock operations on "locks dragged in workspace to get hands on practice$ To connect the output port o one "lock to the input port o another "lock(

'$ Position the pointer on the irst "lock1s output port! note that the cursor shape changes to cross hair$ +$ Press and hold down the le t mouse "utton$ :$ )rag the pointer to second "lock1s input port$ 5$ Position the pointer on or near the port! the pointer changes to a dou"le cross hair$ B$ 8elease the mouse "utton$ >0MJL04< replaces the port sym"ol "y a connecting line with an arrow showing the direction o signal low$

Another simple methodology doesn1t re7uire dragging the line$ B&o181 output port is re7uired to "e connected to B&o182 input port$

'$ select Block' "y clicking anywhere inside the "lock$ +$ 6old down the 3trl key$ :$ 3lick on "lock+! "oth the "locks will "e connected$

To connect the output port o one "lock with the input ports o several "locks, we can use ,ranc' %ines$ Both the e%isting line and the "ranch line carry the same signal$ To add a "ranch line, do the ollowing(

'$ Position the pointer on the line where you want the "ranch line to start$ +$ While holding down the 3trl key, le t click on the line segment! note that the cursor shape changes to cross hair$ :$ 8elease the control key, while pressing down the le t mouse "utton! drag the pointer to the input port o the target "lock$ 5$ 8elease the mouse "utton! target "lock will "e connected to the line segment$

>ome o the important line#segment and "lock operations are as ollows(

'$ To move a line segment, position the pointer on the segment you want to move$ Press and hold down the le t mouse "utton$ )rag the pointer to the desired location and release$ 4ote that this operation is valid with line segments only, not with the dedicated connecting lines "etween two "locks$ +$ To disconnect a "lock rom its connecting lines, hold down the shi t key, then drag the "lock to a new location$ 0ncoming and outgoing lines will "e converted to red colored dotted lines$ One can insert a di erent "lock "etween these lines$

E(er1i0e M#.* 3onnect all the "locks appropriately as per the "lock diagram given in &ig$ M:$H$ Make use o the "lock interconnection points discussed a"ove$

4ow let us give a name to the untit&e= workspace$ 6it <tr& , S to save the developed simulation diagram to the disk with an appropriate name$ The ile will "e saved with the e%tension .$=& , an a""reviation or the Kmodel1$ We save the ile using the name ar$atureA=1$otor.$=&% the complete simulation diagram is shown in &ig$ M:$''$

&inally, we need to set the parameters or the simulation run$ Press <tr& , E to open the simulation parameter con iguration window$ Le t panel o the window ,&ig$ M:$'+- displays a tree structured view o parameter su"menu$ 0n the So&Ber su"menu, enter the start and stop time o the simulation ,&ig$ M:$':-$

Fig. M#.11 7ina% simu%ation dia(ram , download -

Fig. M#.12 1arameter con)i(uration su,menu

Fig. M#.1# -nter simu%ation time

4ow we are ready to simulate our "lock diagram o armature#controlled dc motor$ Press

icon

to start the simulation$ 4ote that the icon changes to ! pressing this icon, one can stop the simulation "e ore stop time$ A ter simulation is done, dou"le click the S1o e "lock to display the angular velocity variation with time$ 3lick the autoscale icon in the display window to scale the a%es as per the varia"le ranges$ Autoscaled scope display is shown in &ig$ M:$'5$ With Ioom acility, try Iooming the portion o graph "etween 9$B to ' sec, and +9 to +B unit angular velocity to identi y the numerical value o angular velocity at 9$G seconds$

Fig. M#.1* 6cope disp%ay o) an(u%ar !e%ocity

>et y#a%is limits "y right#clicking the a%is and choosing A(e0 Hro ertie0$ 0n C)$in> enter the minimum value or the y#a%is$ 0n C)$a(, enter the ma%imum value or the y#a%is$ 0n Tit&e> enter the title o the plot$ >ee &ig$ M:$'B$

Fig. M#.1- 6cope a+is properties editor

3lick the icon shown on the icon "ar o &ig$ M:$'5 to open scope parameter editor ,&ig$ M:$'D-$ Denera& parameters include 9u$6er o7 a(e0, Ti$e range, Ti18 &a6e&0> and Sa$ &ing$ 3lick on the Data 3i0torE "utton$ 0 you want input#output data rom this scope to "e availa"le to MATLAB workspace or urther analysis, check the "utton SaBe =ata to ?or80 a1e$ 0n the "o% Oaria6&e na$e> enter the varia"le name or saving the data$ By de ault it will save the data with varia"le name S1o eData$ With the pop#down menu For$at, select the ormat in which you want to save the data$ Three speci ic ormats or saving the data are as ollows( '$ Stru1ture ?it3 ti$e( )ata will "e saved in structured ormat with time steps$ Type the ollowing commands in your MATLAB prompt and o"serve the outputs$

Fig. M#.1" 6cope parameter settin( window

>> S1o eData S1o eData =

ti$e: F*""#(1 =ou6&eG 0igna&0: F1(1 0tru1tG 6&o189a$e: Jar$atureA=1$otor!Angu&ar Oe&o1itEJ >tructures are used in MATLAB to store mi%ed mode data types, and individual ields o the structure can "e accessed "y Kdot type( >> S1o eData.0igna&0 an0 = Ba&ue0: F*""#(1 =ou6&eG =i$en0ion0: 1 &a6e&: JJ tit&e: JJ &otStE&e: 0 0t indicates that the ield 0igna&0 contains su" ield Ba&ue0, which is o 5DD: % ' siIe vector containing the values o angular velocity$ Try accessing the ield ti$e o S1o eData$ 1 operator$ To see the in ormation stored in the ield 0igna&0>

E(er1i0e M#.Plot the angular velocity against time using the &ot command$ =ive suita"le title to the plot and la"els to % and y a%es$ Kint: Rou need to plot S1o eData.0igna&0.Ba&ue0 against S1o eData.ti$e$

2. Stru1ture ( This is the same as Stru1ture ?it3 ti$e! the only di erence is that the time steps will not "e saved$

E(er1i0e M#." 8un the simulation with scope data to "e saved as Stru1ture ormat$ /eri y that the time ield o >cope)ata structure is actually an empty matri%$

:$ ArraE ( Array ormat is simply a two column matri% with num"er o data points "eing e7ual to num"er o rows$ The ma%imum num"er o data points limits to the num"er entered in the "o% Li$it =ata oint0 to &a0t$ 0n &ig$ M:$'D, the limit is B999 data points$ E(er1i0e M#.. 8un the simulation with scope data to "e saved as Array ormat$ 8epeat E%ercise M:$B with saved data matri%$

We have used an e%ample to show how to "uild the simulink diagram, how to enter data and carry out a simulation in the >0MJL04< environment$ The reader will agree that this is a very simple process$ >olving the ollowing e%ercises will make the readers more con ident in solving the control system design and analysis pro"lems through >0MJL04<$

E(er1i0e M#.8 This pro"lem re7uires some modi ication in the a"ove considered armature#controlled d$c$ motor >0MJL04< e%ample$ '$ The angular position is o"tained "y integrating the angular velocity$ 0mplement this in the model and display angular position in a di erent scope$ +$ 8emove the constant applied voltage "lock$ O"tain the >tep, 8amp, and >inusoidal responses o the system$ :$ >imulate a closed#loop position control system assuming a proportional controller o gain 81 $ 6int( Add a re erence input signal or angular position and add a summing "lock which calculates the error "etween the angular position re erence and the measured angular position$ Multiply this error "y the gain 81 and let this signal "e the applied voltage -a $

E(er1i0e M#.9

3onsider a dynamic system consisting o a single output

, and two inputs r and w (

where

Model the system in >0MJL04<$ &or and "oth step signals, o"tain the system output >0MJL04< "lock, etch the output to the workspace$ $ )isplay the output on scope$ Also, using a

6int( To implement deadtime, use the "lock Tran0 ort =e&aE rom <ontinuou0> and identi y suita"le "lock rom Sin80 li"rary to etch the varia"le directly to the workspace$

E(er1i0e M#.10 Assign 9$B, , and to , respectively$

>imulate )isplay plots or

or '9 seconds$ on scope, and also save to the MATLAB ile Rt$mat$

6int( Jse Mat3 Fun1tion, A==, DiBi=e, and Trigono$etri1 Fun1tion rom Mat3 O eration0 "lock li"raries$

E(er1i0e M#.11 This pro"lem is to study the e ects o Proportional ,P-, Proportional F 0ntegral ,P0-, and Proportional F )erivative ,P)- control schemes on the temperature control system$ A temperature control system has the "lock diagram given in &ig$M:$'H$ The input signal is a voltage and represents the desired temperature the control system using >0MJL04< and ind the steady#state error o the system when >imulate is a unit#step

unction and ,i-

,ii-

and ,iii-

Fig. M#.1. 6int( Jse H;D <ontro&&er "lock rom Si$u&in8 E(tra0 A==itiona& Linear to implement the P0) controller$

E(er1i0e M#.12 The "lock diagram in &ig$ M:$'G shows the e ect o a simple on#o controller on second#order process with deadtime$

Fig. M#.18

0mplement and test the model in >0MJL04< or

step inputs o B$9 and '9$9$ )isplay the control signal u, t -

and output the on separate scopes and also etch "oth the signals with time in ormation to MATLAB workspace$ Jsing MATLAB &ot unction, plot the control signal and the output! "oth against time on single graph$ 6int( To implement on#o controller, use Pe&aE rom Di01ontinuou0 "lock li"rary$

E(er1i0e M#.1# >imulate the /an der Pol oscillator, descri"ed "y the ollowing nonlinear di erential e7uation( , where is the distur"ance , orcing unction- given "y $ Assign

6int( 8ewrite the second#order /an der Pol di erential e7uation as a system o coupled irst#order di erential e7uations$ Let,

The >0MJL04< "lock diagram is to "e "uilt using Signa& Denerator, Dain, ;ntegrator, A==, and S1o e$ The output o A== "lock is $ 0ntegrating it once will lead you to and second integration will lead you to $

)ou"le click the ;ntegrator "lock to add the initial conditions

MATLAB MODULE *
&eed"ack >ystem >imulation

Tran07er Fun1tion Mani u&ation


>uppose we have developed mathematical models in the orm o trans er unctions or the plant, represented "y 5,s-, and the controller, represented "y D,s-, and possi"ly many other system components such as sensors and actuators$ Our o"2ective is to interconnect these components to orm "lock diagram representation o a eed"ack control system$ MATLAB o ers several unctions to carry out "lock diagram manipulations$ Two methods are availa"le( '$ >olution via 0erie0, ara&&e&, and 7ee=6a18 commands( 0erie04D>D5 or a cascade connection o 5,s- and D,s-! ara&&e&4D1>D25 or a parallel connection o 5',s- and 5+,s-! 7ee=6a184D>K> 0ign5 or a closed#loop connection with 5,s- in the orward path and H s- in the eed"ack path! and 0ign is #' or negative eed"ack or F' or positive eed"ack ,the sign is optional or negative eed"ack-! and 1&oo 4D>0ign5 or a unity eed"ack system with 5,s- in the orward path, and sign is #' or negative eed"ack or F' or positive eed"ack ,the sign is optional or negative eed"ack-$ +$ >olution via alge"raic operations( D*D or a cascade connection o 5,s- and D,s-! D1,D2 or a parallel connection o 5',s- and 5+,s-! D!41,D*K5 or a closed#loop negative eed"ack connection with 5,s- in the orward path and H,s- in the eed"ack path! and D!41)D*K5 or positive eed"ack systems$

SE0te$ Pe0 on0e


The trans er unction manipulations give us a trans er unction model M,s- "etween command input ;,s- and output 3,s-! model Mw,s- "etween distur"ance input W,s- and output 3,s-! a model "etween command input ;,s- and control :,s-, etc$ 0t is now easy to use some o the control analysis commands availa"le rom the 3ontrol >ystem Tool"o%$ i$ u&0e4M5 and 0te 4M5 commands represent common control analysis operations that we meet in this "ook$ Also re7uently used in the "ook are re7uency#response plots$

E(a$ &e M*.1 3onsider the "lock diagram in &ig$ M5$'$

Fig. M*.1

&or value o gain 8A C G9, the ollowing two MATLAB sessions evaluate the step responses with respect to re erence input ;,s- and distur"ance signal W,s- or

** T>tep response with respect to 8,s>> 0 = t74J0J5% >> QA = 80% >> D1 = -000!40,10005% >> D2 = 1!40*40,2055% >> M = 7ee=6a1840erie04QA*D1>D25>15 >> 0te 4M5 The MATLAB responds with Tran07er 7un1tion: .......................*00000 )))))))))))))))))))))))))))))))))))))))))))))))))) 0/# , 1020 0/2 , 20000 0 , *00000

and step response plot shown in &ig$ M5$+$ The grid has "een introduced in the plot "y right clicking on the plot and selecting Dri= option$

Fig. M*.2 >> ISte re0 on0e ?it3 re0 e1t to N405 >> 0 = t74J0J5% >> QA = 80% >> D1 = -000!40,10005% >> D2 = 1!40*40,2055% >> M? = 4)15 * 7ee=6a184D2> QA*D15 >> 0te 4M?5 MATLAB responds with Tran07er 7un1tion:

.......................)0 ) 1000 )))))))))))))))))))))))))))))))))))))))))))))))))))) 0/# , 1020 0/2 , 20000 0 , *00000 and step response plot shown in &ig$ M5$:$

Fig. M*.#

E(a$ &e M*.2 Let us e%amine the sensitivity o the eed"ack system represented "y the trans er unction

The system sensitivity to parameter 8 is

&igure M5$5 shows the magnitudes o and versus re7uency or 8 C 9$+B! generated using the ollowing MATLAB script$ Te%t arrows have "een introduced in the plot "y ollowing ;n0ert rom the main menu and selecting the option Te(t Arro?$ 4ote that the sensitivity is small or lower re7uencies, while the trans er unction primarily passes low re7uencies$ ? = 0.1:0.1:10% M = a6040.2-.!44+*?5./2,+*?,0.2-55% SMQ = a6044+*? .* 4+*? , 155.!44+*?5./2 , +*? ,0.2-55% &ot4?>M>JrJ>?>SMQ>J6J5% (&a6e&4JFrequen1E 4ra=!0e15J5% E&a6e&4JMagnitu=eJ5%

Fig. M*.* O course, the sensitivity 6 only represents ro"ustness or small changes in gain 8$ 0 8 changes rom '@5 within the range 8 C '@'D to 8 C ', the resulting range o step responses, generated "y the ollowing MATLAB script, is shown in &ig$ M5$B$ This system, with an e%pected wide range o 8, may not "e considered ade7uately ro"ust$ A ro"ust system would "e e%pected to yield essentially the same ,within an agreed#upon variation- response to selected inputs$

0 = t74J0J5% S = 40*40,155!40/2,0,0.2-5% M1 = 0.0"2-!40/2,0,0.0"2-5% M2 = 0.2-!40/2,0,0.2-5% M# = 1!40/2,0,15% 0te 4M15% 3o&= on% 0te 4M25% 0te 4M#5%

Fig. M*.-

Si$u&in8 Si$u&ation
>imulink simulation is an alternative to "lock diagram manipulation ollowed "y time#response analysis$ &rom the >imulink model o a control system, output y in response to command r, output y in response to distur"ance w, control u in response to command r, and all other desired internal varia"les can "e directly o"tained$

E(a$ &e M*.# 3ontrol system design methods discussed in this course are "ased on the assumption o availa"ility o linear time invariant ,LT0- models or all the devices in the control loop$ 3onsider a speed control system$ The actuator or the motor is a power ampli ier$ An ampli ier gives a saturating "ehaviour i the error signal input to the ampli ier e%ceeds %inear ran(e value$ MATLAB simulink is a power ul tool to simulate the e ects o nonlinearities in a eed"ack loop$ A ter carrying out a design using LT0 models, we must test the design using simulation o the actua% control system, which includes the nonlinearities o the devices in the eed"ack loop$ &igure M5$D is the simulation diagram o a eed"ack control system( the ampli ier gain is '99 and the trans er unction o the motor is 9$+9G:@,s F'$H'-$ We assume the ampli ier o gain '99 saturates at FB or #Bvolts$ The result o the simulation is shown in &ig$ M5$H$ The readers are encouraged to construct the simulink model using the procedure descri"ed in Module :$ All the parameter settings can "e set@seen "y dou"le clicking on related "locks$

Time and Output response data have "een trans erred to workspace using To Nor80 a1e "lock rom Sin80 main "lock menu$ <&o18 "lock is availa"le in Sour1e0 main menu$ These varia"les are stored in the structure Out ut and Ti$e in the workspace, along with the in ormation regarding simulink model name$ &or e%ample,

== O&tp&t O&tp&t / time> 0 2 signals> 0 x str&ct2 +lockName> :M!.3/?o @orkspace O&tp&t: == ?ime ?ime / time> 0 2 signals> 0 x str&ct2 +lockName> :M!.3/?o @orkspace ?ime:

To access output and time values, one needs to access Out ut.0igna&0.Ba&ue0 and Ti$e.0igna&0.Ba&ue0 $ The step response plot has "een generated "y the ollowing MATLAB script$
== plot5?ime.signals.Aal&es7O&tp&t.signals.Aal&es8 == xla+el5:?ime 5sec8:8B == )la+el5:O&tp&t:8B == title5:Ctep Desponse:8B

Eig. M!.#

E(a$ &e M*.* 0n this e%ample, we simulate a temperature control system with measurement noise added to the eed"ack signal$ The process trans er unction is

The deadtime minutes$ The measurement noise parameters we have used are( mean o 9, variance o 9$B, initial seed o D'+::, and sample time o 9$ The simulink inputs a step o :9 to the system ,&ig$ M5$G-$ )eadtime "lock in this igure is Tran0 ort De&aE "lock rom <ontinuou0 li"rary, and Pan=o$ 9u$6er "lock is rom Sour1e0 li"rary$

Fig. M*.8 , download -

The data has "een trans erred to the workspace using To Nor80 a1e "lock$ The step response, generated using the ollowing MATLAB script is shown in &ig$ M5$E$
== plot5?ime.signals.Aal&es74.signals.Aal&es8B == )la+el5:O&tp&t 548:8B == xla+el5:?ime5min8:8B == title5:Ctep Desponse:8B

Eig. M!.( 5he pe"fo"mance of the system with measu"ement noise "emoved& is shown in Ai,. M3.)B. 5o "emove the effect of noise& simply disconnect the Dan-om n&m+er bloc% f"om the C&m bloc% in the feedbac% path.

MATLAB MODULE 5ime 2esponse /ha"acte"istics and 65; Ciewe"

65; Ciewe"
The LT0 , Linear Time ;nvariant- /iewer is an interactive graphical user inter ace ,=J0- or analyIing the time and re7uency responses o linear systems and comparing such systems$ 0n particular, some o the graphs the LT0 /iewer can create are step and impulse responses, Bode, 4y7uist, 4ichols, pole#Iero plots, and responses with ar"itrary inputs$ 0n addition, the values o critical measurements on these plots can "e displayed with a click o the mouse$ Ta"le B$' shows the critical measurements that are availa"le or each plot$

Ta6&e -.1
Gain/p*ase marginsB Ctea-) state <ero Aal&e -B/ '11 GreH&encies -

Feak time or Feak Cettling time Dise time GreH&enc)

Fole-<ero Aal&e

Ctep Imp&lse Bo-e N)H&ist Nic*ols Fole-<ero

6ere we provide steps you may ollow to use the LT0 /iewer to plot time and re7uency responses$
). Access t*e J?I Kie@erD 5he 65; Ciewe" window& shown in Ai,. M+.)& can be accessed by typin, ltiAie@ in the M'56'7 /ommand 9indow o" by e#ecutin, this command in an M-file.

Fig. M-.1 LT4 <iewer Window +$ <reate LT; tran07er 7un1tion0( 3reate LT0 trans er unctions or which you want to o"tain responses$ The trans er unctions can "e created in an M# ile or in the MATLAB 3ommand Window$ 8un the M# ile or MATLAB 3ommand Window statements to place the trans er unction in the MATLAB workspace$ All LT0 o"2ects in the MATLAB workspace can "e e%ported to the LT0 /iewer$

The ollowing MATLAB commands create the trans er unction >> 0 = t74J0J5% >> D = 1!40,15%

*. Celect J?I transGer G&nctions Gor t*e J?I Kie@er> /hoose ImportL unde" the Eile menu in the 65; Ciewe" window and select all 65; objects whose "esponses you wish to display in the 65; Ciewe" sometime du"in, you" cu""ent session. 4electin, G "esults in Ai,. M+.*.

Fig. M-.2 4mport 6ystem Data Window

5$ Se&e1t t3e LT; o6+e1t0 7or t3e ne(t re0 on0e &ot: 8ight#click anywhere in the LT0 /iewer plot area to produce a pop#up menu$ Jnder SE0te$0, select or deselect the o"2ects whose plots you want or do not want to show in the LT0 /iewer$ More than one LT0 trans er unction may "e selected$
+. Celect t*e plot t)pe> 2i,ht-clic% anywhe"e in the 65; Ciewe" plot a"ea to p"oduce a popup menu. 0nde" Flot ?)pes& select the type of plot you want to show in the 65; Ciewe" (Ai,. M+.*).

Fig. M-.#

E(a$ &e M-.1 Take a typical underdamped second#order trans er unction and import it to the LT0 viewer window$

D$ Se&e1t t3e 13ara1teri0ti10: 8ight#click anywhere in the LT0 /iewer plot area to produce a pop#up menu$ Jnder <3ara1teri0ti10, select the characteristics o the plot you want displayed$ More than one characteristic may "e selected$ &or each characteristic selected, a point will "e placed on the plot at the appropriate location$ The characteristics menu and the su"menu are displayed in &ig$ MB$5 o"tained "y importing a typical second#order trans er unction$ 4ote the di erence in the de inition o rise time employed in the LT0 /iewer with respect to the one used in the te%t$

Fig. M-.* LT4 <iewer wit' step response p%ot and c'aracteristics

E. Interact @it* t*e plot>


o

Moom In 5Moom O&t8> 4elect the Moom In (Moom O&t) button (with the + ( ) si,n) on the tool ba". Fold the mouse button down and d"a, a "ectan,le on the plot ove" the a"ea you want to enla",e (delu,e)& and "elease the mouse button. Original Kie@> 4elect Deset to Original Kie@ in the menu popped up by "i,htclic% to "etu"n to o"i,inal view of you" plot afte" 1oomin,. Gri-> 4elect Gri- in the "i,ht-clic% menu to on o" off the ,"id. 5he "i,ht clic% menu will not wo"% if any 1oom button on the tool ba" is selected. Normali<e> 4elect Normali<e in the "i,ht-clic% menu to no"mali1e all cu"ves in view.

o o o

%*aracteristics> 2ead the values of the cha"acte"istics by placin, the mouse on the cha"acte"istics point on the plot. 6eft-clic% the mouse to %eep the values displayed (Ai,. M+.+). Froperties> 4elect Froperties in the "i,ht-clic% menu o" double-clic% anywhe"e (e#cept the cu"ve) on the ,"aph sheet to chan,e the appea"ance of the ,"aph. >ou can chan,e the title& a#es labels& and limits& font si1es and styles& colo"s& and "esponse cha"acte"istics definitions. %oor-inates an- c&rAe> 6eft-clic% the mouse at any point on the plot to "ead the system identification and the coo"dinates (Ai,. M+.+& shown by s(ua"e bloc%). A-- text an- grap*ics> 0nde" the Eile menu& choose Frint to Eig&re. 'n additional fi,u"e with toolba" will open (Ai,. M+.G).5he toolba" of this fi,u"e has additional tools fo" addin, te#t& a""ows& lines& le,ends& and to "otate the fi,u"e. A--itional plot-e-it capa+ilities> 5he E-it menu of the J?I Kie@er and the fi,u"es c"eated by selectin, Frint to Eig&re& offe" a wide va"iety of cont"ols ove" the plot p"esentation.

o o

H. Kie@er preGerences> /hoose Kie@er FreGerencesL in the E-it menu. J?I Kie@er FreGerences window (Ai,. M+.E) will open. 5his allows use"s to set pa"amete"s such as units (;nits)& style of labels (Ct)le)& "esponse cha"acte"istics definitions (%*aracteristics)& and also p"ovide a cont"ol ove" the time and f"e(uency vecto" ,ene"ation (Farameters).

Fig. M-.- Coordinate !a%ues in step response cur!e

Fig. M-." LT4 response wit' te+t and (rap'ics editor too%,ar

Ti$e Pe0 on0e <3ara1teri0ti10 in MATLAB ?in=o?


E(a$ &e M-.1 3onsider the position control system shown in &ig$ MB$G$ $

,trans er unction o motor, gears, and load-

,trans er unction o power ampli ier8A C preampli ier gain sensitivity o input and output potentiometers Time response characteristics o the system are generated "y the ollowing MATLAB script$ 0 = t74J0J5% D1 = 100!40,1005% D2 = 0.208#!40*40,1..155% Q = 1000% D = 0erie04Q*D1>D25% K = 1! i% M = 0erie047ee=6a184D>K5>K5% &tiBie?4M5%

MATLAB response is shown in &ig$ MB$E$ 0n the ollowing we compare the time response characteristics o this system with the one o"tained "y replacing the power ampli ier with a trans er unction o unity ,&ig$ MB$'9-$ 0 = t74J0J5% D1 = 1% D2 = 0.208#!40*40,1..155% Q = 1000% D = 0erie04Q*D1>D25%

K = 1! i% M1 = 0erie047ee=6a184D>K5>K5% &tiBie?4M15%

Fig. M-.9

Fig. M-.10

The second#order appro%imation seems to "e 7uite reasona"le$ The two responses in &igs MB$E and MB$'9 can "e o"tained in a single plot using the command &tiBie?4M>M15$ Alternatively, choose ;$ ort... under the Fi&e menu in the LT0 /iewer window and select M.

E(a$ &e M-.2 3onsider a unity eed"ack system shown in &ig$ MB$''$

Fig. M-.11

We will consider the ollowing three controllers( D',s- C :! D+,s-C:F,'B@ s -! and D:,s-C,:F,'B@ s -F9$: s The ollowing MATLAB code generates the step responses shown in &ig$ MB$'+$ 0 = t74J0J5% D = -9.292!40/2,".9..9*0,1-.125% D1 = #% D2 = # , 1-!0% D# = # , 1-!0 ,0.#*0% M1 = 7ee=6a184D1*D>15% M2 = 7ee=6a184D2*D>15% M# = 7ee=6a184D#*D>15% 0te 4M15% 3o&=% 0te 4M25% 0te 4M#5% We need not access LT0 viewer to ind out the time response characteristics o the closed#loop system$ The 0te command in MATLAB has this eature in"uilt in it as is seen in &ig$ MB$'+$

Fig. M-.12

4ote that adding the integral term increases the oscillatory "ehaviour "ut eliminates the steady# state error, and that adding the derivative term reduces the oscillations, while maintaining Iero steady#state error$

Fig. M-.. LT4 <iewer 1re)erences window

MATLAB MODULE Time 8esponse 3haracteristics and LT0 /iewer

Ti$e Pe0 on0e <3ara1teri0ti10 in S;MUL;9Q ?in=o?


E(a$ &e M-.# 3onsider a unity eed"ack, P0) controlled system with ollowing parameters(

Plant trans er unction(

P0) controller trans er unction(

8e erence input( A >imulink "lock diagram is shown in &ig$ MB$':$

Fig. M-.1# ,downloadThe >imulink model inputs a step o :9 to the system$ Time response characteristics o the model developed in >imulink can "e o"tained "y invoking the LT0 /iewer directly rom the >imulink$ LT0 /iewer or >imulink can "e invoked "y ollowing Too&0 )) <ontro& De0ign )) Linear Ana&E0i0 as shown in &ig$ MB$'5$

Fig. M-.1*

This opens <ontro& an= E0ti$ation Too&0 Manager shown in &ig$ MB$'B$

Fig. M-.1-

>elect lineariIation input#output points "y right clicking on the desired line and selecting Lineari2ation Hoint0 in your >imulink model$ &ig$ MB$'D e%plains the selection o input point$ >imilarly output point has "een selected$ Once input#output lineariIation points appear in the <ontro& an= E0ti$ation Too&0 Manager window, click on the Lineari2e Mo=e& at the "ottom o the window ,&ig$ M$B$'B-$ The type o response can "e selected rom the drop down menu 2ust near the Lineari2e Mo=e& "utton$ Other linear analysis plots availa"le are( Bode, 0mpulse, 4y7uist, 4ichols, Bode magnitude plot, and pole#Iero map$

Fig. M-.1"

The step response with the characteristics is shown in &ig$ MB$'H$

Fig. M-.1.

E(a$ &e M-.* 3onsider a unity eed"ack, P0 controlled system with ollowing parameters(

Plant trans er unction( Plant deat#time( C 9$'B minutes

P0 controller trans er unction( Actuator saturation characteristic( Jnit slope! ma%imum control signal C'$H$

8e erence input( A >imulink "lock diagram is shown in &ig$ MB$'G$ P0) controller "lock is availa"le in A==itiona& Linear "lock set in Si$u&in8 E(tra0 "lock li"rary$ The parameters o P0) controller "lock have "een set as ( 1 C 9$9E, 4 C 9$EB, and D C 9$

Fig. M-.18 ,download-

We can invoke LT0 /iewer to determine the time response characteristics o the system o &ig$ MB$'G$ 6owever, LT0 /iewer will lineariIe the system and then plot the characteristics$ An alternative is to trans er the output response data to workspace using To Nor80 a1e "lock and then generate the time response using the &ot command$ A MATLAB code can then "e written to determine the re7uired characteristics$ The ollowing code gives settling time, peak overshoot, and peak time or the output response data o &ig$ MB$'G$ ti$e = t.0igna&0.Ba&ue0% E = C.0igna&0.Ba&ue0% &ot4ti$e>E5% tit&e4JSte re0 on0eJ5% (&a6e&4JTi$e 4$in5J5% E&a6e&4JOut utJ5% E$a( = $a(4E5% 0te A0i2e = 10%

ea8AoBer03oot = 44E$a()0te A0i2e5!0te A0i2e5*100 in=e(A ea8 = 7in=4E == E$a(5% ea8Ati$e = ti$e4in=e(A ea85 0 = &engt34ti$e5% ?3i&e44E405>=0.9-*0te A0i2e5 T 4E405U=1.0-*0te A0i2e55 0 = 0)1% en= 0ett&ingAti$e = ti$e405 The MATLAB responds with &ig$ MB$'E and the ollowing characteristics$ ea8AoBer03oot = #9.00-8 ea8Ati$e = 1.9##9 0ett&ingAti$e = -.9.#9

Fig. M-.19

MATLAB MODULE "


>ta"ility Analysis on 8oot Locus Plots

Sta6i&itE Ana&E0i0 in State S a1e


There are several use ul MATLAB commands related to analysis and design in state space$ 3ommands use ul or sta"ility analysis in state space are( 00% 0te % initia&% eig% t7% $inrea& The MATLAB program "elow orms the matrices A,",c and d or the system

>> A = F0 1 0% 0 0 1% 0 )2 )#G% >> 6 = F0% 0% 1G% >> 1 = F1 0 0 G% >> = = 0% The output generated in the MATLAB 3ommand Window "y e%ecuting these commands is A=
0 0 0 1 0 -2 0 1 -3

6=
0 0 1

1=
1 0 0

==
0

The command 00 4A>6>1>=5 creates the state space model! let us call it 0t$o= $ The MATLAB dialogue is given "elow$ >> 0t$o= = 004A>6>1>=5 a= ......(1 .(2 (# (1 ..0 ..1 ...0 (2 ..0 ..0 ...1 (# ..0 .)2 ..)# 6= .......u1 (1 ...0 (2 ...0 (# ...1 1= ......(1 (2 (# E1 ..1 ..0 ...0 == .......u 1 E1 ....0 <ontinuou0)ti$e $o=e&.

The system 0t$o= can then "e used as an argument or many o the MATLAB commands we have already discussed$ &or instance, the command 0te 40t$o=5 generates the plot o unit#step response y,t- ,with Iero initial conditions-$ The command initia&40t$o=> (05 creates the ree response ,with input u,t- C 9- to initial condition vector %9$ Typing eig40t$o=5 in the command window produces the dialogue >> eig40t$o=5 an0 =
0 -1 -2

Thus the eigenvalues o the plant matri% A are

MATLAB has the means to per orm model conversions$ =iven the state model stmod, the synta% or conversion to trans er unction model is t mod C t ,stmod3ommon pole#Iero actors o the trans er unction model must "e cancelled "e ore we can claim that we have the trans er unction representation o the system$ To assist us in pole#Iero cancellation, MATLAB has $inera& 4t7$o=5 unction$ Asymptotic sta"ility is given "y the command eig4A5$ 0 conversion o the state model to trans er unction gives a model with no pole#Iero cancellations, the system is "oth controlla"le and o"serva"le! asymptotic sta"ility implies B0BO sta"ility and !ice !ersa$ >ta"ility analysis can "e carried out using trans er unctions under the assumption o controlla"ility and o"serva"ility o the corresponding dynamic system$ The command o&e4t7$o=5 inds the poles o a trans er unction$ The command 2$a 4t7$o=5 plots the poles and Ieros o the trans er unction$ A MATLAB code or the 8outh sta"ility criterion can easily "e written or sta"ility analysis$ 6owever, our ocus in this course is on root locus or sta"ility analysis$ The ocus in this MATLAB module will there ore "e on root locus analysis$

Poot Lo1u0 Ana&E0i0


0n the ollowing, we provide "rie description o power ul MATLAB commands or root locus analysis$ The reader may wonder why the instructors emphasiIe learning o hand calculations when power ul MATLAB commands are availa"le$ &or a given set o open#loop poles and Ieros, MATLAB immediately plots the root loci$ Any changes made in the poles and Ieros, immediately result in new root loci and so on$

)epending on our "ackground and aptitude, we may, a ter a while, "egin to make some sense o the patterns$ May "e we inally "egin to ormulate a set o rules that ena"les us to 7uickly make a mental sketch o the root locus the moment the poles and Ieros appear$ 0n other words, "y trial# and#error, we ind the rules o the root locus$ Through the systematic ormulation o set o rules o the root locus, we look or the clearest, and simplest e%planation o the dynamic phenomena o the system$ The rules o the root locus give us a clear and precise understanding o the endless patterns that can "e created "y an in inite set o characteristic e7uations$ We could eventually learn to design without these rules, "ut our level o skill would never "e as high or our understanding as great$ This is true o other analysis techni7ues also such as Bode plots, 4y7uist plots, 4ichols charts, and so on, covered later in the course$ MATLAB allows root locus or the characteristic e7uation ' F 5 ,s-H,s- C 9 to "e plotted with the r&o1u04DK5 command$ Points on the root loci can "e selected interactively ,placing the cross#hair at the appropriate place- using the FQ> G = r&o17in=4DK5 command$ MATLAB then yields the gain Q at that point as well as all the poles that have that gain$ The root locus can "e drawn over a grid generated using the 0gri= 42eta> ?n5 command, that allows constant damping ratio 2eta and constant natural re7uency ?n curves$ The command r&o1u0 4DK> Q5 allows us to speci y the range o gain Q or plotting the root locus$ Also study the commands F >QG=r&o1u04DK5 and F G=r&o1u04DK>Q5 using MATLAB online help$ E(a$ &e M".1 3onsider the system shown in the "lock diagram o &ig$ MD$'$

Fig. M".1 The characteristic e7uation o the system is ' F 5,s- C 9 with

The ollowing MATLAB script plots the root loci or 0 = t74J0J5% D = 1!40*40,.5*40,1155% r&o1u04D5% a(i0 equa&% 3licking at the point o intersection o the root locus with the imaginary a%is gives the data shown in &ig$ MD$+$ We ind that the closed#loop system is sta"le or 8 [ ':D9! and unsta"le or 8 * ':D9$

Fig. M".2 &ig$ MD$: shows step responses or two values o 8 $ >> Q = 8"0% >> 0te 47ee=6a184Q*D>15>-5 >> 3o&=%

I <urrent &ot 3e&= >> Q = 1*"0% >> 0te 47ee=6a184Q*D>15>-5

Fig. M".#

E(a$ &e M".2 3onsider the system shown in &ig$ MD$5$

Fig M".* The plant trans er unction 5,s- is given as as

The ollowing MATLAB script plots the root locus or the closed#loop system$ 1&ear a&&% 1&o0e a&&% 0 = t74J0J5% D = 40,15!40*40.1*0)155% r&o1u04D5% a(i0 equa&% 0gri=% tit&e4JPoot &o1u0 7or 40,15!040.10)15J5% FQ> G=r&o17in=4D5

Fig M".0e&e1te=A oint =

)2.220* , #.0099i Q= 1.**9* = )2.2*"8 , #.0.#*i )2.2*"8 ) #.0.#*i

E(a$ &e M".# &or a unity eed"ack system with open#loop trans er unction

a root locus plot shown in &ig$ MD$D has "een generated using the ollowing MATLAB code$ 0 = t74J0J5% D = 40/2)**0,205!440,25*40,*55% r&o1u04D5% 2eta = 0.*-% ?n = 0% 0gri=42eta>?n5% Properly rede ine the a%es o the root locus using Pig3t 1&i18 ))> Hro ertie0 ))> Li$it0.

Fig. M"."

3licking on the intersection o the root locus with 2eta=0.*- line gives the system gain 8 C 9$5'B that corresponds to closed#loop poles with 3licking on the intersection o the root locus with the real a%is gives the "reakaway point and the gain at that point$

MATLAB MODULE .
8oot Locus )esign and >0>O )esign Tools

De0ign u0ing MATLAB =ia&ogue0


E(a$ &e M..1 A unity eed"ack system has orward path trans er unction

Our goal is to design a cascade P0) compensator that improves the transient as well as steady# state per ormance o the closed#loop system ,re er 4ise,+995--$ We want to achieve a transient response that has no more than +9T overshoot$ This, as we know, can "e achieved "y simple gain ad2ustment$ We there ore irst evaluate the uncompensated system operating at +9T overshoot$ The ollowing MATLAB dialogue is help ul or this evaluation$
s . tf(<s<); I) . (s+H) ((s+*)*(s+G)*(s+)B)); 1eta . B.3+G; "locus(I)); s,"id(1eta&B);

Fig.M..1

>electing the point o intersection o the root locus with +9T overshoot line in &ig$ MH$' using r&o17in=4D5 command> MATLAB yields the gain at that point, as well as all the poles that have that gain . The MATLAB session ollows( >> FQ> G = r&o17in=4D15 Se&e1t a oint in t3e gra 3i10 ?in=o? 0e&e1te=A oint = )-.*1.1 ,10.*81*i Q= 119."-89 = )-.*1*2 ,10.*81*i )-.*1*2 )10.*81*i )8.1.1" The unit step response o the uncompensated system with 8 C''E$DBGE, is given "y the ollowing dialogue( >> M = 7ee=6a184Q*D1>15 Tran07er 7un1tion: .............119.. 0 , 9-..# ))))))))))))))))))))))))))))))))))))))))))) 0/# , 19 0/2 , 22... 0 , 11#. >> 0te 4M5

Fig. M..2

The step response is shown in &ig$ MH$+! the peak time t p C9$+ED sec$

The position error constant is

There ore

Let us now i% speci ications or design$ >ay, we want to design a P0) controller so that the closed#loop system operates with a peak time that is two#thirds that o the uncompensated system at +9T overshoot, with Iero steady#state error or a step input$ To compensate the system to reduce the peak time to two#thirds o the uncompensated system, we must irst ind the compensated system1s desired dominant pole location$ The imaginary part o the compensated dominant pole is

and the real part is

4e%t we design a P) compensator$ We search or compensator1s Iero location so that the root locus o the compensator system passes through the desired dominant pole location$ 0 we are using >0>O )esign Tool ,descri"ed later in this module-, the trial#and#error search or the compensator Iero is straight orward$ Otherwise, we may proceed as ollows$ Evaluate the angle contri"uted "y all the poles and Ieros o 5,s- at s d C #G$'BH'F / 'B$E+9+ using the ollowing MATLAB command( >> S= = )8.1-.1,1-.9202i S= = )8.1-.1 ,1-.9202i ang&eAatA=o$inantA o&e=4180! i5*4ang&e4 o&EBa&4F1>8G>S=55)4ang&e4 o&EBa&4F1>#G>S=55... ,ang&e4 o&EBa&4F1>"G>S=55,ang&e4 o&EBa&4F1>10G>S=5555 ang&eAatA=o$inantA o&e = )198.*9". We ind the sum o angles rom uncompensated system1s poles and Iero to the desired compensated dominant pole to "e #'EG$5EDHo$ Thus the contri"ution re7uired rom the compensator Iero is 'EG$5EDH 'G9 C 'G$5EDHo$ Assuming that compensator Iero is located at as shown in &ig$ MH$:, we o"tain

This gives 9c C BB$H5DH$

Thus the P) controller is

The complete root locus or the P)#compensated system is sketched in &ig$ MH$5$ Jsing r&o17in= command, the gain at the design point is B$+5'9$ 3omplete analysis o P)#compensated system is as ollows( >> D1 = 0,--..*".% >> r&o1u04D1*D15% >> 0gri=42eta>05% >> FQ> G=r&o17in=4D1*D15 Se&e1t a oint in t3e gra 3i10 ?in=o? 0e&e1te=A oint = )8.10*# ,1-."8#2i

Q= -.2*10 = )8.0.99 ,1-."91*i )8.0.99 )1-."91*i )8.0812 The Ieros are at #G,#BB$H5DH$ The e ect o third closed#loop pole is nearly cancelled "y a Iero$

Fig. M..* The P)#compensated system has settling time 9$5B5 sec$, peak time 9$'HG sec$, and steady#state error 9$9H+, as seen in simulation shown in &ig$MH$B$ >> M=7ee=6a184Q*D1*D1>15% ** step,M-

We see the reduction in peak time and improvement in steady#state error over the uncompensated system$ We now design a P0 compensator to reduce the steady#state error to Iero or a step input$ Any P0 compensator will work as long as the Iero is placed close to the origin$ This ensures that P0 compensator will not change the transient response o"tained with the P) compensator ,The placement o the Iero o the P0 compensator is not entirely ar"itrary$ The location o the Iero in luences the magnitude o the relevant error constants$ 0n the case o e%ample under consideration, the placement o the Iero in luences the magnitude o 8! -$ 3hoosing

we sketch the root locus or the P0)#compensated system$

Fig. M..The ollowing session generates the root locus and simulates the P0)#compensated system$ >> D2 = 40,0.-5!0

Trans er unction( s F 9$B ########## $$$$$s ** ) C )'?)+! ** rlocus,)?='** sgrid,Ieta,9** P<,pQCrloc ind,)?='>elect a point in the graphics window selectedSpoint C #H$+B'+ F'5$:5HGi <C 5$:E+G pC #H$5''D F'5$:995i #H$5''D #'5$:995i #G$'9:H #9$5DD9 ** step, eed"ack,<?)?=','-The Ieros are at #9$B,#G,#BB$H5DH$ The e ects o third and ourth closed#loop poles are nearly cancelled "y Ieros$

Fig. M.."

Fig. M...

>earching the 9$5BD damping ratio line ,&ig$ MH$D-, we ind the dominant second#order poles to "e , with an associated gain o 5$:E+G$ >imulation in &ig$ MH$H gives settling time +$DH sec, peak time 9$'G5 sec, and Iero steady state error$ P) compensator improved the transient response "y decreasing the time re7uired to reach the irst peak as well as yielding some improvement in the steady#state error$ The complete P0) controller urther improved the steady#state error without apprecia"ly changing the transient response designed with the P) controller$ E(a$ &e M..2 =iven a unity eed"ack position control system with orward path trans er unction(

The goal is to design a cascade compensator to meet the ollowing re7uirements ,re er 4ise,+995--$ $$$$$$$$$$$$$$$$,i- +BT overshoot, ,ii- settling time( + sec, and ,iii- 8! C +9$ The +BT overshoot corresponds to a damping ratio o 9$595$ 3onsider the ollowing MATLAB session$ 0 = t74J0J5% =' C D$D:@,,s-?,sF'$H'-?,sF'99--! Ieta C 9$595! rlocus,='-! sgrid,Ieta,9-! Properly rede ine the a%es o the root locus using Pig3t 1&i18 ))> Hro ertie0 ))> Li$it0. FQ> G = r&o17in=4D15% >elect a point in the graphics window selectedSpoint C #9$G9BH F '$GE55i ** <

<C D5$DDDB ** p pC '$9eF99+ ? #'$9995 #9$99G: F 9$9'E9i #9$99G: # 9$9'E9i

Fig. M...8

The intersection o +BT overshoot line with the root locus ,&ig$ MH$G- locates the system1s dominant second#order poles at and the gain at the dominant poles is D5$DDDB$ The location o the third closed#loop pole is at '99$95! second#order appro%imation is thus valid$ The simulation o the closed#loop system1s step response is given "y the ollowing commands(

M C eed"ack,<?=','-! step,M-!

Fig. M..9 &igure MH$E shows that the design re7uirement o +BT overshoot is met$ The settling time is 5$9H sec$ and

3omparing these values with the design re7uirements, we want to improve the settling time "y a actor o two and we want appro%imately eight# old improvement in 8! $ We irst attempt lead compensator design to improve transient response$ To o"tain a settling time ts o + secs and +BT overshoot, the real part o dominant closed#loop poles should "e at and the imaginary part at We now assume a lead compensator Iero and ind the compensator pole location so that lead# compensated root locus passes through Let us assume compensator Iero at

Angular contri"ution at the design point "y open#loop poles and compensator Iero is o"tained as ollows( S= = )2,*.-28-i% ang&eAatA=o$inantA o&e=4180! i5*4ang&e4 o&EBa&4F1>2G>S=55)4ang&e4 o&EBa&4F1>0G>S=55... ,ang&e4 o&EBa&4F1>1..1G>S=55,ang&e4 o&EBa&4F1>100G>S=5555 ang&eAatA=o$inantA o&e = )120.1#8* 3ompensator pole must contri"ute '+9$':G5 #'G9 C #BE$GD'Do or the design point to "e on the compensated system1s root locus$ &rom the geometry shown in &ig$ MH$'9,

This gives pc C 5$D+E'$

Thus the lead compensator is

8oot locus plot and its analysis or the lead#compensated system is given "y the ollowing MATLAB session$ ** )' C ,sF+-@,sF5$D+E'-! ** rlocus,)'?='-! ** sgrid,Ieta,9Properly rede ine the a%es o the root locus using 8ight click ##* Properties ##* Limits $ ** P<,pQ C rloc ind,)'?='>elect a point in the graphics window selectedSpoint C #'$ED+' F 5$55'9i

<C :H+$GH5:

pC '$9eF99+ ? #'$99+D #9$9+99 F 9$9555i #9$9+99 # 9$9555i #9$9+9G ** step, eed"ack,<?)'?=','--!

Fig. M..11

Fig. M..12

The transient response speci ications are satis ied, with gain C :H+$GH5: ,&igs$ MH$''#MH$'+-$ The lead#compensated system 8! "ecomes

>ince we want 8!C+9, the amount o improvement re7uired over the lead#compensated system is +9@D$+5D+C:$+$ 3hoose pc C9$9' and calculate 9c C9$99:+, which is :$+ times larger than pc, that is we choose the lag compensator as

8oot locus plot and its analysis or the complete lag#lead compensated system is given "y the ollowing session( D2 = 40,0.0#25!40,0.015% r&o1u04D1*D2*D15% 0gri=42eta>05% Properly rede ine the a%es o the root locus using 8ight click ##* Properties ##* Limits$ ** P<,pQ C rloc ind,)'?)+?='>elect a point in the graphics window selectedSpoint C #'$ED+' F 5$55'9i

<C :H:$BB+G

pC '$9eF99+ ? #'$99+D

#9$9'EE F 9$9555i #9$9'EE # 9$9555i #9$9+9G #9$999: ** step, eed"ack,<?)'?)+?=','--

Fig. M..1#

Fig. M..1* The design point has not moved with the addition o the lag compensator, and the gain at this point is :H:$BB+G ,&ig$ MH$':-$ We also see rom &ig$ MH$'5 that peak overshoot is higher than speci ied$ The system may "e redesigned to reduce the peak overshoot$ E(a$ &e M..# 3onsider a unity eed"ack system with the plant

The plant varies signi icantly(

0t is desired to achieve ro"ust "ehaviour ,re er )or and Bishop ,'EEG--$ A design carried on the nominal plant with 8 C', gives the ollowing cascade compensator$

&or 7ualitative ro"ustness analysis, we have o"tained step response or the our conditions( and $ The results o"tained using the ollowing MATLAB code, are summariIed in &ig$ MH$'B, and Ta"le MH$'$

0 = t74J0J5% D1 = 1!440,15/25% D2 = 1!440.-*0,15/25% D# = 2!440,15/25% D* = 2!440.-*0,15/25% D = 41,0.1"*05*4.2.-*,12!05% M1 = 7ee=6a184D1*D>15% M2 = 7ee=6a184D2*D>15% M# = 7ee=6a184D#*D>15% M* = 7ee=6a184D**D>15% 0te 4M15% 3o&=% 0te 4M25% 0te 4M#5% 0te 4M*5% The scale has "een modi ied using Pig3t 1&i18 ))> Hro ertie0 ))>Li$it0.

Fig. M..1-

Ta6&e M..1 Plant conditions Percent overshoot >ettling time ,secM' ,nominal system''$E 9$BB' M+ +$5 9$'BB M: G$DE 9$59 M5 '$D: 9$9:B'

As is seen rom this ro"ustness analysis, the deviations rom the nominal design per ormance do not take the system outside the accepta"le range! the design is there ore ro"ust$ E(a$ &e M..* A control system has the structure shown in &ig MH$'D$ The parameter variations are and with the nominal conditions 8m = + and p C5$ &urthermore, a third pole at s= B9 has "een omitted rom the model ,re er )or and Bishop,'EEG--$

Fig. M..1"

A design carried out on the nominal system gives the ollowing result$

We e%amine the per ormance o the system with nominal parameters 8m C+, p C5! and worst# case parameters 8m C'$B, p C:$ We also e%amine the nominal system with the third#pole added, so that the control plant is

The ro"ustness analysis results, o"tained using the ollowing MATLAB code, are summariIed in &ig$ MH$'H and Ta"le MH$+$ 0 = t74J0J5% D1 = 2!40*40,*55% D2 = 1.-!40*40,#55% D# = 2*-0!40*40,*5*40,-055% D = 41,0.0"*05*429*."9,**-#!05% M1 = 7ee=6a184D1*D>15% M2 = 7ee=6a184D2*D>15% M# = 7ee=6a184D#*D>15% 0te 4M15% 3o&=% 0te 4M25% 0te 4M#5%

The scale has "een modi ied using Pig3t 1&i18 ))> Hro ertie0 ))>Li$it0.

Fig M..1.

Ta6&e M..2 Plant conditions Percent overshoot >ettling time ,secM' ,nominal system:'$E 9$+DD M+ :E$+ 9$:E5 M: G'$D 9$G5H

The system does not o er ro"ust per ormance to parameter variations$ The response o the system with added pole shows that again the system ails the re7uirement o ro"ust per ormance$ >ince the results are not ro"ust, it is possi"le to iterate on the design until an accepta"le per ormance is achieved$ The interactive capa"ility o MATLAB allows us to check the ro"ustness "y simulation$

MATLAB1s >0>O )esign Tool


The S;SO , Single# ;nput@ Single# Output- De0ign Too& is a graphical user inter ace which allows one to design single#input@single#output compensators "y interacting with the root locus plots and Bode plots o the closed#loop@open#loop systems$ The tool also has the option o using a 4ichols chart, which can "e selected under the Oie? menu$ A ter the tool produces these plots, one can ad2ust the closed#loop poles along the root locus and read gain, damping ratio, natural re7uency, and pole locations$ These changes immediately get re lected to Bode plots and immediate changes in the system1s closed#loop response can "e viewed in the LT; Oie?er 7or S;SO De0ign Too& ?in=o?$ One can add poles, Ieros, and compensators, which can "e interactively changed to see the immediate e ects on the root locus, Bode plots, and time response$ With Bode plots, one can a ect the gain change "y shi ting the Bode magnitude curve up and down! and gain, gain margin, gain crossover re7uency, phase margin, phase crossover re7uency, and whether the loop is sta"le or unsta"le can "e checked$ These changes immediately get re lected to root locus plots and immediate changes in the system1s closed#loop response can "e viewed in the LT; Oie?er 7or S;SO De0ign Too& ?in=o?$ The ollowing steps are re7uired to use the S;SO De0ign Too&. 1. A11e00 t3e S;SO De0ign Too&( The S;SO De0ign Too& window, shown in &ig$ MH$'G, can "e accessed "y typing sisotool in the MATLAB 3ommand Window or "y e%ecuting this command in an M# ile$ 0n the "lock diagram given in the top#right corner o >0>O )esign Tool window, < represents the compensator$ $$$$$$$$$$$$$$$An interactive tutorial on S;SO De0ign Too& can "e invoked "y selecting S;SO De0ign Too& Ke& under the S;SO De0ign Too& window Ke& menu$ 2. <reate LT; tran07er 7un1tion0( 3reate open#loop LT0 trans er unctions or which you want to analyIe closed#loop characteristics or design compensators$ The trans er unctions can "e created in an M# ile or in the MATLAB 3ommand Window$ 8un the M# ile or MATLAB 3ommand Window statements to place the trans er unction in the MATLAB workspace$ All LT0 o"2ects in the MATLAB workspace can "e e%ported to the S;SO De0ign Too& $

The ollowing MATLAB commands create the trans er unction nu$=*-00% =en=F1 #"1.2 0G% D=t74nu$>=en5

#. <reate t3e 1&o0e=)&oo $o=e& 7or t3e S;SO De0ign Too&( 3hoose 0mport; under the &ile menu in the S;SO De0ign Too& window to display the window shown in &ig$ MH$'E$ LT0 o"2ects can "e selected rom the >0>O Models list and can "e e%ported to one o the "locks o the system "y pressing the right# acing arrow ne%t to the selected "lock , D, K, F, or < - located in the section o the window la"eled SE0te$ Data$ Press the Ot3er' "utton to rotate through a selection o eed"ack structures and select the desired con iguration$ Alternatively, this can also "e done "y pressing the FS "utton on the "ottom right corner o closed#loop "lock diagram in the >0>O )esign Tool window ,&ig$ MH$'G-$ 8oot locus and Bode diagrams will change immediately to re lect the changes in the eed"ack structure ,&ig$ MH$+9-$ LT0 trans er unction generating command, t74nu$>=en5, can also "e supplied directly into the spaces or trans er unctions in &ig$ MH$'E$

Fig. M..18 646> Desi(n Too% window

*. ;ntera1t ?it3 t3e S;SO De0ign Too&( A ter the ;$ ort SE0te$ Data window closes, the S;SO De0ign Too& window now contains the root locus and Bode plots or the system as shown in &ig$ MH$+9$ 0n this e%ample, we have considered the open#loop system given "y

$ Jnder the Ana&E0i0 menu, select the desired response to open the LT; Oie?er 7or S;SO De0ign Too& window ,&ig$ MH$+'-$ 8ight#click on the LT; Oie?er 7or S;SO De0ign Too& and choose desired H&ot TE e0, SE0te$0, and <3ara1teri0ti10$

Fig. M..19 4mport 6ystem Data Window

Loop gain can "e changed in three di erent ways( i$ ;n Poot Lo1u0 E=itor( <eep the mouse pointer on a closed#loop pole ,s7uareson the root locus$ The arrow cursor changes to a hand$ 6old down the le t mouse "utton and drag the closed#loop pole along the root locus$ Bode plot and the closed#loop response in the LT0 /iewer will immediately change to re lect the gain change$ The value o the gain will "e displayed in the <urrent <o$ en0ator section o the S;SO De0ign Too& ?in=o?$ ;n O en)Loo Bo=e E=itor( <eep the mouse pointer anywhere on the Bode magnitude curve$ The arrow cursor changes to a hand$ 6old down the le t mouse "utton and shi t the curve up or down$ 8oot locus and closed#loop response in the LT0 /iewer will immediately change to re lect the gain change$ ;n t3e <urrent <o$ en0ator Nin=o?( Type the desired gain value in the <405= "o% in the S;SO De0ign Too& ?in=o?$

ii$

iii$

With gain changes, you can read the gain and phase margins and gain crossover and phase crossover re7uencies at the "ottom o the Bode magnitude and phase plots$ Also, at the "ottom o the Bode magnitude plot, you are told whether or not the closed#loop system is sta"le$

Fig. M..20 ;oot %ocus and Bode p%ots o) 5 in 646> Desi(n Too% window

Fig. M..21 LT4 <iewer )or 646> Desi(n Too% window

-. De0ign 1on0traint0( )esign constraints may "e added to your plots$ These constraints may "e selected "y right#clicking a respective plot and selecting De0ign <on0traint0$ To put new constraints, choose 9e?' and to edit e%isting constraints, choose E=it' $ &or e%ample, &ig$MH$++ shows the selection o design constraint( damping ratioC9$B$ On pressing O<, indicators appear identi ying portions o the root locus where the damping ratio is less than 9$B,shaded gray-, e7ual to 9$B,damping line-, and greater than 9$B, &ig$MH$+: -$ 4ote the change made in a%es limits in this igure with respect to &ig$MH$+9 using the Hro ertE E=itor ,the description o the Property Editor is given in the ne%t step-$ 3onstraints may also "e edited on the plots$ Two "lack s7uares appear on the constraint$ Rou can drag these with your mouse anywhere in the plot region$ Point the mouse at the "oundary o the constraint$ When it changes to our#pointed arrow, you can drag the "oundary to a new position$ The values o the constraints are displayed in the Statu0 Bar at the "ottom o the plots$

Fig. M..22 Addin( desi(n constraints

Fig.M..2# Addin( desi(n constraints

". Hro ertie0( 8ight#clicking in a plot1s window and selecting Hro ertie0' displays the Hro ertE E=itor window$ &rom this window, some o the properties o the plot such as a%es la"els and limits can "e controlled$ Try e%ploring various options availa"le with root locus and Bode plot properties editor$

.$ A== o&e0> 2ero0> an= 1o$ en0ator0( Poles and Ieros may "e added rom the S;SO De0ign Too& window tool"ar shown in &ig$ MH$+:$ Let your mouse pointer rest on the "utton or a ew seconds to see the unctionality o the "utton in the orm o screen tips$ A== rea& o&e! A== rea& 2ero! A== 1o$ &e( o&e! A== 1o$ &e( 2ero! De&ete o&e!2ero! ..... unctions are availa"le$ Jse the S;SO De0ign Too& too&6ar and select the desired real@comple% pole@Iero compensator$ Move the mouse on the plots! your cursor shows that a compensator was selected$$ Place the cursor arrow to the point on the root locus or Bode plot where you want to add the compensator, and click$ The compensator will "e updated in the <urrent <o$ en0ator section o the S;SO De0ign Too& window$ 3ompensator addition will "e re lected immediately in the root locus, Bode plots, and LT; Oie?er 7or S;SO De0ign Too& window$ =o to S;SO Too& Hre7eren1e0' ##* O tion0 under the E=it menu to change the way the compensator is represented$ 8. E=iting 1o$ en0ator0 an= re7i&ter0: The pole and Iero values o the compensators and pre ilters can "e edited in several ways$ The most convenient is to click on < or F "locks in the "lock diagram representation in top#right corner o the S;SO De0ign Too& window ,&ig$ MH$+:-$This operation will open pre ilter or compensator editor window shown in &ig$ MH$+5$ )esired real@comple% Iero@pole locations can "e edited here$ The same windows can also "e opened "y ollowing <o$ en0ator0 E=it < or F rom the S;SO De0ign Too& window$ 0n control systems design, we use compensators o the orm

that alter the roots o the characteristic e7uation o the closed#loop system$ 6owever, the closed#loop trans er unction, M,s-, will contain the Iero o D,s- as a Iero o M,s-$This Iero may signi icantly a ect the response o the system M,s-$ We may use a pre ilter 7,sto reduce the e ect o this Iero on M,s-$ &or e%ample, i we select

we cancel the e ect o

the Iero without changing the dc gain$

Pre ilters may "e employed with lead@P) compensation$

Fig. M..2* -ditin( compensators and pre)i%ters

E(a$ &e ..* 3onsider a plant with the ollowing trans er unction(

We will design a cascade controller using >0>O )esign Tool in interactive mode, so that the unity eed"ack closed#loop system meets the ollowing criteria ,re er <uo and =olnaraghi,+99:--( >teady#state error due to unit#ramp input Ma%imum overshoot 8ise time 9$99+ sec B percent 9$99955:

>ettling time

sec

The irst step is to import the model into S;SO De0ign Too&$ >ystem trans er unctions can "e imported in >0>O )esign Tool "y clicking on Fi&e and then going to ;$ ort' Be ore e%ecuting this se7uence, create trans er unction D in MATLAB 3ommand Window( nu$=*-00% =en=F1 #"1.2 0G% D=t74nu$>=en5 0n order to e%amine the system per ormance, we start "y using a proportional controller$ The system root locus can "e o"tained "y clicking on Oie? in the main menu and then selecting Poot Lo1u0 only$ &ig$ MH$+B shows the root locus o the system$ The plot is or 8 C',"y de ault-$

Fig. M..2-

0n order to see the poles and Ieros o D and K , go to the Oie? menu and select SE0te$ Data, or alternatively, dou"le click the "lock D or K in the top#right corner o the "lock diagram in the S;SO De0ign Too& window$ The SE0te$ Data window is shown in &ig$MH$+D$

Fig. M..2"

Rou may o"tain the closed#loop system poles "y selecting <&o0e=)Loo Ho&e0 rom the Oie? menu$ 3losed#loop poles are given in &ig$MH$+H$

Fig. M..2. 0n order to see the closed#loop system time response to a unit#step input, select the Pe0 on0e to Ste <o$$an= in the Ana&E0i0 main menu$ With speci ic selections made in SE0te$0 and <3ara1teri0ti10 su"menus, we generate &ig$ MH$+G, which shows the unit step response o the closed#loop system with unity gain controller, i.e. , 8= '$

Fig. M..28 As a irst step to design a controller, we use the "uilt#in design criteria option within the S;SO De0ign Too& to esta"lish the desired closed#loop poles regions on the root locus$ To add the design constraints, use the E=it menu and choose the Poot Lo1u0 option$ >elect 9e? to enter the design constraints$ The De0ign <on0traint0 option allows the user to investigate the e ect o the ollowing( o o o o 6ett%in( time 1ercent o!ers'oot Dampin( ratio 2atura% )re*uency

We will use the settling time and the percent overshoot as primary constraints$ A ter designing a controller "ased on these constraints, we will determine whether the system complies with the rise time constraint or not$ &igure MH$+E shows the addition o settling time constraint$ Peak overshoot constraint is added on similar lines$

Fig. M..29 &igure MH$:9 shows the desired closed#loop system pole locations on the root locus a ter inclusion o the design constraints ,4ote that the scale has "een modi ied "y ollowing Pig3t 1&i18 ))> Hro ertie0 ))> Li$it0. Le t#clicking anywhere inside plot will remove the "lack s7uares on the Ieta lines-$ O"viously, closed#loop poles o the system or 8 C ' are not in the desired area$ 4ote the de inition o the desired area( the vertical gray "ar signi ies the "oundary or that portion o the root locus where the settling time re7uirement is not met! and the gray "ars on damping lines signi y the "oundary or that portion o the root locus where the peak overshoot re7uirement is not met$ 3hanging 8 will a ect the pole locations$ 0n the Poot Lo1u0 window, <405 represents the controller trans er unction$ &ig$MH$:9 corresponds to <405 C Q C 1 $ 6ence, i <405 is increased, the e ective value o 8 increases, orcing the closed#loop poles to move together on the real a%is, and then ultimately to move apart to "ecome comple%$ >ee &ig$ MH$:' wherein 8= 'D$G gives closed#loop poles on the damping lines$ 6owever, the settling time re7uirement is not met$

Fig. M..#0

Fig. M..#1 The closed#loop poles o the system must lie to the le t o the "oundary imposed "y the settling time,&ig$MH$:'-$ O"viously, it is impossi"le to use the proportional controller , or any value o 8 - to move the poles o the closed#loop system arther to the le t#hand plane$ 6owever, a P) controller C,s-C 8 ,'F sTD - may "e used to accomplish this task$ The Iero s C # '@ TD o the compensator has to "e placed ar into the le t hal plane to move the root#locus plot to the le t$ We have tried various values( s C # '@9$999B! # '@9$99'! # '@9$99'B! # '@9$99+,$$$ The value s C #'@9$999EB gives satis actory results$ To add a Iero to the controller, click the < "lock in the "lock diagram in top#right corner o &ig$ MH$:'$ &ig$MH$:+ shows the E=it <o$ en0ator window and how the P) controller is added(

Fig. M..#2 &igure MH$:: shows the plot or sC # '@9$999EB$ 4ote that the closed#loop poles have "een dragged to the desired locations$ The value o 8 that achieves the desired dominent closed#loop poles is +G+$ This value o 8 orces the closed#loop poles to the desired region$ The system closed#loop poles are shown in &ig$ MH$:5$

Fig. M..##

Fig. M..#* The step response o the controlled system in &ig$ MH$:B shows that the system has now complied with all design criteria$

&ig$ MH$:B

MATLAB MODULE 8
>ta"ility Analysis on Bode @ 4y7uist Plots

Bo=e H&ot0
&or a given trans er unction 5,s-, Bode plot can "e produced in di erent ways( '$ By simply using the command "ode ,=We will get the Bode plot o 5,s- in the current window or a de ault re7uency range set "y the MATLAB package$ MATLAB will automatically choose the re7uency values "y placing more points in regions where the re7uency response is changing rapidly$ &ig$ MG$' shows the Bode diagram or the trans er unction

,ene"ated by the followin, code. s / tG5:s:8B G / 5s+ 8/51. *s+ 8B +o-e5G8B

Fig. M8.1

+$ To produce a Bode plot over a speci ied re7uency range ?$in to ?$a(, we use the command 6o=e 4D> V?$in> ?$a(W5 &or e%ample, 6o=e4D>V0.1>10W5 will produce a Bode plot in the range 9$' to '9 rad@sec, shown in &ig$ MG$+$

Fig. M8.2 0 we supply the vector ? = F0.1% 0.#% 0.-% 0..% 0.9% 1.0% #.0% -.0% ..0% 9.0% 10G% and type 6o=e 4D>?5 MATLAB will compute the magnitude and phase at the re7uency points supplied in the re7uency vector$ 0 you choose to speci y the re7uencies e%plicitly, it is desira"le to generate the vector ? using the &og0 a1e unction$ &og0 a1e 4=1>=25 generates a vector o B9 points logarithmically e7ually spaced "etween decades '9d' and '9d+$ ,B9 points include "oth endpoints$ There are 5G points

"etween the endpoints-$ To generate B9 points "etween 9$' rad@sec and '99 rad@sec, enter the command ? = &og0 a1e 4)1>25 &og0 a1e4=1>=2>n5 generates n points logarithmically e7ually spaced "etween decades '9d' and '9d+ , n points include "oth endpoints-$ &or e%ample, to generate '99 points "etween ' rad@sec and '999 rad@sec, enter the command w C logspace ,9,:,'99:$ When invoked with le t#hand arguments, such as Pmag,phase,wQ C "ode ,=6o=e returns the re7uency response o the system in varia"les $ag> 3a0e and ?$ 4o plot is drawn on the screen$ The magnitude and phase characteristics are placed in the workspace through the matrices $ag and 3a0e$ The vector ? contains the values o the re7uency in rad@sec at which the magnitude and phase will "e calculated$ 0 we supply the vector ? and type F$ag> 3a0e> ?G = 6o=e 4D>?5 MATLAB will use the re7uency vector supplied and compute the magnitude and phase at those re7uency points$ This is clear rom the ollowing MATLAB session$ ** w C logspace,#', ', B?= 0.1000 0.#1"2 1.0000 #.1"2# 10.0000 >> F$ag> 3a0e>?G=6o=e4D>?5 $ag4:>:>15 = 1.00*9 $ag4:>:>25 = 1.0*8# $ag4:>:>#5 = 1.*0.2 $ag4:>:>*5 =

#.1"2# $ag4:>:>-5 = ..10"# 3a0e4:>:>15 = -.1#.. 3a0e4:>:>25 = 1-..#.2 3a0e4:>:>#5 = #9.289* 3a0e4:>:>*5 = -*.90#2 3a0e4:>:>-5 = #9.289* ?= 0.1000 0.#1"2 1.0000 #.1"2# 10.0000 MATLAB does not assume that the system is a >0>O system, "ut allows greater le%i"ility or dealing with more comple% systems$ MATLAB stores $ag and 3a0e varia"les as matrices o dimension p + * + n, where p is the num"er o inputs, * is the num"er o outputs, and n is the num"er o re7uency points$ &or >0>O systems, the dimension o $ag and 3a0e will "e To access the magnitude and phase points or pth input and *th output, we have to write $ag4 > q> :5 or 3a0e4 > q> :5$ &or e%ample, ** mag,',',:an0 =

1.*0.2 >> 3a0e41>1>#5 an0 = #9.289* &or >0>O systems, $ag4:>:>#5 and 3a0e4:>:>#5 will also give the same answer$ We use $ag4:>:5J> 3a0e4:>:5J to convert arrays to column vectors, where the apostrophe signi ies matri% transpose$ &or e%ample, the ollowing command stores points o the Bode plot in matri% orm with magnitude in dB, phase in degrees, and re7uency in rad@sec$ "odeSpoints C Pw, +9?log'9, mag,(,(-1 -, phase,(,(-1 Q 0n ormation a"out the plots o"tained with 6o=e can "e ound "y le t#clicking the mouse on the curve$ Rou can ind the curve1s la"el, as well as the coordinates o the point on which you clicked$ 8ight#clicking away rom a curve "rings up a menu$ &orm this menu, you can select ,isystem responses to "e displayed ,magnitude plot, phase plot, or "oth-, and ,ii- characteristics, such as peak response and sta"ility margins$ When selected, a dot appears on the curve at the appropriate point$ Let your mouse rest on the point to read the value o the characteristic$ Rou may also ,iii- select the re7uency units in 6I$, magnitude in a"solute, phase in radians, ,iv- set a%is limits, and ,v- grid etc$ A Bode plot with grid selected is shown in &ig$ MG$:$

Fig. M8.#

9Equi0t H&ot0
We can use MATLAB to make 4y7uist plots using the command nEqui0t4D5$ 0n ormation a"out the plots o"tained with this command can "e ound "y le t#clicking the mouse on the curve$ Rou can ind the curve1s la"el, as well as the coordinates o the point on which you have clicked and the re7uency$ 8ight#clicking away rom a curve "rings up a menu$ &rom this menu, you can select ,i- system responses to "e displayed ,with and without negative re7uencies-, and ,iicharacteristics, such as peak response and sta"ility margins$ When selected, a dot appears on the curve at the appropriate point$ Let your mouse rest on the point to read the value o the characteristic$ Rou may also ,iii- select the re7uency units in 6I$, ,iv- set a%is limits, and ,vgrid etc$ We can o"tain points on the plot "y using Fre i$ ?G = nEqui0t4D5, where the real part, imaginary part, and re7uency are stored in re, i$, and ?, respectively$ re and i$ are :# dimensional arrays$ We use re4:>:5J and i$4:>:5J to convert the arrays to column vectors$ We can speci y the range o ? "y using Fre>i$G = nEqui0t4D>?5$ A sample 4y7uist plot generation is illustrated "elow$ 0 = t74J0J5% D = 1!40/2,0.8*0,15% nEqui0t4D5% a(i0 equa&%

Fig. M8.*

A%is used should "e 1 equa& 1, otherwise circles appear s7uashed$ 4ote that when a MATLAB operation involves 1 DiBi=e 6E 2ero 1, the resulting 4y7uist plot may "e erroneous$ &or e%ample, 4y7uist plot o

is shown in &ig$ MG$B$ D=1!4405*40,155% ny7uist,=-

Fig. M8.-

0 such an erroneous 4y7uist plot appears, then it can "e corrected "y manipulating the a%es$ &or e%ample, manipulating the %#a%is to P#+,+Q and y#a%is to P#B,BQ in &ig$ MG$B, results in the 4y7uist plot shown in &ig$ MG$D$

Fig. M8."

>ometimes in the course o using the nEqui0t unction, we may ind that a 4y7uist plot looks nontraditional or that some in ormation appears to "e missing$ 0t may "e necessary in these cases to ad2ust the a%es and override the automatic scaling, and@or to use the nEqui0t unction with le t#hand arguments with speci ied re7uency range in con2unction with the plot unction$ 0n this way we can ocus on the critical region or our sta"ility analysis$

Sta6i&itE Margin0
We use P=M, PMQ C margin,=- to ind gain margin ,=M- and phase margin ,HM-$ We use P=M, PM, wg, wphiQ C margin,=- to ind gain margin ,=M-, phase margin ,PM-, gain crossover re7uency ,wg-, and phase crossover re7uency ,wphi-$ The margin unction is invoked in con2unction with the "ode unction to compute gain and phase margins$ 0 the $argin4D5 is invoked without le t#hand arguments, the Bode plot is automatically generated with gain margin, phase margin, gain crossover re7uency, and phase crossover re7uency la"eled on the plot$ This is illustrated in &ig$ MG$H$ 0 = t74J0J5%

D = 1!40/2,0.8*0,15% $argin4D5%

Fig. M8..

>ta"ility margins, and gain and phase crossover re7uencies are also given "y the right#clicking eature on the plots generated using the MATLAB unctions nEqui0t and 6o=e $

MATLAB MODULE 9
&re7uency 8esponse 3haracteristics

9on)unitE Fee=6a18 SE0te$0


E(a$ &e M9.1 3onsider a non#unity eed"ack system with orward#path trans er unction

and eed"ack#path trans er unction

8esonance peak, resonance re7uency, and "andwidth o the closed#loop re7uency response may "e o"tained "y generating Bode plot o the closed#loop trans er unction$ 0 = t74J0J5% D = 10!40*40,-55% K = 1!40.1*0,15% M = 7ee=6a184D>K5% ? = &og0 a1e4)1>15% 6o=e4M>?5% gri=% This MATLAB program produces Bode plots or the closed#loop system shown in &ig$ME$'$ 8ight#clicking away rom a curve "rings up a menu$ &rom this menu, select <3ara1teri0ti10 ))> Hea8 Pe0 on0e$ When selected, a dot appears on the curve at the appropriate point Let your mouse rest on the point to read the parameters o the resonance peak$ 4ow point the mouse at any point on the magnitude curve and le t#click$ The arrow curser changes to our#pointed arrow$ 6old down the le t mouse "utton and drag the our#pointed arrow along the magnitude curve$ By trial#and#error, locate the point where magnitude is # :dB$ The re7uency at this point is the "andwidth$

Fig. M9.1 &rom &ig$ME$', we o"tain the ollowing( Mr C 9$:''dB, C '$B: rad@sec$, and C :$:G rad@sec$

The gain margin and phase margin can "e o"tained rom the Bode plot o 5,s-H,s-$ The Bode plot and the per ormance measures generated "y the command $argin4D*K5 are shown in &ig$ ME$+$

Fig. M9.2

UnitE Fee=6a18 SE0te$0 on 9i13o&0 <3art


4ichols chart can "e generated using the ni13o&04D5 unction or the MATLAB trans er unction D$ 0 the ni13o&0 unction is invoked without le t#hand arguments, the 4ichols chart is automatically generated! otherwise one must use ni13o&0 in con2unction with the &ot unction$ A 4ichols grid can "e drawn with the ngri= unction$ 0n ormation a"out the plots o"tained with ni13o&04D5 can "e ound "y le t#clicking the mouse on the curve$ Rou can ind the curve1s la"el, as well as the coordinates o the point on which you clicked, and the re7uency$ 8ight#clicking away rom a curve "rings up a menu$ &rom this menu, you can select characteristics, such as peak response and sta"ility margins$ When selected, a dot appears on the curve at the appropriate point Let your mouse rest on the point to read the value o the characteristic$ Rou may also select choice or grid on or o , returning to ull view a ter Iooming, and properties, such as la"els, limits, units, style, and characteristics$

E(a$ &e M 9.2 3onsider a unity eed"ack system with open#loop trans er unction

To produce a 4ichols chart or the given system, with the closed#loop dB M#contours superimposed, use the commands(
s / tG5:s:8B G / !6/5s*5s+688B @ / 1.6>61B nic*ols5G7@8B ngri-B

The corner re7uency o the lag term is at w C B rad@sec$ We will like to include a range o re7uencies a decade a"ove and "elow this corner re7uency$ >etting the re7uency range rom 9$B to B9 rad@sec meets our re7uirements$

Eig. M(.3

We see rom &ig$ ME$: that the response line is nearly tangential to the :dB M #contour$ There ore the closed#loop re7uency has no peak value a"ove :dB$ 8esonance re7uency, read rom the plot, is B$HE rad@sec$ The intersection o the response line with # :dB contour gives the "andwidth o the closed#loop system$ Bandwidth, read rom &ig$ME$:,is E$:H rad@sec$

=ain and phase margins can also "e determined rom 4ichols chart$ 6owever, the $argin unction is a convenient alternative$

Example M9.3
0n this e%ample, we study how to ad2ust the system gain to meet speci ications on gain margin, phase margin, "andwidth and resonance peak$ We consider a unity eed"ack system with open# loop trans er unction

to illustrate the design process$ Bode plot generated using the command $argin4D5 or 8 C ' is shown in &ig$ ME$5$
s / tG5:s:8B G / "."3/55s8*5s+ .# 8*5s+ 1188B margin5G8

0n order to ind the range o 8 or sta"ility, we notice rom &ig$ME$5 that gain margin is DG$5 dB$ There ore the gain can "e raised "y "e ore the system is driven to the verge o insta"ility$ 8econsider the system with 8 C '$ We now intend to ind the gain 8 re7uired or a closed#loop response o +9T overshoot or a step input$ Jsing second#order appro%imation, a +9T overshoot implies a damping ratio o 9$5BD and, this implies a phase margin o a"out 5G degrees$ The phase angle should there ore "e at gain crossover re7uency$ Point the mouse at any point on the phase curve and le t#click$ The arrow curser changes to our#pointed arrow$ 6old down the le t mouse "utton and drag the our#pointed arrow along the phase curve$ By trial#and#error, locate the point where the phase is # ':+o$ The phase angle is at '$B rad@sec where the gain is dB ,&ig$ ME$5-$ Thus

or +9T overshoot$ >ince the system is third#order, the second order appro%imation should "e checked$ &igure ME$B shows the step response generated using the ollowing code$
N / 6,.!'B M / Gee-+ack5N*G7 8B

step5M8B

Eig. M(.! A"om Ai,. MJ.+& we find the pea% ove"shoot -B.GK.

Eig. M(.6

E(a$ &e M9.* 3onsider a unity eed"ack system with open#loop trans er unction

The 4ichols chart or 8 C ' is shown in &ig$ ME$D$


s / tG5:s:8B G / ,1/5611*s^,+"1*s+ 8B nic*ols5G8

The scale has "een modi ied using Pig3t 1&i18 ))> Hro ertie0 ))> Li$it0 $

Eig. M(."

We would like to alter 8 to provide a closed#loop resonance peak o 'dB$ &inding a value o 8 to meet this speci ication is not as straight orward as satis ying a gain margin or phase margin speci ication$ This is "ecause it is not easy "y inspection to locate the point on the original curve which would "ecome tangential to the re7uired M#contour$ We proceed "y trial#and#error$

Luckily, the use o MATLAB makes this a airly simple procedure and we ind that "y trying a couple o gain values, we can 1home in1 on the most appropriate gain setting$ &or the design pro"lem under consideration, the trial#and#error gives a gain ad2ustment "y a actor o G$+B@+9$ That is, reduction o gain "y H$DE dB$ >imilar trial#and#error procedure can "e used to meet the speci ications on "andwidth$

E(a$ &e M9.We can use MATLAB and re7uency response methods to include the time delay in the loop$ 3onsider a unity eed"ack system with the trans er unction

The response o the ollowing MATLAB script is given in &ig$ ME$H$ The scale has "een modi ied using Pig3t 1&i18 ))> Hro ertie0 ))>Li$it0.
s / tG5:s:8B G / /5s*5s+ 8*5s+ 188B +o-e5G8B *ol-B G / GB G .Inp&t$ela) / B +o-e5G 8B

0n LT0 o"2ect D1 created "y MATLAB, input delay can "e accessed "y ='$ 0nput)elay$ 0n our case, deadtime is ' second! the command D1.;n utDe&aE=1 sets the deadtime in the trans er unction model, as seen rom the ollowing MATLAB response$
== G 5"ansfe" functionD ................................... exp5- *s8 * ---------------------------....................s^3 + s^, + 1s

Eig. M(.#

MATLAB MODULE 10
Frequen1E Pe0 on0e De0ign an= S;SO De0ign Too&

De0ign U0ing MATLAB Dia&ogue0


E(a$ &e M10.1 A unity eed"ack system has orward path trans er unction

Our goal is to design a cascade P) compensator so that the closed#loop system meets the ollowing speci ications ,re er <uo and =olnaraghi ,+99:--$ >teady#state error due to unit#ramp input Phase angle 8esonance peak Bandwidth We want to achieve a steady#state response that has no more than 9$99955: error due to unit# ramp input$ This, as we know, can "e achieved "y simple gain ad2ustment$ We there ore irst evaluate the Kuncompensated system1 that meets the steady#state accuracy re7uirement$ 8 should "e set at 'G'$'H$ We now e%amine the per ormance o the uncompensated system$ The ollowing MATLAB dialogue is help ul(
s / tG5:s:8B G / 5!611* ' . #8/5s*5s+3" .,88B Gig&re5 8B margin5G8B gri-B Gig&re5,8B nic*ols5G8B ngri-B

9$99955:

Fig. M10.1

Fig. M10.2

>ince the plot in 4ichols coordinate system does not touch any o the M#contours availa"le "y de ault in the ngrid command, we may generate Bode plot o uncompensated eed"ack system to o"tain resonance peak Mr$

Fig. M10.#

The uncompensated system with 8 C 'G'$'H has ,&igs M'9$'#'9$:- a phase margin gain crossover re7uency MrC'9G$'5@+9 -, and "andwidth A P) compensator with trans er unction resonance peak Mr C +$BB+H ,

has asymptotic Bode plot o the orm shown in &ig$ M'9$5$

The logical way to approach the design pro"lem is to irst e%amine how much additional phase is needed to realiIe a o G9o$ >ince the uncompensated system with the gain set to meet the steady#state re7uirement has o only ++$Do, the P) compensator must provide an additional o phase o G9 ++$DCBH$5 $ The additional phase must "e placed at the desired gain crossover re7uency o the compensated system in order to realiIe a o G9o$ 8e erring to the asymptotic Bode plot o P) compensator shown in &ig$ M'9$5, we see that the additional phase at re7uencies * '@ TD is always accompanied "y a gain in the magnitude curve$ As a result, the gain crossover o the compensated system will "e pushed to a higher re7uency$ At new gain crossover, the phase o the uncompensated system would correspond to smaller $ Thus we may run into the pro"lem o diminishing returns$ >imple trial#and#error placement o corner re7uency o the compensator around the gain crossover re7uency can meet the design re7uirements$ The per ormance measures in the re7uency domain or the compensated system with the compensator parameters( TD C 9$999B,

9$99', 9$99'B, 9$99+, and 9$99'H, are ta"ulated in Ta"le M'9$'$ With TD C 9$99'H, the per ormance re7uirements in re7uency domain are all satis ied$

Ta6&e M10.1 TD 9$999B 9$99' 9$99'B 9$99+ 9$99'H 5D$' DB$B HG$B GB$B G'$E E': '9D9 ':+9 'DD9 '5B9 '::9 'BE9 'D99 +9B9 'DB9 M r C'9 dB@+9 '$:D:9 '$':'' '$95D5 '$9'+B '$9+E+

The ollowing MATLAB dialogue gives one result o Ta"le M'9$'( T= = 0.001.% D = 1,T=*0% 7igure415% $argin4D*D5% gri=% 7igure425% ni13o&04D*D5% ngri=% 7igure4#5% 6o=e47ee=6a184D*D>155% E%ample M'9$+ Let us reconsider the system o E%ample M'9$' ,re er <uo and =olnaraghi ,+99:--$ 0nitially we take gain 8 C 'G'$'H simply "ecause the value was used in E%ample M'9$'$ We will tune the total loop gain later to meet the steady#state per ormance re7uirement$

The uncompensated system with 8 C'G'$'H has ,re er &ig$ M'9$'-$ Let us speci y input-

C++$Do and gain crossover re7uency to "e atleast D5o , and ess ,para"olic

We know that P0 compensator is an appro%imation or the lag compensator(

The asymptotic Bode plot o a P0 compensator is shown in &ig$ M'9$B$

&rom the Bode plot o uncompensated system ,&ig$ M'9$D-, we ind that the new gain crossover re7uency at which the phase margin is D5o, is 'H: rad@sec$ The magnitude o at this C

re7uency is +'$5 dB$ Thus the P0 compensator should provide an attenuation o +'$5 dB at 'H: rad@sec$

0 = t74J0J5% D = 4*-00*181.1.5!40*40,#"1.255% $argin4D5%

Fig. M10."

A simple trial#and#error or values o that are su iciently small ,low# re7uency range- can meet the design re7uirements$ The per ormance measures in the re7uency domain or the compensated system with the compensator parameters( 81 C and 84C 9$99GB', 9$9GB', 9$GB', and '$H9+, are ta"ulated in Ta"le M'9$+$ 4ote that or the values o 81 @ 84 C

that are su iciently small, all vary little$ We choose 84 C 9$9GB'$ With this value o 84, the per ormance re7uirements in re7uency domain are all satis ied$ Ta6&e M10.2 84 9$99GB' 9$9GB' 9$GB' '$H9+ D5$: D5$' D'$' BH$H 'H: 'H: 'H: 'H5 +HE +GB :+5 :+: MrC'9 dB@+9 '$99++ '$99H9 '$9BH+ '$''H'

The ollowing MATLAB dialogue gives one o the results o Ta"le M'9$+$ Q; = 0.08-1% D = 0.08-1,4Q;!05% 7igure415% $argin4D*D5% gri=% 7igure425% ni13o&04D*D5% ngri=% 7igure4#5% 6o=e47ee=6a184D*D>155% Let us now evaluate the steady#state per ormance$

>teady#state re7uirement is thus satis ied$

0t should "e noted that o the system can "e improved urther "y increasing the value o a"ove '@9$9GB'$ 6owever, the "andwidth o the system will "e reduced$ &or e%ample, or is increased to HB$Ho "ut E(a$ &e M10.# 3onsider the unity# eed"ack system whose open#loop trans er unction is is reduced to '+H rad@sec$

The system is to "e compensated to meet the ollowing speci ications( '$ /elocity error constant 8 ! C :9$ +$ Phase margin :$ Bandwidth $ $

0t easily ollows that 8 C:9 satis ies the speci ication on 8<$ The Bode plot o with 8 C:9 is shown in &ig$ M'9$H rom which it is ound that the uncompensated system has a gain crossover re7uency 0 = t74J0J5% D = 1!40*40.1*0,15*40.2*0,155% Q = #0% $argin4Q*D5% and phase margin C 'H$+o $

Fig. M10..

0 lag compensation is employed or this system, the "andwidth will decrease su iciently so as to all short o the speci ied value o '+ rad@sec, resulting in a sluggish system$ This act can "e veri ied "y designing a lag compensator$ 0 on the other hand, lead compensation is attempted, the "andwidth o the resulting system will "e much higher than the speci ied value! the closed# loop system will "e sensitive to noise, which is undesira"le$ This act can also "e veri ied "y designing a lead compensation scheme$ Let us design a lag#lead compensator to overcome the di iculties mentioned a"ove$ >ince a ull lag compensator would reduce the system "andwidth e%cessively, the lag section o the lag#lead compensator must "e designed to provide partial compensation only$ The lag section design there ore proceeds "y making a choice o the new gain crossover re7uency, which must "e higher than the crossover re7uency i the system were ully lag compensated$ &ull lag compensation demands that the gain crossover re7uency should "e shi ted to a point where the phase angle o the uncompensated system is( Fspeci ied phase margin F &rom &ig$ M'9$H, we ind that this re7uirement is met at +$' rad@sec$ &or the design o lag section o lag#lead compensator, the selected gain crossover re7uency should "e higher than +$'$ The choice is made as to start with$

&rom &ig$ M'9$H, we ind that the gain o the uncompensated system at There ore to "ring the magnitude curve down to 9 dB at attenuation o +9$: dB$ This gives the

is +9$: dB$

, the lag section must provide an

parameter o the lag section as

Let us now place the upper corner re7uency o the lag section at '@9$G rad@sec$ This gives the lag#section trans er unction

Bode plot o lag#section compensated system is shown in &ig$ M'9$G! the phase margin is +:$Go$ D1 = 40.8*0,15!48*0,15% $argin4D1*Q*D5%

Fig. M10.8

We now proceed to design the lead section$ We choose provided "y the lead section is there ore

The ma%imum phase lead

The lag#compensated system has a gain o ,the re7uency at which the lead section has ma%imum phase

at B$D rad@sec$ >etting - C B$D rad@sec, we get

$ Take the lead section as

&rom the Bode plot and 4ichols chart o the lag#lead compensated system ,&igs M'9$E and M'9$'9-, we ind that the phase margin is BB$H o and the "andwidth is '+$B rad@sec$ The design there ore does meet the speci ications laid down$ D1 = 40.8*0,15!48*0,15% D2 = 40.-"-*0,15!40.0-"-*0,15% 7igure415% $argin4D1*D2*Q*D5% 7igure425% ni13o&04D1*D2*Q*D5% gri=%

Fig.M10.9

MATLAB MODULE 10
Frequen1E Pe0 on0e De0ign an= S;SO De0ign Too&

Po6u0tne00 Ana&E0i0
E(a$ &e M10.* A unity eed"ack system has the plant

0t is desired to achieve ro"ust per ormance$ A design carried out on nominal plant with 8 C' and p# C ', gives the ollowing cascade compensator ,re er )or and Bishop ,'EEG--$

We e%amine here the ro"ustness properties o this controller or a range o plant parameter variations o with 8 CB$ We also e%amine the ro"ustness or variations in 8 with p# i%ed at '$ The results generated using the ollowing MATLAB code are displayed in &igs M'9$'' and M'9$'+$ s C t ,1s1-! ='' C B@,,sF9$'-A+-! =+' C B@,,sF'-A+-! =:' C B@,,sF'9-A+-! ) C ,'F9$':H?s-?,5+++F+D:99@s-! M'' C eed"ack,=''?),'-! M+' C eed"ack,=+'?),'-! M:' C eed"ack,=:'?),'-! igure,'-! step,M''-!

hold! 0te 4M215% 0te 4M#15% D12 = 1!440,15/25% D22 = 2!440,15/25% D#2 = -!440,15/25% M12 = 7ee=6a184D12*D>15% M22 = 7ee=6a184D22*D>15% M#2 = 7ee=6a184D#2*D>15% 7igure425% 0te 4M125% 3o&=% step,M++-! step,M:+-! The scale has "een modi ied using Pig3t 1&i18 ))> Hro ertie0 ))>Li$it0.

Fig. M10.11 /ariations in p9

Fig. M10.12 /ariations in 8

The simulation results indicate that the P0) design is ro"ust with respect to changes in p# and 8$ The di erences in the step response or E(a$ &e M10.A unity eed"ack system has the nominal plant are "arely discerni"le on the plot$

A cascade design on the nominal system(

We e%amine here the ro"ustness o the system with respect to deadtime in the loop ,re er )or and Bishop ,'EEG--$ >imulations were carried out with

with and 9$5 secs$ The results are summariIed in &ig$ M'9$': and Ta"le M'9$:$ The MATLAB script is given "elow$ s C t ,1s1-! = C :@,:$'?sF'-! ) C ,'F9$9D?s-?,:$++F+$G@s-! M' C eed"ack,=?),'-! Pnumd',dend'QCpade,9$',+-! Pnumd+,dend+QCpade,9$5,+-! delS' C t ,numd',dend'-! delS+ C t ,numd+,dend+-! =d' C =?delS'! =d+ C =?delS+! M+ C eed"ack,=d'?),'-! M: C eed"ack,=d+?),'-!

step,M'-! hold! step,M+-! step,M:-! The scale has "een modi ied using Pig3t 1&i18 ))> Hro ertie0 ))>Li$it0.

Fig. M10.1#

Ta6&e M10.# H&ant M1 1on=ition0 42ero =ea=ti$e5 Percent D$HG overshoot >ettling time :$: ,secM2 4=ea=ti$e=0.15 G$BH +$GE M# 4=ea=ti$e = 0.*5 GE$5 H$9:

8o"ustness analysis shows that the design is accepta"ly ro"ust i deadtime is less than 9$' sec$ 6owever, or large deadtimes o the order o 9$5 sec$, the design is not ro"ust$ 0t is possi"le to iterate on the design until an accepta"le per ormance is achieved$ The interactive capa"ility o MATLAB allows us to check the ro"ustness "y simulation$

De0ign U0ing S;SO De0ign Too&


E(a$ &e 10." Let us reconsider E%ample M'9$' ,re er <uo and =olnaraghi ,+99:--$ =iven a plant with the trans er unction

we will design a cascade controller using >0>O )esign Tool in interactive mode, so that the unity eed"ack closed#loop system meets the ollowing criteria( >teady#state error due to a unit#ramp input Phase margin G99 9$99955:

8esonant peak M r BW +999 rad@sec

3reate trans er unction D in MATLAB 3ommand Window(


num=4500; den=[1 361.2 0]; G=tf(num,den)

Access the S;SO De0ign Too& window "y typing sisotool in the MATLAB 3ommand Window$ 4ow import the model = into >0>O )esign Tool $ >ystem trans er unctions can "e imported in >0>O )esign Tool "y clicking on &ile$$$ and then going to 0mport; 0n order to e%amine the system per ormance, we start "y using a proportional controller$ To e%amine the per ormance o the proportional controller, we need to ind the system Bode plots$ The Bode plots can "e o"tained "y clicking on /iew in the main menu and then selecting Open# Loop Bode only$ &ig$ M'9$'5 shows the Bode plot o the system$ The plot is or <405 C 8 C',"y de ault-$

Fig. M10.1*

We want to achieve a steady#state response that has no more than 9$99955: error due to unit# ramp input$ This, as we know, can "e achieved "y simple gain ad2ustment$ We there ore irst evaluate the Kuncompensated system1 that meets the steady#state accuracy re7uirement$ 8 should "e set at 'G'$'H$ 0n the 3urrent 3ompensator window, type the desired gain value in the <405 C "o%$ &ig$M'9$'B shows the Bode plots with <405 C 8 C'G'$'H$ The uncompensated system with 8 C 'G'$'H has a phase margin and gain crossover re7uency

Fig.M10.1-

To determine resonance peak and "andwidth o the uncompensated system, we can select O en) Loo 9i13o&0 under the Oie? menu$ &ig$M'9$'D shows the 4ichols chart$ The pointer when taken near the open#loop re7uency response curve, changes into hand$ Move the hand along the curve till it grips the point o intersection o open#loop re7uency response curve with the O : dB contour$ &ig$M'9$'D corresponds to this position! rom the data given at the "ottom portion o this igure, we o"tain "andwidth o the uncompensated systemC'599 rad@sec ,)ragging the hand on Ioomed 4ichols chart will give "etter resolution-$

Fig. M10.1" >ince the plot in 4ichols coordinate system does not touch any o the M #contours availa"le "y de ault in the gri=, we may use Bode plot o uncompensated eed"ack system to o"tain resonance peak Mr$ >elect <&o0e=)Loo Bo=e under the Ana&E0i0 menu$ &ig$M'9$'H shows the closed#loop Bode plot$ 8ight#clicking anywhere shows a su"menu$ >elect <3ara1teri0ti10 )))> Hea8 Pe0 on0e$ &ig$M'9$'H corresponds to this selection$ We get resonance peak Mr C +$BB+H , MrC'9G$'5@+9 -$

Fig. M10.1.

We attempt a P) compensator design with trans er unction

>imple trial#and#error placement o corner re7uency o the compensator around the gain crossover re7uency can meet the design re7uirements$ The per ormance in the re7uency domain or the compensated system with the compensator parameters( TD C 9$999B, 9$99', 9$99'B, 9$99+, and 9$99'H was e%amined$ With TD C 9$99'H, the per ormance re7uirements in re7uency domain are all satis ied$ E%amining this using >0>O )esign Tool will "e a good e%ercise$

Вам также может понравиться