Professional Documents
Culture Documents
SIMULINK
Basics
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
Simulink Basics
Content
Whats SIMULINK?
SIMULINKLibraries Sources, Sinks und Math
Simulation parameters
Algorithms for numerical integration
SIMULINKLibraries Signals&Systems, Subsystems
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
SIMULINK Basics
Whats Simulink?
Graphical modelling of dynamic systems by signal flow
graphs
Addition to MATLAB (Toolbox)
SimulinkAdditions: Blocksets (SimPower-Systems,
SimMechanics)
Sine Wave
Clock
Product1
80
Gain
Product3
eu
Math
Function
Product2
Mux
gedaempfte
Sinusschwingung
Gain1
Constant
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
SIMULINK Basics
Starting SIMULINK
Blocks are basic elements
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
SIMULINK Basics
SIMULINK block libraries Sources and Sinks
Block library Sources:
Generation of signals
Import data from MATLAB
workspace
Import of data from files
untitled.mat
Step
From File
1
In1
Constant
simin
Ramp
Repeating
Pulse
Generator Sequence
From
Workspace
untitled.mat
To File
Scope XY Graph
simout
1
Out1
To Workspace
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
SIMULINK Basics
Example for Sources and Sinks
Signal 1
Signal 2
1
s
Integrator
Scope
Signal Builder
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
SIMULINK Basics
SIMULINK block library Math Opertions
Block library Math:
Arithmetic, logical and relational operators
Mathematical and trigonometric functions
etc.
1
eu
Product
Math
Function
Sum
Gain
AND
Logical
Operator
Slider
Gain
<=
sin
Dot Product
Trigonometric
Function
K*u
Relational
Operator
Matrix
Gain
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
SIMULINK Basics
Examples for Math Operations
Sine Wave
Clock
Product1
80
Gain
Product3
eu
Math
Function
Product2
Mux
gedaempfte
Sinusschwingung
Gain1
Constant
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
SIMULINK Basics
Simulation: parameters and solvers
Configuration
Parameters
dialog box
Solver pane:
Specify start and stop time of simulation
Solvers for numerical integration
Output options
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
SIMULINK Basics
Numerical integration of ODE
Inhomogeneous linear ordinary differential equation:
u(t)
DGL
y(t)
y(t)
= f (u(t), y(t))
tn+1
Z
Integration:
yn+1 = yn +
f (u(t), y(t))dt
tn
Numerous methods:
Euler method
Heuns method
Other RungeKuttamethods
AdamsBashforth methods
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
SIMULINK Basics
Numerical integration of ODE
Euler method (explicit)
y
y1
dy
y(t1)
y0
hy0
y(t)
y0
h
t0
t1
y1 = y0 + h y0
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
10
SIMULINK Basics
Numerical integration of ODE
RungeKutta method
y
P3(t2) = y2
y1
y1
y0
P3(t)
y0
h
t0
t1
t2
2h
y2 = y0 +
[y0 + 4y1 + f (u2, y2P )]
6
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
11
SIMULINK Basics
Numerical integration of ODE
AdamsBashforth method
y
yn
P2(tn+1)
yn-1
P2(t)
yn-2
h
tn-2
tn-1
tn
tn+1
h
yn+1 = yn +
[23yn 16yn1 + 5yn2]
12
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
12
SIMULINK Basics
Solver: integration algorithms in MATLAB
Variablestep solver:
use variable step size
allow error control & detection of zero crossings
for continuous-time, non-stiff systems:
ode45 (first try), ode23, ode113
for continuous-time, stiff systems:
ode15s, ode23s, ode23t,ode23tb
for discrete-time systems:
discrete (Variablestep)
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
13
SIMULINK Basics
Solver: integration algorithms in MATLAB
Fixedstep solver:
use fixed step size
no error control
no detection of zero crossings
for continuous-time systems:
ode5, ode4, ode3, ode2, ode1
for discrete-time systems:
discrete (Fixedstep)
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
17
SIMULINK Basics
Simulation: parameters and solver methods
Configuration
Parameters
dialog box
18
SIMULINK Basics
Simulation: parameters and solver methods
Configuration
Parameters
dialog box
Diagnostics pane:
Control of warning and error messages
Set simulation options
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
19
SIMULINK Basics
Simulation
Start and stop of simulation
from SIMULINK window
from MATLAB Command Window
set_param(sys, SimulationCommand, cmd)
get_param(sys, SimulationStatus)
[t,x,y] = sim(model, timespan, options, ut)
options = simset(property, value, ...)
newopts = simset(oldopts, property, value, ...)
struct = simget(model)
Example:
[t,x,y] = sim(m1,[],simset(simget(m1),Solver,ode23,MaxStep,0.01))
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
20
SIMULINK Basics
Error handling
Simulation
Diagnostics
Viewer
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
23
SIMULINK Basics
SIMULINK block library Signal Routing
Block library Signal Routing:
Date saving
A
Data Store
Memory
Data Store
Read
Data Store
Write
Mux
Demux
Bus
Selector
Demux
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
Selector
Hit
Crossing
[1]
From
IC
[A]
Goto
24
SIMULINK Basics
Subsystems
Subsystems:
Structural order of complex models
Combining blocks of similar function
hierarchic structuring
Creation by
1. menue item Edit/Create Subsystem
2. block library Subsystems
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
25
SIMULINK Basics
SIMULINK block library Subsystems
Block library Subsystems:
In1
Out1
Subsystem
In1
Out1
In1
Atomic Subsystem
Triggered
Subsystem
In1
Out1
FunctionCall
Subsystem
In1
Out1
Out1
If Action
Subsystem
In1
function()
In1
Action
Out1
if(u1 > 0)
While Iterator
Subsystem
u1
else
If
Enabled
Subsystem
etc.
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
26
SIMULINK Basics
Conditionally executed subsystems / Masking
Conditionally Executed Subsystems
Execution controlled by control signal
comprise Enable or Trigger
Masking of subsystems
building a new block from a subsystem
easier parametrization of complex subsystems
Setting up of user defined libraries
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
27
SIMULINK Basics
Masking of subsystems
Example bspmask.mdl
x
m
Steigung
Matlab/Simulink
Dipl.-Ing. U. Wohlfarth
yAchsenabschnitt
y=mx+b
28