Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 15

A GENTLE INTRODUCTION TO SIMULINK 1. What is SIMULINK? SIMULINK is a program with graphical programming facilities for simulating dynamic systems.

As an extension to MATLA ! SIMULINK adds many features specific to dynamic systems while retaining of MATLA "s general purpose functionality. #or example complex systems containing also nonlinearities can $e $uilt and analysed easily. A short introduction is gi%en here. #or more details we refer to the help function and the SIMULINK documentation. SIMULINK has two phases of use! model definition and model analysis. #irst a model has to $e defined or a pre%iously defined model is recalled. Then that model is analysed. To facilitate model definition SIMULINK adds a new class of windows called block diagram windows. In these windows models are created and edited $y mouse dri%en commands. After ha%ing defined a model! we can analy&e it either $y choosing options from the SIMULINK menus or $y entering commands in MATLA "s command window. The progress of a simulation can $e %iewed while the simulation is running! and the final results can $e made a%aila$le in MATLA wor'space when a simulation is complete. 2. Constructin a !o"#$ SIMULINK represents dynamic systems with $loc' diagrams. (efining a system is much li'e drawing a $loc' diagram. Instead of drawing the indi%idual $loc's! $loc's are copied from li$raries of $loc's! either the standard $loc' li$rary supplied with SIMULINK or $loc' li$raries you $uild yourself. The standard $loc' li$rary is organi&ed into se%eral su$systems! grouping $loc's according to their $eha%ior. loc's can $e copied from these or any other li$raries or models into your model. #irst! dou$le)clic' on the SIMULINK icon to in%o'e MATLA . Then! open the SIMULINK $loc' li$rary $y entering the command * simulink +. This command displays a new window containing icons for the su$system $loc's ,Fig.1.-.

Fig. 1. Simulin' $loc' li$rary /onstructing your model select N#% from the &i$# menu to open a new empty window in which you can $uild your model. 0pen one or more li$raries and drag some $loc's into your acti%e window. The su$system li$raries can $e opened $y dou$le clic'ing pro%iding their $loc's to $e copied into your model. The Sources li$rary! for example! contains $loc's creating input signals ,Fig. 2.-.

Fig. 2. Sources li$rary Fig.3. shows the most commonly used $loc's collected in the Extras su$li$rary. Using the $loc's of the li$raries different systems! e.g. continuous or discrete control systems can $e $uilt and analysed. To $uild your model you can drag the appropriate $loc's $y the left mouse $utton
1

from their li$raries to your file to the re2uired position where you release the $utton. To connect two $loc's use the left mouse $utton to clic' on either the output or input port of one $loc'! drag to the other $loc'3s input or output port to draw a connecting line! and then release the $utton. y clic'ing on the $loc' with the right $utton you can duplicate it. The $loc's can $e increased! decreased! rotated. 0pen the $loc's $y dou$le clic'ing to change some of their internal parameters. Sa%e the system $y selecting Sa'# from the &i$# menu. 4un a simulation $y selecting Start from the Si!u$ation menu. Simulation parameters can $e changed. 5ou can monitor the $eha%ior of your system with a Scope or a 6raph $loc' or you can use the To 7or'space $loc' to send data to the MATLA wor'space and perform MATLA functions ,e.g. plot- on the results.

. Fig. 3. The most commonly used $loc's Some useful remarks: After ha%ing selected the $loc' can $e rotated in the Style and Options menu points. The measure of the $loc' can $e changed $y catching and mo%ing its corner. A part of the $loc' diagram consisting of se%eral $loc's can $e condensed into a single one $loc' from the Options menu with point Group.

Example 1 Fig.4. illustrates the SIMULINK diagram of a continuous control system. The $loc's ha%e $een dragged from the Sources, inear, !onlinear an" Sinks li$raries respecti%ely. The input signal is a unit)step starting at t9.. The simulation time was :;! the simulation step ;... 4unge)Kutta integration algorithm was chosen from the Simulation menu. Fig. #. an" $. shows the course of the output signals as displayed in the Grap% windows. oth of the output signals transported to MATLA wor'spaces can also $e plotted $y MATLA plot,t!x.- and plot,t!y- command. It is seen! that the y output signal trac's the reference input signal without steady)state error due to its integrating characteristics. The dead time causes the : seconds delay $etween the changing of the output and the input signal. The x. control signal on the plot shows an o%ershoot! which has a maximum %alue of ..:. The minimum and maximum %alue of the output signal can $e determined $y matla$< min,y-9;! max,y-9..;=..

Fig. 4. Simulin' $loc')diagram of a control system

