Sunteți pe pagina 1din 45

Introduction to MATLAB Simulink

http://www.mathworks.com/help/simulink/index.html
Simulink is a graphical, drag and drop environment for building
simple and complex signal and system dynamic simulations.
It allows users to concentrate on the structure of the problem, rather
than having to worry (too much) about a programming language.
The parameters of each signal and system block is configured by the
user (right click on block)
Signals and systems are simulated over a particular time.
1/14
v
s
,

v
c
t
MATLAB Toolboxes
MATLAB has a number of add-on software modules, called toolboxes, that
perform more specialized computations.
Signal & Image Processing
Signal Processing- Image Processing Communications - System
Identification - Wavelet Filter Design
Control Design
Control System - Fuzzy Logic - Robust Control -
More than 60 toolboxes!
What Is the Signal Processing Toolbox?
The Signal Processing Toolbox is a collection of tools or functions
expressed mostly in M-files, that implement a variety of signal processing
tasks.
Command line functions for:
Analog and digital filter analysis
Digital filter implementation
FIR and IIR digital filter design
Analog filter design
Statistical signal processing and
spectral analysis
Waveform generation
Interactive tools (GUIs) for:
Filter design and analysis
Window design and analysis
Signal plotting and analysis
Spectral analysis
Filtering signals
Starting and Running Simulink
Type the following at the Matlab
command prompt
>> simulink
The Simulink library should appear
Click File-New to create a new
workspace, and drag and drop objects
from the library onto the workspace.
Selecting Simulation-Start from the pull
down menu will run the dynamic
simulation. Click on the blocks to view
the data or alter the run-time parameters
4/14
Signals and Systems in Simulink
Two main sets of libraries for building simple
simulations in Simulink:
Signals: Sources and Sinks
Systems: Continuous and Discrete
5/14
Basic Simulink Example
Copy sine wave source and scope sink
onto a new Simulink work space and
connect.
Set sine wave parameters modify to 2
rad/sec
Run the simulation:
Simulation - Start
Open the scope and leave open while you
change parameters (sin or simulation
parameters) and re-run
Many other Simulink demos
6/14
Example 1: a simple model
Build a Simulink model that solves the differential equation
Initial condition
First, sketch a simulation diagram of this mathematical model
(equation)
(3 min.)
( ) t x 2 sin 3 =
. 1 ) 0 ( = x
Simulation diagram
Input is the forcing function 3sin(2t)
Output is the solution of the differential equation x(t)
Now build
this model in Simulink
x
x
s
1
3sin(2t)
(input)
x(t)
(output)
1 ) 0 ( = x
integrator
Select an input block
Drag a Sine Wave block
from the Sources library to
the model window
Select an operator block
Drag an Integrator block
from the Continuous library
to the model window
Select an output block
Drag a Scope block from the
Sinks library to the model
window
Connect blocks with signals
Place your cursor on the
output port (>) of the Sine
Wave block
Drag from the Sine Wave
output to the Integrator
input
Drag from the Integrator
output to the Scope input
Arrows indicate the direction
of the signal flow.
Select simulation parameters
Double-click on the
Sine Wave block to
set amplitude = 3
and freq = 2.
This produces the
desired input of
3sin(2t)
Select simulation parameters
Double-click on
the Integrator
block to set initial
condition = -1.
This sets our IC
x(0) = -1.
Select simulation parameters
Double-click on the
Scope to view the
simulation results
Run the simulation
In the model
window, from the
Simulation pull-
down menu, select
Start
View the output x(t)
in the Scope
window.
Simulation results
To verify that this plot
represents the solution
to the problem, solve
the equation
analytically.
The analytical result,
matches the plot (the
simulation result)
exactly.
( ) t t x 2 cos ) (
2
3
2
1
=
Example 2
Build a Simulink model that solves the following differential
equation
2nd-order mass-spring-damper system
zero ICs
input f(t) is a step with magnitude 3
parameters: m = 0.25, c = 0.5, k = 1
) (t f kx x c x m = + +
Create the simulation diagram
On the following slides:
The simulation diagram for solving the ODE is created step by step.
After each step, elements are added to the Simulink model.
Optional exercise: first, sketch the complete diagram (5 min.)
) (t f kx x c x m = + +
(continue)
First, solve for the term with highest-order derivative
Make the left-hand side of this equation the output of a summing
block
kx x c t f x m = ) (
x m
summing
block
Drag a Sum block from the
Math library
Double-click to change the
block parameters to
rectangular and + - -
(continue)
Add a gain (multiplier) block to eliminate the coefficient and
produce the highest-derivative alone
x m
m
1
x
summing
block
Drag a Gain block from the
Math library
Double-click to change the
block parameters.
Add a title.
The gain is 4 since 1/m=4.
(continue)
Add integrators to obtain the desired output variable
x m
m
1
summing
block
s
1
s
1 x
x
x
Drag Integrator blocks from
the Continuous library
Add a scope from the Sinks library.
Connect output ports to input ports.
Label the signals by double-clicking on the leader line.
ICs on the integrators
are zero.
(continue)
Connect to the integrated signals with gain blocks
to create the terms on the right-hand side of the
EOM
x m
m
1
summing
block
s
1
s
1 x x
x
c
k
x c
kx
Drag new Gain blocks
from the Math library
Double-click on gain blocks to
set parameters
Connect from the gain block
input backwards up to the
branch point.
Re-title the gain blocks.
To flip the gain block, select it
and choose Flip Block in the
Format pull-down menu.
c=0.5
k=1.0
Complete the model
Bring all the signals and inputs to the summing
block.
Check signs on the summer.
x m
m
1
s
1
s
1 x x
c
k
x c
kx
f(t)
input
+
-
-
x
x
x
x(t)
output
Double-click on Step block to
set parameters. For a step
input of magnitude 3, set Final
value to 3
Final Simulink model
Run the simulation
Results
Underdamped response.
Overshoot of 0.5.
Final value of 3.
Is this expected?
Paper-and-pencil analysis
based on the equations of motion
Standard form
Natl freq.
Damping ratio
Static gain
) (
1
t f
k
x x
k
c
m
k
x
= + +

5 . 0
2
= = ,
e
,
k
c
n
0 . 2 = =
m
k
n
e
1
1
= =
k
K
Problem: We need to simulate the resonant circuit
and display the current waveform as we change the
frequency dynamically.
+
v(t) = 5 sin et

i
10 O 100 uF
0.01 H
Varies e
from 0 to
2000 rad/s
Observe the current. What do we expect ?
The amplitude of the current waveform will become
maximum at resonant frequency, i.e. at e = 1000 rad/s
How to model our resonant circuit ?
+
v(t) = 5 sin et

i
10 O 100 uF
0.01 H
}
+ + = idt
C
1
dt
di
L iR v
Writing KVL around the loop,
LC
i
dt
i d
L
R
dt
di
dt
dv
L
1
2
2
+ + =
Differentiate wrt time and re-arrange:
Taking Laplace transform:
LC
I
I s sI
L
R
L
sV
2
+ + =
(

+ + =
LC
1
s
L
R
s I
L
sV
2
Thus the current can be obtained from the voltage:
(
(
(

+ +
=
LC
1
s
L
R
s
) L / 1 ( s
V I
2
LC
1
s
L
R
s
) L / 1 ( s
2
+ +
V
I
Start Simulink by typing simulink at Matlab prompt
Simulink library and untitled windows appear
It is here where we
construct our model.
It is where we
obtain the blocks to
construct our model
Constructing the model using Simulink:
Drag and drop block from the Simulink library
window to the untitled window
1
s+1
Transfer Fcn
si mout
To Workspace Si ne Wave
Constructing the model using Simulink:
LC
1
s
L
R
s
) L / 1 ( s
2
+ +
6 2
10 1 s 1000 s
) 100 ( s
+ +
100s
s +1000s+1e6
2
Transfer Fcn
v
To Workspace1
i
To Workspace Si ne Wave
We need to vary the frequency and observe the current
100s
s +1000s+1e6
2
Transfer Fcn1
v
To Workspace3 w
To Workspace2
i
To Workspace
Ramp
s
1
Integrator
si n
El ementary
Math
Dot Product3
Dot Product2
1000
Constant
5
Ampl i tude
From initial problem definition, the input is 5sin(t).
You should be able to decipher why the input works, but
you do not need to create your own input subsystems of
this form.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-1
-0.5
0
0.5
1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-5
0
5
The waveform can be displayed using scope similar
to the scope in the lab
100s
s +1000s+1e6
2
Transfer Fcn
0.802
Sl i der
Gai n
Scope
s
1
Integrator
si n
El ementary
Math
Dot Product2
5
Constant1
2000
Constant
Simulink System Model - Example
Simulink - a package for modeling dynamic systems
References
Internet search engine
http://www.mathworks.com/help/simulink/index.html

S-ar putea să vă placă și