INTRODUCTION TO SIMULINK
by
Yasmin Hanum Md Thayoob
&
Aidil Azwin Zainul Abidin
TABLE OF CONTENTS
What Is Simulink? Creating Subsystems
Starting Simulink Simulation Parameters
Simulink Windows Running A Simulation
Simulink Library Getting Output
Creating A New Model Using Scope
Entering Simulink Further Considerations
Commands Ending A Simulink
Connecting Blocks Session
Modeling In Simulink Case Study
Example 1
References
Example 2
What Is Simulink
Simulink is a graphical method of modeling and
simulating a mathematical equation or a system in
Matlab.
Simulink is not a stand alone program which
means that it could not be run without running
Matlab.
Whatever variable defined in Matlab can be used
in Simulink.
Starting Simulink
To start Simulink, you must first start MATLAB. Consult
your MATLAB documentation for more information. You
can then start Simulink in two ways:
Click the Simulink icon on the MATLAB toolbar.
Enter the simulink command at the MATLAB prompt.
On Microsoft Windows platforms, starting Simulink
displays the Simulink Library Browser
Simulink Windows
Simulink uses separate windows to display:
a block library browser
a block library
a model
graphical (scope) simulation output
These windows are not MATLAB figure
windows and cannot be manipulated using
HandleGraphics® commands.
Simulink Library
The Library Browser displays a
tree-structured view of the
Simulink block libraries installed
on your system. You can build
models by copying blocks from
the Library Browser into a model
window.
Sources and Sinks
Continuous and Discrete Systems
All dynamic systems can be analyzed as continuous or discrete time
systems. Simulink allows you to represent these systems using transfer
functions, integration blocks, delay blocks etc.
Simulink Extras
Figure 5 contains some advanced linear blocks, available in the
“Simulink Extras” ibrary. They contain certain advanced blocks, such
as a PID control block, transfer functions with initial conditions, etc.
Non-linear operators
Functions and Tables
Math Block (Mathematical tools)
Signals & Systems Block
(Signals and data transfer)
In complicated block diagrams,
there may arise the need to
transfer data from one portion
to another portion of the block.
They may be in different
subsystems. That signal could
be dumped into a GOTO block,
which is used to send signals
from one subsystem to another.
Multiplexing helps us remove
clutter due to excessive
connectors, and makes matrix
(column/row) visualization
easier.
Subsystems Block
Creating a New Model
Click the New button on the Simulink Library Browser’s
toolbar (Windows only) or choose New from the library
window’s File menu and select Model. You can move the
window as you do other windows.
You can build models by copying blocks from the Library
Browser into a model window (this procedure is described
later in the modeling example ).
• Simulink opens a new model window as below.
Entering Simulink Commands
You run Simulink and work with your model by entering
commands. You can enter commands by:
•Selecting items from the Simulink menu bar
•Selecting items from a context-sensitive Simulink menu (Windows
only)
•Clicking buttons on the Simulink toolbar (Windows only)
•Entering commands in the MATLAB command window
• Using Context-Sensitive Menus to Enter
Commands:
Simulink displays a context-sensitive menu when you
click the right mouse button over a model or block library
window. The contents of the menu depend on whether a
block is selected. If a block is selected, the menu displays
commands that apply only to the selected block. If no
block is selected, themenu displays commands that apply
to a model or library as a whole.
Connecting Blocks
To connect blocks, left-click and drag the mouse from the output of
one block to the input of another block. The figure below shows the
steps involved.
Modeling In Simulink
Example 1: Modeling Equations
Converting Celsius to Fahrenheit:
To model the equation that converts Celsius temperature to
Fahrenheit
TF = 9/5(TC) + 32
First, consider the blocks needed to build the model:
•A Ramp block to input the temperature signal, from the Sources library
•A Constant block to define a constant of 32, also from the Sources
library
•A Gain block to multiply the input signal by 9/5, from the Math library
•A Sum block to add the two quantities, also from the Math library
•A Scope block to display the output, from the Sinks library
Next, gather the blocks into your model window.
Assign parameter values to the Gain and Constant blocks by opening
(double-clicking) each block and entering the appropriate value. Then,
click the Close button to apply the value and close the dialog box.
Now, connect the blocks.
The Ramp block inputs Celsius temperature. Open that block
and change the Initial output parameter to 0.
The Gain block multiplies that temperature by the constant
9/5. The Sum block adds the value 32 to the result and outputs
the Fahrenheit temperature.
Open the Scope block to view the output. Now, choose Start
from the Simulation menu to run the simulation. The
simulation runs for 10 seconds.
Example 2: Modeling A Simple Continuous System
To model the differential equation
x′ ( t ) = – 2x (t ) + u (t )
where u(t) is a square wave with an amplitude of 1 and a
frequency of 1 rad/sec. The Integrator block integrates its
input x′ to produce x. Other blocks needed in this model
include a Gain block and a Sum block. To generate a square
wave, use a Signal Generator block and select the Square
Wave form but change the default units to radians/sec.
Again, view the output using a Scope block. Gather the
blocks and define the gain.
An important concept in this model is the loop that
includes the Sum block, the Integrator block, and the
Gain block. In this equation, x is the output of the
Integrator block. It is also the input to the blocks that
compute x′, on which it is based. This relationship is
implemented using a loop.
• The Scope displays x at each time step. For a simulation
lasting 10 seconds, the output looks like this:
The equation you modeled in this example can also be
expressed as a transfer function. The model uses the
Transfer Fcn block, which accepts u as input and outputs
x. So, the block implements x/u. If you substitute sx for x′
in the above equation, you get
sx = -2x + u
Solving for x gives
x = u /(s + 2)
or,
x ⁄ u = 1 ⁄ ( s + 2)
• The Transfer Fcn block uses parameters to specify the
numerator and denominator coefficients.
In this case, the numerator is 1 and the denominator is s+2.
Specify both terms as vectors of coefficients of successively
decreasing powers of s. In this case the numerator is [1] (or just
1) and the denominator is [1 2]. The model now becomes quite
simple.
The results of this simulation are identical to those of the previous
model.
Creating Sub System
It helps reduce the number of blocks displayed in
your model window.
It allows you to keep functionally related blocks
together.
It enables you to establish a hierarchical block
diagram, where a Subsystem block is on one layer
and the blocks that make up the subsystem are on
another.
Before - After
Check with model browser in Simulink window
Label subsytem Ports
Simulation Parameters
You can set the simulation parameters for each simulation
such as run time or solver option
Simulation Parameters (Continue)
Step Solver
Size type
Setting simulation time
Setting solver
Running A Simulation
A simulation can be run
using 3 ways:
Clicking the start word on the
simulation tab
Clicking the “play” button on
the window
Pressing Ctrl+T.
When a simulation is running, the status bar displays the status
of the simulation, including the current simulation time and the
name of the current solver. You can display or hide the status
bar by selecting or clearing the Status Bar option on the
Simulink View menu.
Getting Output
Parameters You can save scope data
into workspace (you can do
this with “save to
workspace” block in “sinks”
catagory)
You can view more than
one signal in scope either on
the same axis or in the
separate axis.
Data can also be exported to
the workspace using the
scope.
Using Scope
Setting the number of axes for the scope (Figure 1)
Saving the data to workspace (Figure 2)
Further Considerations
This lecture can’t possibly look upon all the blocks.
Another way is to get “help” concerning the block.
This can be done by double clicking on the block. A
window will appear where a help button is available.
Click on that button to know what is the potential of
the block.
Ending A Simulink Session
Terminate a Simulink session by closing all
Simulink windows.
Terminate a MATLAB session by choosing
the command below from the File menu:
•Exit MATLAB
References
SIMULINK – Model-Based and System-Based Design
Matlab Documentation, The MathWorks.
www.mathworks.com
http://sts.bwk.tue.n1/7y530/readers/.%5CSimuLinkTutori
al.pdf
http://www.eng.warwick.ac.uk/staff/msl/progs/
simulinklab1.pdf
http://www.engin.umich.edu/group/ctm/working/mac/
simulink_basics/