Fig. #. The control signal

Fig. $. The output signal

Example 2 &n'estigating t%e effect of saturation

Fig..(. Nonlinear system with saturation

Fig. )a The effect of saturation on the output signal

Fig. )* The control signal with saturation at S9: and S9.;;

Fig. (. gi%es an o%er%iew on the effect of the saturation. This model shows the saturating characteristics of the physically reali&a$le controllers. The input signal is a unit step starting at t9.. If the controller saturates at :! so the output signal will react slower $ecause of the limited control signal ,Fig. )a an" )*-. 7e can ma'e the model more compact $y grouping the parts of the controller into one su$system , Fig. +.-. 7e can do this $y selecting the components with mouse and grouping them with the group command from the options menu.

Fig. +.

(. L#'#$s o) us# There are three different ways to use SIMULINK! the most interacti%e way is to control the simulation from the menu $ar! and to %iew the $eha%ior of the system with the Scopes or 6raphs. This method is simple to use! 2uic' to learn! and can pro%ide fast results. The second way is to use the $uilt)in simulation and analysis function from the command line. This method is not as interacti%e as the first method $ut pro%ides greater flexi$ility. 6etting the results of simulation into the MATLA wor'space allows further analysis and data %isuali&ation using MATLA "s $uilt)in graphics tools. The most complex and flexi$le way to use SIMULINK is to access a model"s S) function directly. >%ery SIMULINK model is a%aila$le in MATLA as an S)function that em$odies the dynamical $eha%ior of the system. Simulation of SIMULINK models in%ol%es the numerical integration of sets of ordinary differential e2uations. SIMULINK pro%ides a num$er of integration algorithms for the simulation of such e2uations. The appropriate choice of method and the careful selection of simulation parameters are important considerations for o$taining accurate results. A simulation can $e started from either the command line or the simulation menu. All of the methods use the same arguments and menu parameters.

Simulation from t%e ,enu A simulation can $e run $y selecting Start from the Si!u$ation menu. Set the simulation parameters in the control panel dialog $ox! which is displayed $y selecting *ara!#t#rs from the Si!u$ation menu. The /ontrol ?anel dialog $ox has fields in which you can enter num$ers or any legal MATLA expression! for example! the %aria$les tstart, tfinal, minstep, maxstep, and final which can $e defined in the MATLA wor'space. The return %aria$les @t!x!yA are used to put the time! state! and output traBectories into MATLA wor'space. The start and stop times for the simulation are set in %aria$les tstart and tfinal. The integration parameters final, minstep and maxstep control the relati%e local error! minimum step si&e! and maximum step si&e of the simulation. /ertain operations can $e performed interacti%ely during the simulation. #or example the parameters of a $loc' can $e changed pro%ided this does not cause a change in the num$er of states! inputs or outputs of that $loc'C any of the simulation parameters can $e changed ! except return %aria$les and the start timeC the simulation algorithm can $e changedC for discrete $loc's you can change the sampling time. 5ou can clic' on a line to see its output on a floating scope. An unconnected scope is called a floating scope.

Simulation from t%e -omman" ine Any simulation run from the menu can also $e run from the MATLA command line. #or example @t!x!yA9linsim,3model3!@tstart!tfinalA!x;!@final!minstep!maxstepA-C where mo"el is the name of the $loc' diagram system. Initial conditions are defined in the %ector x;. These conditions o%erride the initial conditions set in the $loc's. Specifying no lefthand arguments automatically plots the outputs or the state traBectories. A simulation can $e run from an m)file allowing parameters in the $loc's to $e iterati%ely changed. All of the integration algorithms ha%e identical calling syntax ,e.g. instead of linsim euler! r'18! r'=:! adams or gear respecti%ely-. .ie/ing output tra0ectories The output traBectories from SIMULINK can $e plotted $y Scope or 6raph $loc's! or $y return %aria$les and the MATLA plotting commands! or $y To 7or'space $loc's and MATLA plotting commands. +. Chan in ,ara!#t#rs o) SIMULINK -$oc.s )ro! MATLA/ *setEparam+ is used to set SIMULINK $loc' parameters from the MATLA command line. Its syntax is or setEparam,name! parameter! %aluesetEparam,name! parameter! %alue!parameter1!%alue1F-

