Simulink is a powerful system modeling tool which accompanies MATLAB. It allows the user to graphically model equations and analyze the results. By allowing the user to work at a higher level, a system can be better understood and “what-if” scenarios can be more ready explored. This particular tutorial is designed to familiarize the student with the basic tools needed to develop and run a Simulink model.
The following conventions will be used in this tutorial when describing command sequences:
- A comma is used to separate sequential commands or entries.
- The down arrow symbol ▼ indicates that a pull-down menu must be accessed to find the appropriate menu item.
- For Radio Buttons the symbol ~ will be used to indicate a selection. Menu bar items and keyboard strokes will be italicized.
- Custom entered commands will be enclosed in parenthesis i.e. “type here”
To begin, we will discuss some of the basics of using Simulink.
Opening a Simulink model:
Double click on the MATLAB icon on your desktop; the command prompt window will appear as in Fig. 1 below.
At the prompt, type Simulink, return. You will see the Simulink library browser appear as in Fig. 2 below.
From the File menu, select new, model. A new untitled window will appear. This will be the model space in which you will construct your Simulink model.
Bringing blocks into the model
To build a model, drag and drop blocks from the library into the model space. For example, to drag a Scope block into the model space, click on the Simulink library browser tree, then click on the Sinks submenu (you will see a series of icons appear on the right), now click and drag the Scope icon onto the model space. Refer to Fig. 3 below.
Other blocks can be accessed under the Simulink submenu.
Connecting and disconnecting blocks:
Lines are used to connecting blocks and allow signal transmission between blocks.
Drag and drop a Sine-wave block from the Sources submenu into the model space. Notice the output of the sign block and the input of the Scope block in Fig. 4 below.
Left-click on the output port of the Sine-Wave block (the pointer will become a cross-hair), click and drag the line towards the input terminal of the next block as in Fig. 5 below.
When you reach the input port of the next block the pointer will become a double cross-hair. Release the left mouse button. The connected blocks will appear as in Fig. 6 below.
Note: It is also possible to start with your cursor at the input port of a box and draw a line to the output port of another box.
Creating branch lines:
You can also create a branch line off of the signal line just created. To do this, press and hold the Ctrl key, now with your cursor positioned anywhere on the line, left-click and create a branch line as in Fig. 7 below.
Changing block directions:
Sometimes it will become necessary to flip a block around. This can be done easily by right-clicking on the block, selecting Format, Flip Block or Rotate Block. The results of these choices can be seen in Fig. 8 below.
Copying and moving blocks:
To create additional instances of a block, simply hold down the Ctrl key, click on the block, and drag off a copy. To move a block, simply left-click on the block, hold down on the mouse key, and drag the block to a new desired location.
Changing block labels and inserting text:
To change block labels, simply click on the label and edit as usual. To add a text box to the workspace, double-click anywhere on the workspace and a textbox will appear, type into the textbox as usual, when done, click anywhere outside the textbox.
Changing block parameters:
Block parameters are used to control block input and output. The parameter window for any block can be accessed by double-clicking on the block. For example, double-clicking on a Sum block will open the following window, shown in Fig. 9 below.
Here, it is possible to change the shape of the icon and the number of input ports. Also, the input ports can be adjusted to act as a summer ( + ) or a comparator ( – ). After changing the block parameters as required select Apply, OK to activate the new parameters. See the Summary Table for details on the parameters associated with different blocks. To aid in understanding how Simulink works, suggested values will be given for the examples in this tutorial.
Running the Simulation:
Once the block parameters have been specified, it is time to run the model simulation. Select Simulation from the menu bar, Simulation Parameters, a window will appear as in Fig. 10 below.
In general, ode45 is the standard solver and will be sufficient for most of the simulations you will be doing. For most cases the start time should be left at the default of 0, the stop time, however, should be adjusted as required to see the system response (i.e. if the stop time is set too short you may not see the full responsibility of the system). For the remaining fields, keep the default values. Once the fields have been updated select Apply, OK.
To run the simulation go to the menu bar and select the ► button in Fig. 11 below.
Viewing the Simulation Results:
To view the output of any block simply drag and drop a scope block into the model space as shown in the example above and tap off of the line of interest. After running the simulation you can view the results by double-clicking on the Scope block. A window will appear as in Fig. 12 below.
Click on the binocular icon to auto-size the window. You can also zoom in and out on the signal by selecting the appropriate buttons on the menu bar.
This concludes our basic introduction to using Simulink. You should now have the basic skills necessary to construct some simple dynamic systems models, run these models, and analyze the results.