Beruflich Dokumente
Kultur Dokumente
Page|i ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Audience:
The motive of this tutorial is to give hints, highlights and some insight about Simulink to 4 th year
Electrical engineering students and hence will help them to do their projects (course project, final
project, mini projects ). However, any student in the field of science, Engineering and computing
can use this note to advance his/her knowledge of MATLAB.
Prerequisite:
This tutorial will start at very basic level that is intended to audiences with no prior knowledge
about it. However, to study MATLAB including the code part (command part) fundamental
understanding of concepts like variables, constants, expression, statements, etc. is needed. If you
have done programming in any other high-level programming language like C, C++ or Java, then
it will be very much beneficial and learning MATLAB will be like a fun for you.
Page|ii ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Page|iii ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
1.Introduction to Simulink:
Simulink is an environment for simulation and model-based design for dynamic and
embedded systems. It provides an interactive graphical environment and a customizable set
of block libraries that let you design, simulate, implement, and test a variety of time-varying
systems, including communications, controls, signal processing, video processing, and image
processing. Simulink offers:
A quick way of develop your model in contrast to text based-programming
language such as e.g., C.
Simulink has integrated solvers. In text based-programming language
such as e.g., C you need to write your own solver.
It allows you to incorporate MATLAB algorithms into models as well as export the simulation
results into MATLAB for further analysis.
Simulink supports:
system-level design
simulation
automatic code generation, i.e. we can generate a code with .m extension file
from the graphical model.
testing and verification of embedded systems
Page|1 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
2.Starting Simulink:
start Simulink from the MATLAB IDE:
Open MATLAB and select the Simulink icon in the Toolbar:
Page|2 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Page|3 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
The Simulink Library Browser is the library where you find all the blocks you may use in
Simulink. Simulink software includes an extensive library of functions commonly used in
modeling a system. There are two major classes of items in Simulink: blocks and lines. Blocks
are used to generate, modify, combine, output, and display signals. Lines are used to transfer
signals from one block to another.
Blocks
There are several general classes of blocks within the Simulink library:
Sources: used to generate various signals
Sinks: used to output or display signals
Page|4 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Page|5 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Page|6 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Page|7 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
You may now drag the blocks you want to use from the Simulink Library Browser to the
model surface (or right-click on a block and select Add to).
Example: In this example we place (drag and drop) two blocks, a Sine Wave and a Scope, on the
model surface:
Page|8 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
inputs
output
When holding the mouse over an input or an output the mouse changes to the following
symbol.
Use the mouse, while holding the left button down, to drag wires from the input to the
output.
Page|9 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Page|10 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
All standard blocks in Simulink have detailed Help. Click the Help button in the Block
Parameter window for the specific block in order to get detailed help for that block.
The Help Window then appears with detailed information about the selected block:
Page|11 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
2.5. Configuration:
There are lots of parameters you may want to configure regarding your simulation. Select
Configuration Parameters in the Simulation menu.
Select, Simulation menu > model configuration parameter
Page|12 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Page|13 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Step 2: Configuration
Double-click on the Integrator block. The Parameter window for the Integrator block
appears:
Page|14 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Select Initial condition source=external. The Integrator block now looks like this:
Double-click on the Constant block. The Parameter window for the Constant block appears:
Page|15 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
In the Constant value field, we type in the initial value for the integrator, e.g., type the value
1.
Step 3: Wiring
Use the mouse to wire the inputs and outputs of the different blocks.
inputs
output
Wire all the blocks together and you will get the following diagram:
Page|16 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Step 4: Simulation
Start the simulation by clicking the Start Simulation icon in the Toolbar:
Page|17 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Page|18 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Page|19 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
As you see, we can use standard MATLAB syntax to create a vector. If you want to see the
signal dimensions, select Signal Dimensions and Wide Non-Scalar Lines.
Select Display>signals & ports> Signal Dimensions, Wide Non-Scalar Lines
The block diagram should now look like this:
The thick lines indicate vectors, while the number (8) is the size of the vector.
Lets change the Saturation block:
Run the simulation and see the results in the Scope block.
Page|20 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Page|21 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
By double clicking on the Transfer Function Set the numerator & denominator coefficient:
Page|22 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
3. Useful Features:
You should know about these features in Simulink in order to take full advantage of
Simulink.
3.1. Comments/Labels:
Double-click on your surface in order to write Labels or Comments in your model block
diagram.
In order to flip the input and outputs right-click on the block and select Flip Block.
Page|23 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Page|24 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Page|25 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
N.B: You may mix continuous blocks and discrete blocks in the same system, so-called Hybrid
systems. So, the above example is hybrid system.
Page|26 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
[ Figure: Wikipedia]
The goal is to view the position x(t) of the mass m with respect to time t. You can calculate
the position by integrating the velocity of the mass. You can calculate the velocity by
integrating the acceleration of the mass. If you know the force and mass, you can calculate
this acceleration by using Newton's Second Law of Motion, given by the following equation:
Force = Mass Acceleration
Therefore,
Acceleration = Force / Mass
Substituting terms from the differential equation above yields the following equation:
X = 1/m (F cx - kx)
You will construct a simulation diagram that iterates the following steps over a period of
time.
Create the block diagram for the mass-spring-damper model above.
Instead of hard-coding the model parameters in the blocks you should refer to them as variables
set in an m-file.
These variables should be configured:
x_init
dxdt_init
m=
c=
k
t_step_F
F_O
F_1
Page|27 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Page|28 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Note: the keyword simset in the above script is used to configure parameters in the block and
the keyword sim is used to simulate the Simulink model. But to see the output via the scope
you have to double click the scope in the Simulink model.
Page|29 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Page|30 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
6. Subsystems:
Subsystems allow you to create a hierarchical model comprising many layers. A subsystem is a
set of blocks that you replace with a single Subsystem block. As your model increases in size and
complexity, you can simplify it by grouping blocks into subsystems. Using subsystems:
Establishes a hierarchical block diagram, where a Subsystem block is on one
layer and the blocks that make up the subsystem are on another
Keeps functionally related blocks together
Helps reduce the number of blocks displayed in your model window
When you make a copy of a subsystem, that copy is independent of the source subsystem. To
reuse the contents of a subsystem across a model or across models, use either model referencing
or a library.
Example: let you have the Simulink model given in the below.
Now, if you went to create a subsystem for the blocks saturation, Zero-Order Hold & Zero-Order
Hold1, the first thing you have to do is Select the part of your system from which you want to
create a subsystem, right-click and then select Create Subsystem.
Page|31 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
So, model with the new created subsystem will be shown in below:
Page|32 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Practice Problems:
1.Use Simulink to construct the block diagram shown below.
Enter the following parameters:
For the step block, step time=1, initial time=0, final value=0, sample time=0
For the transfer function block, numerator coefficient=[3.78], denominator coefficient=[1 16.9 0]
Gain=1
Page|33 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
3.design the following single phase full wave controlled rectifier and simulate the output voltage
at the load (inductor)?
Parameters to be entered:
For the Ac voltage: amplitude=50, frequency=50, sample time=0 and phase=0
For all the thyristors: resistance (Ron)=0.00001, Rs=500, Cs=250e-9 and the rest zero
For pulse generator and pulse generator1: amplitude=1, period=0.02, Pw=0.015, Pd=0.005
For pulse generator2 and pulse generator3: amplitude=1, period=0.02, Pw=0.005, Pd=0.015
Page|34 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
Page|35 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
4.enter the command sldemo_auto_carelec in the command window of the MATLAB, after
that built-in Simulink model will pop-up as it can be seen below. Analyze and figure-out the
model in addition observe the output via the scope.
7. Recommendation!
This tutorial is just an introductory part which will give you some hint, means and insight about
Simulink. However, if you went to master the platform and hence will help you to do your
project, you need to refer additional concepts about it. This tutorial is a gate like the door so the
door is open learn more & faster, explore more.
Page|36 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1
Simulink Tutorial ADU, 2010 E.C
References:
[1]. Simulink., Internet: https://www.mathworks.com/help/simulink/index.html?s_cid=doc_ftr
accessed: Nov 27, 2017
[2]. MATLAB, internet: http://home.hit.no/~hansha/ accessed: Nov 27, 2017
[3].Simulink tutorial , internet:
http://home.hit.no/~hansha/documents/lab/Lab%20Work/MATLAB/MATLAB%20Course%20-
%20Part%203.pdf accessed: Nov 28, 2017
[4]. Simulink, internet: https://www.tutorialspoint.com/matlab/matlab_simulink.htm accessed:
Nov 28, 2017
[5]. MATLAB internet: [Video], http://www.mathtutordvd.com accessed: Nov 26, 2017
Page|37 ______________________________________________________________________________
Compiled by Alem T. Bsc
Target Audiences- Electrical Eng. 4th year students
Ver. 1