Specific $loc' parameters %ary with each type of $loc'. The names and effects of each $loc'"s specific parameters can $e found in the entry for that $loc'.

Example 3 The Simulin' $loc' diagram of a control system is show in Fig 2.11. The system sa%ed with the name Gdtime".

Fig.11. Simulin' $loc')diagram of Gdtime" system Follo/ing ,23 24 program s%o/s %o/ to c%ange t%e controller "enominator from t%e ,23 24 /in"o/:
for i=4:2:10 den=[i 0]; %we set the controllers integrating time constant %to different values (1 4s!!!1 10s" set#$aram(%dtime controller%&%'enominator%&%den%"; %sets dtime s(stem& controller $art& 'enominator value to den [t&)&(]=r*2+(%dtime%&,0"; %,0 sec simulation for each denominator value (au)=)(:&2"; %2nd column of ) gives the out$ut signal $lot(t&(au)"&grid hold on shg $ause end

Fig.11.

Example 4 -%anging t%e gain an" t%e "amping factor in a secon" or"er system

Fig. 12. Simulin' diagram of a second order system The gain and the damping factor of the second order system shown in Fig.12. changes. The program changes te gain to .! 1 and 8 respecti%ely while the damping factor is ;.1 and plots the output signals in the same diagram,Fig. 13.The system is sta$le! $ut an oscillating transient is present in the outputs due to the small %alue of the damping factor. If we increase the damping factor! the output signal $ecomes aperiodic. The second part of the MATLA program shows the output signal at different %alues of the damping factor,Fig. 14.-.
for i=1:+ -=i; set#$aram(%set$ar -ain%&%-ain%&%-%"; set#$aram(%set$ar .ransfer /cn%&%'enominator%&%[1 0!4 1]%"; % 0hange the gain [t&)]=linsim(%set$ar%&+0"; % 1ntegration algorithm for simulation& final time=+0 (=)(:&2"; % .he out$ut is the second state varia2le for 3=1:(length(t"" (((3&i"=((3"; end end $lot(t&((&%w%"&grid $ause % 0hange the dam$ing factor -=1; [t1&)]=linsim(%set$ar%&+0"; (1=)(:&2"; set#$aram(%set$ar .ransfer /cn%&%'enominator%&%[1 4 1]%"; [t2&)]=linsim(%set$ar%&+0"; (2=)(:&2"; $lot(t1&(1&%w%&t2&(2&%w%"&grid

Fig. 13. /hanging the gain

Fig. 14. /hanging the damping factor

0. S1)unctions 7hen creating a SIMULINK model in a graphical way! a new function! called S) function $ecomes a%aila$le in MATLA with syntax s2s3!o"#$4t565u5)$a 7 or 8s2s5695str5ts:3!o"#$4t565u5)$a 5,ara!#t#r15,ara!#t#r25;7 Mo"#$ is the name of the function. &$a controls the type of information returned in %aria$le s2s at operating point defined $y the time t! state %ector 6 and input %ector u. ts means the sampling time! str ma'es possi$le e%aluating a string! ,ara!#t#rs are optional. The flag options are< flag9; S)function returns si&es of parameters and initial conditions as sys,.- num$er of continuous states! sys,1- num$er of discrete states! sys,8- num$er of outputs! sys,=- num$er of inputs! sys,:- num$er of discontinuous roots! sys,D- flag for direct feedthrough ,used for finding alge$raic loopssys,H- is . for sampled systems. S)function returns the discrete state x,nK.-. S)function returns the output %ector y. S)function returns the next time inter%al for a discrete update.

