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. 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.

drag “Step” to model editor window. We need a summing junction block for this. type plot(t. leaving plenty of gap between them. 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. connect “Step” to “Transfer Fcn” and “Transfer Fcn” to “To Workspace”. Now for placing the system. you may simply close it without any modifications. Enter variable name as “t”. But it is better to select diagnostics in the left pane and set the “Automatic parameter selection” to “none”. drag “Transfer Fcn” to model editor and place it between the “Step” and the “To workspace” icons. Similarly place another workspace sink to the right of “Step”. hold CTRL key down and then click the “To Workspace” icon. but if desired. Now we need to connect the blocks. In this example. Name its signal as y and change its save format to array. However we cannot combine two signals by joining the lines. Following graph should appear. A simpler way is to select the “Clock” icon with a left mouse click. Note that a single output may be connected to more than one inputs simply by drawing lines. Double click on the workspace icon to invoke its property editor. drag “Clock” to model editor window. Click the run icon. This eliminates one useless and irritating warning. you may change its start time to 0 instead 1 second and also change its final value. Select Simulation> Configuration parameters from the menu. For this purpose. Click on the arrow of the Save Format Edit box and select “Array” from the drop down menu. Similarly. For this example. 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”.y). Double click on the “Step” icon to invoke its property editor. From the right pane. . you need not change anything and leave everything to their default values.In the left pane of the simulink window. select “Sources”. In Matlab command prompt. select “Continuous” in the left pane of the simulink library window and from the right pane. Double click it to invoke its property editor. Enter numerator coefficient as [1 2 1] and denominator coefficient as [1 2 3 2 1]. In a similar manner.

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

gain. double click just above the connecting line and enter the name. Double click the scope block and click the play button.5 ---------s And the transfer function of the plant is 1 ------------s2 + 2 s +4 Solution As explained in the previous example. transfer function and scope. adder. The transfer function of the PI controller is S+2 2. create a new model file called control1. transfer function.Assignment 2 Find the step response of a feedback control system using a PI controller. . Click the auto size button on the scope window. To add labels to the signal. Modify each block by double clicking and making changes in the property editor. Following output should appear. We need to create following block diagram.mdl. Add blocks for step. The adder and gain blocks are found in the “Math operations library”.