simulink starter

4
MATLAB SIMULINK AND GUI A short tutorial by Dr. S.S.Limaye SIMULINK is a dynamic simulation package that allows the user to specify a block diagram representation of a dynamic process, and study its time domain response. The block diagram is composed of icons representing different sections of the process. Once the block diagram is "built", one has to specify the parameters in the various blocks, for example the gain of a transfer function. Assignment 1 The objective of this assignment is to observe the step-response of a linear system with given s-domain transfer function. S 2 + 2 s + 1 ---------------------------- S 4 + 2 s 3 + 3 s 2 + 2 s +1 Solution To invoke SIMULINK, you must start a MATLAB session and type simulink (SMALL LETTERS!) at the MATLAB prompt (>>). Alternatively, you may click on the simulink tool(eighth from left on the toolbar). A SIMULINK LIBRARY window should appear shortly. The left pane of the window shows the hierarchy of block library modules. By default, basic SIMULINK library is selected. The right pane shows the contents of this library, which are - Sources, Sinks, Discrete, Linear, Nonlinear, Connections, Etc. Go to the file menu in this window and choose New> Model to start a new project. A new window appears where you can build your new model. We want the output to be in the form of a graph between system output – y v/s time –t. The system stimulus (Step) is readily available in the library. For simplicity, we will output y to workspace as an array. Time array is created using “Clock” library module as signal source and sending it to workspace directly. After simulation, we will use plot(t,y) command for plotting. You will realize the importance of dumping the output variables in workspace when we combine simulink with MATLAB GUI.

Upload: yuvionfire

Post on 22-Oct-2015

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Simulink Starter

MATLAB SIMULINK AND GUIA short tutorial by Dr. S.S.Limaye

SIMULINK is a dynamic simulation package that allows the user to specify a block diagram representation of a dynamic process, and study its time domain response. The block diagram is composed of icons representing different sections of the process. Once the block diagram is "built", one has to specify the parameters in the various blocks, for example the gain of a transfer function.

Assignment 1

The objective of this assignment is to observe the step-response of a linear system with given s-domain transfer function.

S2 + 2 s + 1 ---------------------------- S4 + 2 s3 + 3 s2 + 2 s +1

Solution

To invoke SIMULINK, you must start a MATLAB session and type simulink (SMALL LETTERS!) at the MATLAB prompt (>>). Alternatively, you may click on the simulink tool(eighth from left on the toolbar).

A SIMULINK LIBRARY window should appear shortly. The left pane of the window shows the hierarchy of block library modules. By default, basic SIMULINK library is selected. The right pane shows the contents of this library, which are - Sources, Sinks, Discrete, Linear, Nonlinear, Connections, Etc.

Go to the file menu in this window and choose New> Model to start a new project. A new window appears where you can build your new model. We want the output to be in the form of a graph between system output – y v/s time –t. The system stimulus (Step) is readily available in the library. For simplicity, we will output y to workspace as an array. Time array is created using “Clock” library module as signal source and sending it to workspace directly. After simulation, we will use plot(t,y) command for plotting. You will realize the importance of dumping the output variables in workspace when we combine simulink with MATLAB GUI.

Page 2: Simulink Starter

In the left pane of the simulink window, select “Sources”. From the right pane, drag “Clock” to model editor window. Similarly, drag “Step” to model editor window. Double click on the “Step” icon to invoke its property editor. For this example, you may simply close it without any modifications, but if desired, you may change its start time to 0 instead 1 second and also change its final value. Now select “Sinks” from the left pane of the simulink library and drag “To Workspace” to model editor and place it to the right of “Clock”. Double click on the workspace icon to invoke its property editor. Enter variable name as “t”. Click on the arrow of the Save Format Edit box and select “Array” from the drop down menu. Similarly place another workspace sink to the right of “Step”, leaving plenty of gap between them. Name its signal as y and change its save format to array. Now for placing the system, select “Continuous” in the left pane of the simulink library window and from the right pane, drag “Transfer Fcn” to model editor and place it between the “Step” and the “To workspace” icons. Double click it to invoke its property editor. Enter numerator coefficient as [1 2 1] and denominator coefficient as [1 2 3 2 1].

Now we need to connect the blocks. For this purpose, hold the left mouse button on the output connector of the “Clock” icon and drag it to the input connector of the “To Workspace” icon. A simpler way is to select the “Clock” icon with a left mouse click, hold CTRL key down and then click the “To Workspace” icon. In a similar manner, connect “Step” to “Transfer Fcn” and “Transfer Fcn” to “To Workspace”. Note that a single output may be connected to more than one inputs simply by drawing lines. However we cannot combine two signals by joining the lines. We need a summing junction block for this.

Select Simulation> Configuration parameters from the menu. In this example, you need not change anything and leave everything to their default values. But it is better to select diagnostics in the left pane and set the “Automatic parameter selection” to “none”. This eliminates one useless and irritating warning.

Click the run icon.

In Matlab command prompt, type plot(t,y). Following graph should appear.

Page 3: Simulink Starter

Alternative way of seeing result

In the model editor window, remove the “To workspace” block of output. Replace it with another sink called “Scope”. Also remove the “clock” and its sink because the scope block automatically takes time as x axis. Double click on scope block to make its window visible. After pressing RUN button, the graph will be displayed but its scale will not be proper. Press the auto scale button (Shaped like a binocular). Now the graph shown below should appear.

Page 4: Simulink Starter

Assignment 2Find the step response of a feedback control system using a PI controller. The transfer function of the PI controller is

S + 2 2.5 ---------- s

And the transfer function of the plant is1

------------- s2 + 2 s +4

SolutionAs explained in the previous example, create a new model file called control1.mdl. We need to create following block diagram.

Add blocks for step, adder, gain, transfer function, transfer function and scope. The adder and gain blocks are found in the “Math operations library”. Modify each block by double clicking and making changes in the property editor. To add labels to the signal, double click just above the connecting line and enter the name.Double click the scope block and click the play button. Click the auto size button on the scope window. Following output should appear.