Professional Documents
Culture Documents
SIMULINK with
Applications
Module IV:
SIMULINK and Neuro-Fuzzy Toolboxes
SIMULINK
Session 1:
Getting Started with Simulink
Outlines
What is SIMULINK
Getting Started with SIMULINK
Continuous-time System
Subsystems
Masking
Discrete-time System
Session Outlines
What is SIMULINK?
Getting Started with SIMULINK
Modeling of Continuous Time
What is SIMULINK?
What is SIMULINK?
Simulink can be launched by using one of the
following ways from MATLAB.
By clicking the Simulink icon on the MATLAB
toolbar
Click the Simulink icon to start simulink
What is SIMULINK?
When Simulink opens you will see the box called
the SIMULINK library browser will open as shown
in the figure.
New window icon
Simulink library
icon
What is SIMULINK?
Two Steps with Simulink
Creating a graphical model
SIMULINK Model Editor
SIMULINK Model Library
What is SIMULINK?
Elements of a Simulink Model
Sources
System Block
Diagram
Sinks
What is SIMULINK?
Sources
The source library contains of data/signals that
one would use in a dynamic system simulation in
Simulink.
The sources may:
constant input
sinusoidal wave
input
step input
a repeating
sequency
ramp input
etc
Department of Mechatronics Engineering
What is SIMULINK?
Sources
You may also open the source library on a
separate window by right-click the source icon
then select open.
What is SIMULINK?
Sinks
The sinks are block were signals are terminated
or ultimately used.
The signals could be
displayed
or even stored in a
file/workspace.
What is SIMULINK?
Sources
You may also open the sinks library on a
separate window by right-click the source icon
then select open.
What is SIMULINK?
Simulink Model Library
Simulink allow you to represent a model as
continuous as well as discrete systems by using
transfer function, integration blocks, etc.
What is SIMULINK?
Simulink Model Library
Simulink also provides nonlinear (discontinuous)
blocks and look-up table blocks for building a
model.
What is SIMULINK?
Simulink Model Library
Other useful
blocks are Math
block.
Getting Started
Lets start by building a simulink model that
solves the following differential equation
x ( t ) 3 sin( 2 t )
where
x (0) 1
Getting Started
Building a Model
Sources
System Block
Diagram
Sinks
Initial condition:
x(0)=-1
Department of Mechatronics Engineering
Getting Started
Building a Model
If necessary, open the Simulink block library.
Simulink can be launched by using one of the
following ways from MATLAB.
By clicking the Simulink icon on the MATLAB
toolbar
Click the Simulink icon to start simulink
Getting Started
Building a Model
When Simulink opens you will see the box called
the SIMULINK library browser will open as shown
in the figure.
New window icon
Simulink library
icon
Getting Started
Building a Model
To build the model, you first need a space to
create model.
An empty window
for building the
model.
Click New window
icon to create a
new space
Department of Mechatronics Engineering
Getting Started
Building a Model
Next, select the Simulink icon to expand the list
of avalaible elements which can be used to create
a system model
Getting Started
Building a Model
Each folder contains elements which may be used
to create a system model.
Getting Started
Building a Model
Lets refer back the sketched model.
Input:
3sin(2t)
1
s
Output:
x(t)
Initial condition:
x(0)=-1
To construct this model, we require three
elements
A Sine Wave Block
An Integrator Block
A Scope Block.
Department of Mechatronics Engineering
Getting Started
Building a Model
Getting Started
Building a Model
Getting Started
Building a Model
Getting Started
Building a Model
The blocks can be connected by dragging a line
from the output of one block to the input of
another block.
Getting Started
Building a Model
The resulting model is as follows
Getting Started
Building a Model
Lets refer back the sketched model.
Input:
3sin(2t)
1
s
Output:
x(t)
Initial condition:
x(0)=-1
To construct this model, we require three
elements
A Sine Wave Block
amplitude 1 and frequency
An Integrator Block
initialof condition
-1
Department
Mechatronics Engineering
Getting Started
Building a Model
Most blocks have different parameters that are
associated with them. To access parameters,
simply double-click on the block of interest. This
will bring up a dialog box which allows the
parameters to be changed.
Getting Started
Building a Model
Lets modify the sine wave parameters.
Getting Started
Building a Model
Next, lets modify the integrator block.
Double-click on the
integrator block and
then set the initial
condition equal to -1
Getting Started
Building a Model
Next, lets modify the integrator block.
Double-click on the
scope block.
This block does not
have any parameters
which need setting, but
instead displays the
scope display screen.
Department of Mechatronics Engineering
Getting Started
Saving a Model
Now the model has been created and defined.
We may save this model before we run the
model.
To save the created model, click Save as under
File menu, then enter the name of the model.
Click OK.
Getting Started
Running a Model
Now the model has been created and defined,
the model is ready to run.
To start simulation,
pull down menu the
simulation menu and
select start.
View the output of the
simulation on the
scope window.
Department of Mechatronics Engineering
Getting Started
Running a Model
x ( t ) 3 sin( 2 t )
where
x (0) 1
Getting Started
Model Modification
We can modify the simulink block. For example,
we want to display both input and output in a
scope. To do so, drag mux block to the model
workspace.
Getting Started
Model Modification
Then, connect the mux input to the both sine
and integrator block outputs.
Getting Started
Running a Model
Now the model has been modified, the model is
ready to run.
To start simulation,
pull down menu the
simulation menu and
select start.
View the output of the
simulation on the
scope window.
Department of Mechatronics Engineering
Getting Started
Running a Model
x ( t ) 3 sin( 2 t )
where
x (0) 1
Getting Started
Configuring the Simulation
When we choose Simulation:Start from the
model window menu bar, Simulink solves the
model numerically using one of its solver
methods.
Before we run a simulation we may set various
parameters such as starting and ending time,
simulation step size, a number of tolerance and
solver method.
Getting Started
Configuring the Simulation
To set simulation parameters, choose Simulation
Parameters under Simulation menu.
Simulation
parameters dialog
box opens.
Department of Mechatronics Engineering
Four tabbed
pages
Getting Started
Configuring the Simulation
Solver page consists of three section; simulation
time, solver option and output option.
Change the following:
start 0
end 20
fixed step solver
Ode4 (Runge-Kutta)
Fixed step size 0.01
Getting Started
Configuring the Simulation
The Workspace I/O page permits us to acquire
simulation input from the MATLAB workspace
and send output directly to the MATLAB
workspace.
Enter the following:
Time: t
Output: y
Limit data point:
2000
Click OK to close the box.
Department of Mechatronics Engineering
Getting Started
Configuring the Simulation
In MATLAB 7, to set simulation parameters,
choose Configuration Parameters under
Simulation menu.
Getting Started
Configuring the Simulation
Solver page consists of three section; simulation
time, solver option and output option.
Change the following:
start 0
end 20
fixed step solver
Ode4 (Runge-Kutta)
Fixed step size 0.01
Getting Started
Configuring the Simulation
The Data Export/Import permits us to acquire
simulation input from the MATLAB workspace
and send output directly to the MATLAB
workspace.
Enter the following:
Time: t
Output: y
Limit data point:
2000
Check
State
Click
OK to
close the box.
Department of Mechatronics Engineering
Getting Started
Configuring the Simulation
Getting Started
Running a Model
Now the model has been modified, the model is
ready to run.
To start simulation,
pull down menu the
simulation menu and
select start.
View the output of the
simulation on the
scope window.
Department of Mechatronics Engineering
Getting Started
Running a Model
Now the model has been modified, the model is
ready to run.
To start simulation in
MATLAB 7, pull down
menu the simulation
menu and select start.
View the output of the
simulation on the
scope window.
Department of Mechatronics Engineering
Getting Started
Running a Model
Getting Started
Simulink Help System
Simulink includes an extensive help system in
the form of on-line Users Guide in HTML format
and an integrated browser.
Getting Started
Simulink Help System
For example, we want to access the help system
for integrator block.
Double-click on the
integrator block and
then click help button.
Getting Started
Simulink Help System
Continuous System
Concept
Continuous system is dynamical system that can
be described using differential equation.
Lets consider a mass-spring-damper system as
our example.
Motion
x(t)
equation
f ( t ) mx ( t ) cx ( t ) kx ( t ) f ( t )
c
Continuous System
Primitive Blocks
The motion equation can rewrite as follows
1
mx ( t ) f ( t ) cx ( t ) kx ( t )
m
f (t)
1/ m
+
-
x ( t )
x ( t )
c
k
Department of Mechatronics Engineering
x(t)
Continuous System
Primitive Blocks
ADD
(Math)
f (t)
1/ m
+
-
Step
(Source
)
x ( t )
x ( t )
x(t)
Scope
(Sinks)
c
Gain
(Sinks)
Integrator
(Math)
Continuous System
Primitive Blocks
To build the model, you first need a space to
create model.
An empty window
for building the
model.
Click New window
icon to create a
new space
Department of Mechatronics Engineering
Continuous System
Primitive Blocks
Locate the Step Block under the source folder and
click, drag and drop it in the model workspace
window to create input block.
Continuous System
Primitive Blocks
Locate the Sum Block in the Math Operation
library and Click, Drag and Drop it into your new
workspace.
Continuous System
Primitive Blocks
Locate the Gain Block in the Math Operation
library and Click, Drag and Drop it into your new
workspace. You need to do this three times or you
may use Copy and Paste for making three Gain
Blocks.
Continuous System
Primitive Blocks
Double click for each Gain Block and modify the
gain parameters as 1/m, c and k repectively.
Continuous System
Primitive Blocks
If necessary, we can resize the block to improve
the appearance of a model. For example
parameter 1/m of the gain block doesnt fit on the
block icon, the display value is K-.
Continuous System
Primitive Blocks
The second and third gain blocks may be flipped
to make an easier connection. Click the
respective gain block, then select Flip Blocks
under Format Menu.
Continuous System
Primitive Blocks
Next, insert two integrator and scope blocks by
drag and drop them into the model workspace.
Continuous System
Primitive Blocks
Finally, make connection between block correctly
to finish the model building.
Continuous System
Transfer Function Blocks
Taking the Laplace Transform, the motion
equation can rewrite as follows
ms
cs k X s F s
F s
X s
1
F s ms 2 cs k
1
2
ms cs k
X s
Continuous System
Transfer Function Blocks
Locate the Transfer Function in the Continuous
library and Click, Drag and Drop it into the
workspace.
Continuous System
Transfer Function Blocks
Add one Scope Block to the model workspace
then connect it to the Transfer Function Block.
Connect also the Step Block output to the
Transfer Function Block input.
Continuous System
State Space Block
The motion equation can also be rewritten in the
form of state space as follows
x Ax Bu
y Cx Du
where
k / m c / m
C 1 0
Department of Mechatronics Engineering
0
B
1 / m
D 0
Continuous System
Transfer Function Blocks
Locate the State Space Block in the Continuous
library and Click, Drag and Drop it into the
workspace.
Continuous System
Transfer Function Blocks
Add one Scope Block to the model workspace
then connect it to the State Space Block. Connect
also the Step Block output to the Transfer
Function Block input.
Continuous System
Parameters Definition
Before we run the model, we have to define the
model parameters since we just enter constant
variable.
In the MATLAB prompt, write the following
>>
>>
>>
>>
>>
m=1;c=2;k=10;
A=[0 1;-k/m -c/m];
B=[0;1/m];
C=[1 0];
D=[0];
Continuous System
Running a Model
Now we have simulation model, and we are ready
to simulate it. You may change the simulation
parameters if necessary.
End of Session 1
Further Reading
Using Simulink
End of Session 1
Further Reading
Using Simulink