Professional Documents
Culture Documents
with Applications
Module IV:
SIMULINK and Neuro-Fuzzy Toolboxes
SIMULINK
Session 2:
Getting Started with Simulink
Session Outlines
Subsytems
Masking
Discrete System
Subsystems
What is Subsystems?
We may make a very complex system resulting in a very
complex model.
As subprogram (subroutine or function) of other
programming language, Simulink provides an analogous
capability called subsystems.
Using subsystems, we can make the models easier to
develop, to understand and to maintain.
Subsystems
Method of Creating Subsystems
Subsystems
Encapsulating Subsystems
Suppose we want to make our primitive model of massspring-damper as a subsystem.
Subsystems
Encapsulating Subsystems
To encapsulate a portion of a Simulink model, select all
the blocks and signal line to be included in the
subsystem using a bounding box using our mouse.
bounding box
Subsystems
Encapsulating Subsystems
Choose Create Subsystem under Edit menu.
New subsystem
Subsystems
Encapsulating Subsystems
To view or edit a subsystem, double-click the block. A
new window will appear.
Subsystems
Subsystems Blocks
If, when building a model, we know that we will need a
subsystem, it will more convenient to build a subsystem
in a subsystem directly.
Drag a Subsystem Block from Ports & Subsystem
Library to the model window.
Subsystems
Subsystems Blocks
Double click the subsystem to open subsystem window.
Subsystems
Subsystems Blocks
Use Inport Blocks for all signals entering subsystem and
Outport Blocks for all signals leaving the subsystem.
(Both blocks are from Port & Subsytem Library)
Masking
Concept
A mask is a custom user interface for a subsystem
that hides the subsystems contents, making it appear
to the user as an atomic block with its own icon and
parameter dialog box.
Masking permits us to treat a subsystem as if it was a
simple block.
Masking
Concept
Masking
Open a new model workspace, and drag the subsystem
of the primitive model into it.
Masking
Select the subsystem model and then choose Mask
under Edit menu from the new model window menu bar.
Masking
Mask Editor dialog box consists of four tabbed pages
Icon
Initialization
Parameters
Documentation
Masking
Mask Editor Documentation Page
The Documentation pane enables you to define or
modify the type, description, and help text for a masked
block.
Masking
Mask Editor Parameters Page
The page is used to set parameters of block in
subsystem underlying the masked block.
For our mass-spring-damper, we have the following
parameters:
Mass, symbol: m, editable by user
Damper, c, editable
Spring, k, editable
add icon
delete icon
Masking
Mask Editor Parameters Page
Masking
Mask Initiation Page
The Initialization pane allows you to enter MATLAB
commands that initialize the masked subsystem.
Simulink executes the initialization commands when it
Loads the model
Starts the simulation or updates the block diagram
Rotates the masked block
Redraws the blocks icon (if the masks icon creation
code depends on variables defined in the
initialization code)
Masking
Mask Initiation Page
For example, if we want
our masked system has
the following value:
m=1;
c=2;
k=10
Type that parameters in
initialization commands.
For our example, leave this page empty since we want to
make the parameters are editable through block
parameters.
Department of Mechatronics Engineering
Masking
Mask Editor Icon Page
The Mask Editors Icon pane enables you to create icons that
can contain descriptive text, state equations, images, and
graphics.
Masking
Mask Editor Icon Page
Drawing commands
This field allows us to enter commands that draw the
blocks icon. Simulink provides a set of commands that
can display text, one or more plots, or show a transfer
function. We may use the following commands: text,
plot, displ, dpoly, etc as shown in the example
command. We must use these commands to draw your
icon.
Masking
Mask Editor Icon Page
Icon options
These controls allow you to specify the attributes of the
block icon.
Frame
Rotation
Department of Mechatronics Engineering
Transparency
Unit
Masking
Mask Editor Icon Page
Let draw the following figure for our masked subsystem.
Set the following icon
option:
Frame: Visible
Transparency: Opaque
Rotation: fixed
Unit: Normalized
Masking
Mask Editor Icon Page
Type the following commands into commands field
plot([0.1 0.1],[0.2 0.8])
plot([0.4 0.7 0.7 0.4 0.4],[0.2 0.2 0.8 0.8 0.2])
plot([0.1 0.2],[0.4 0.4])
plot([0.3 0.2 0.2 0.3],[0.3 0.3 0.5 0.5])
plot([.1 .2 .2 .3 .3 .4],[.7 .7 .8 .6 .7 .7])
plot([0.3 0.4],[0.4 0.4])
plot([0.7 0.9],[0.5 0.5])
text(.5,.5,'m')
text(.25,.35,'c')
text(.25,.85,'k')
text(.8,.6,'f')
Department of Mechatronics Engineering
Masking
Mask Editor Icon Page
We will get the following masked subsystem:
Masking
Mask Editor Icon Page
We may also displaying a tif image on a block icon using
the following drawing command:
image(imread(file_name.tif))
Masking
Close the mask editor, now, our subsystem look like
blocks of Simulink library. Double-click to see the effect
of the masking.
Masking
Mask Editor Documentation Page
Masking
Mask Editor Documentation Page
Discrete System
Concept
Discrete system is dynamical system that can be
described using difference equation.
For example, lets consider the following system:
x1 (k) x1 (k 1) 0.1x 2 (k 1)
x 2 (k) 0.05 sin x1 (k 1) 0.094x 2 (k 1) u(k)
The process is assumed to have a sample time of 0.1
sec.
Discrete System
Concept
Simulink has the ability to
simulate discrete system,
including system whose
components operate at
different rates (multi rate)
and system that mix discrete
and continuous components
(hybrid system).
Discrete System
Lets build a model and simulate the following system:
x1 (k) x1 (k 1) 0.1x 2 (k 1)
x 2 (k) 0.05 sin x1 (k 1) 0.094x 2 (k 1) u(k)
The process is assumed to have a sample time of 0.1
sec.
We may construct a Simulink model by using
primitive blocks
transfer function block
state variable model.
Department of Mechatronics Engineering
Discrete System
Primitive Blocks
We can build a block diagram as the following figure:
(User-defined functions)
(Math)
(Math)
0.05sin[x1(k-1)]
x1(k)
u(k) (Sources)
++
x2(k) 1
0.1
z
0.094
++
x2(k-1)
1
z
x1(k-1)
(Discrete)
Discrete System
Primitive Blocks
Therefore, we have the following Simulink model.
Discrete System
Primitive Blocks
Double click the f(u) block, then modify the desired
function and sampling time. Click OK to close the
window.
0.05*sin(u)
0.1
Discrete System
Primitive Blocks
The Simulink model become as follows:
Discrete System
Primitive Blocks
Double click the unit delay
blocks, then set sample time
to 0.1.
Discrete System
Primitive Blocks
Before we run the Simulink model, we should carefully
determine the step size of the simulation parameter
especially when we use fix step.
Discrete System
Transfer Function
Lets build a model and simulate the following system:
x1 (k) x1 (k 1) 0.1x 2 (k 1)
x 2 (k) 0.05 sin x1 (k 1) 0.094x 2 (k 1) u(k)
In z-domain,
0.1
X1 ( z )
X 2 (z)
z 1
z
0.05 sin X1 (z) U(z)
X 2 (z)
z 0.094
Department of Mechatronics Engineering
Discrete System
Transfer Function
Then we can construct the following block diagram:
(Discrete)
(Math)
U(z)
+(Sources)
X2(z)
z
z 0.094
0.1z
z 1
X1(z)
F(X1)
(Sinks)
(User-defined functions)
Discrete System
Transfer Function
Therefore, we have the following Simulink model.
Discrete System
Transfer Function
Double click the f(u) block, then modify the desired
function and sampling time. Click OK to close the
window.
0.05*sin(u)
0.1
Discrete System
Transfer Function
The Simulink model become as follows:
Discrete System
Transfer Function
Double click the discrete
transfer functions, then
modify the transfer function
parameters and sample time.
[1 0]
[1 -0.094]
0.1
[0.1 0]
[1 1]
0.1
Department of Mechatronics Engineering
Discrete System
Transfer Function
The Simulink model become as follows:
Discrete System
Transfer Function
Before we run the Simulink model, we should carefully
determine the step size of the simulation parameter
especially when we use fix step.
In general, we can select the step size at integer of
multiples of the shortest systems sample time.
In our example, the sample time is 0.1 so we can
select 0.1 as step size. Then we can simulate the
model.
Discrete System
Multirate Discrete Time
Simulink also has capability to handel discrete systems
with involve subsystems that operate at different.
The Simulink sample-time color capability provides help
in keeping track of sample tiems.
To activates the feature, select Format:Port/Signals
Display and then check Sample time colors.
Discrete System
Hybrid System
Mixed continuous and discrete systems are composed
of both sampled and continuous blocks. Such systems
can be simulated using any of the integration
methods, although certain methods are more efficient
and accurate than others.
For most mixed continuous and discrete systems, the
Runge-Kutta variable-step methods, ode23 and ode45,
are superior to the other methods in terms of efficiency
and accuracy.
Department of Mechatronics Engineering
End of Session 2
Further Reading
Using Simulink