flag91 flag98 flag9=

SIMULINK figures out the flag options from the diagram.

7riting a MATLA m)file with the syntax a$o%e and con%erting it to a SIMULINK $loc' our file could $e used as any other $loc's in the SIMULINK li$raries. So we can
.;

$uild up our own user su$)li$rary. / or #04T4AN su$routines written in gi%en format can also $e con%erted to SIMULINK $loc's. 0.1 E6a!,$# )or %ritin an S1)unction an" con'#rtin it to a SIMULINK -$oc. Let3s write a discrete ?I algorithm reali&ing the following pulse transfer function $etween the control signal and the error signal<
6 , 5 . - = 5 5. ', 5 =k u, 55 .

or $y the difference e2uation %,nh-9'Lu,nh-)'L&.Lu,,n).-h-K%,,n).-hwhere h denotes the sampling time and n is the actual time sample. 0.1.1 Writin th# S1)unction The MATLA m)function can $e written $y any text processor! e.g. $y Notepad. The function ,ia$ 2 with parameters . and <1 is the following< )unction 8s2s5695str5ts:3,ia$ 24t565u5)$a 5.5<15"t5'!in5'!a67 Mdiscrete ?I algorithm M%,nh-9'Lu,nh-)'L&.Lu,,n).-h-K%,,n).-hM dt sampling time! the same as h. if a$s,flag-991 sys,.-9'L,.)&.-LuKx,.-C elseif flag998 %9'LuKx,.-C if %N%max %9%maxC elseif %O%min %9%minC else %9%C end sys,.-9%C Moutput signal elseif flag99= sys,.-9tKdtC t9sys,.-C elseif flag99; sys,.-9;C Mnum$er of continuous states sys,1-9.C Mnum$er of discrete states sys,8-9.C Mnum$er of outputs sys,=-9.C Mnum$er of inputs sys,:-9;C sys,D-9;C sys,H-9.C x,.-9;C ts9@dt!;AC
..

else sys9@AC end 0.1.2 Con'#rtin th# S1)unction to a SIMULINK -$oc. 0pen a new SIMULINK file from the SIMULINK window. ring here the S)function $loc' from the Nonlinear su$)li$rary! and open it gi%ing the name of the function ,pialg- and the parameters! separated $y comma! as

Fig. 1#. 7arametri5ation of t%e S8function

.1

Mas' the $loc' as

Fig. 1$. Mas'ing the ?I controller $loc' Then sa%e the $loc' in your own su$)li$rary made a%aila$le for MATLA adding it to matla$path in file matla$rc.m . Then the $loc' can $e dragged in a SIMULINK diagram! as e.g. creating a simulation en%ironment shown in Fig. 1(.

Fig.1(. Using the $loc' in SIMULINK en%ironment

.8

y dou$le clic'ing to our ?I $loc' we can gi%e its parameters. #or example '9. and &.9;.:. The output signal of the controller is shown in Fig. 1).

Fig. 1). Step response of the ?I controller The ?I controller can $e $uilt in a control loop as shown in Fig. 1+.

Fig. 1+. /ontrol loop with the ?I controller 7ith '9;.= and &.9;.: the output signal is shown in Fig. 21. It has to $e mentioned that calculations start in the first sample.

Fig. 21. Step response of the discrete control loop Fig. 21. shows a hy$rid control circuit when a continuous plant gi%en $y its transfer function is controlled $y the discrete ?I controller. In this case it is not necessary to put a &ero order hold element $etween the controller and the plant as SIMULINK recogni&es this situation and 'eeps the control signal during the sampling time. The simulation step may $e less then the control step defined in S)function pialg.
.=

Fig. 21. A hy$rid control circuit with discrete ?I controller

Fig. 22. /ontrol and output signals in the hy$rid control circuit Fig. 22. illustrates the output and the control signal for '9;.I and &.9;.:. The control step was . sec while the simulation step was ;...

.:

You might also like