Matlab Applications

					      Application of

             Prepared by:
Prof. Dr. Almoataz Youssef Abdelaziz
What is Simulink?
• Simulink is a software package for modeling,
simulating, and analyzing dynamical systems.

• It supports linear and nonlinear systems, modeled
in continuous time, sampled time, or a hybrid of the

• Systems can also be Multi-rate, i.e., have different
parts that are sampled or updated at different rates.
• For modeling, Simulink provides a graphical user
interface (GUI) for building models as block
diagrams, using click-and-drag mouse operations.

• With this interface, we can draw the models just as
we would with pencil and paper.

• Simulink includes a comprehensive block library of
sinks, sources, linear and nonlinear components,
and connectors.
Through Simulink, we can easy put the building
We can put any
blocks of frequency analyzers to see signal in the
                 system like filters, generators,
frequency domain, and we can also send elements
integrators, transfer functions, nonlinear all these
like to MATLAB, so others to build a Simulink as
data quantizers, andwe can integrate thesystem, and
a powerful tool put scope in theand MATLAB as a
then simply we for simulation part of the system
powerfulto see how the waveform change with time.
we want tool in data analysis.
Quick start

Press on the icon seen in the circle, we will have the
following window, and it is called the Library
Example 1:
It is required to make a simulation for an adder of 3
inputs of different frequencies (1, 2 and 3 Hz), and
we want it to output the summation of them.

1. Start by creating new model. This can be done
from the main menu of MATLAB file ->

new -> model, or from Simulink file ->new ->model,
or by simply pressing the button.

We will have now the following window.
2. Now start by inserting 3 sin wave generators, this
comes from a library called Simulink > sources
>sine wave
Drag the sine wave from the Library browser and put
it into the model, do this job 3 times to have 3 sine
wave generators, and we will have the following
3. Now from the Simulink>Math operators>Sum,
drag and drop a summation node.
4. Finally drag and drop a scope in your model, you
can find it in Simulink >Sinks library, this is the
monitoring element in our simulation.
Now, we should have the following figure:
To have the properties of any block, double click this
5. Double click the summation element, you will
have the Parameters window of the summation
element, in this window change List of signs to (+++)
this means that you want 3 inputs, all summation
“no subtraction”.
6. Now click on the top sin wave and press CTRL key
and hold it, and then press on the sum node, we will
find that we connected them together, it is a simple
magic, don’t worry ☺.
7. Make this with all the other sine wave generators,
after this make this between the sum node and the
scope, you should now have the following figure:
8. Now, double click the first Sine wave generator,
you will have its parameters window, change it to be
as the follows:
9. Make the same with the other 2 generators, only
change the frequency from (2* π *1) to (2*π*2) and
(2* π *3) “the frequency in rad/sec”.

10. Now double click the scope and see its
parameter window, and then inside it press the

change the properties to be as follows:
The result of the above configurations will lead to 3
sine wave generators with frequencies 1,2,3 Hz and
a summer for them, and we will have a scope having
4 display windows and 4 input ports, now, we want
to connect the signals required to be monitored to
the scope.

11. Connect the output of the summer to the first
input of the scope and then click on the line output
from the first sine wave generator, and press CTRL
and connect the new line to the 2nd input of the
scope, make this also with the 2 other inputs, as
MODEL, all what we want to do is to press button

Now double click the scope to see the scope output,
we will see the following:
By now, it is assumed that we became familiar with
the Simulink environment, of course we can save
our work from file >save, and we can open an
existing model from file>open, and we can copy,
paste and cut from a model, these are the basic
things we want to know to begin working with
Now, we will describe in brief some things that we
did in the Example (1). We can answer the following
questions to discover them:
1- What will be the change in the summation element
if we changed (+++) by (++++)?
2- What will happen if we change the number of axis
in the scope parameter window to 5?
3- What will be the change if we checked the check
box of “limit data points to last:” in the scope
parameter window number 2?

If we put the number = 5000 and run the simulation
to see the output then change it to 3000 then 2000
and test the output, what’s the obvious observation?

What’s the relation between the output of the scope
and the SAMPLING TIME “the last parameter” of the
sine wave?
To discover it, keep one element fixed, say the (limit
data points to last 5000) and double the value of the
sampling time, what will be the effect, then put it into
half of its value.

4- Try to click on the word “Sine Wave 1”, now we
can edit the name.

5- Double click on any place in the empty parts of
the model, and write your comments there, can you
do it? Just double click in an empty region and start
to write.
The subsystem makes the model easy to trace and

The subsystem is a black box that has a lot of
Simulink components, and has inputs and Outputs.

You put these components into your model, you can
mask for better interface with the system designer.

The masked system can have parameters from the
Example 2:

1- Open the model of the last example, save it with
different name “like exp.mdl”.

2- Select the 3 sine wave generator by the mouse or
by clicking on them while keeping SHIFT key

3- Right click and choose “create subsystem”, you
should have the following figure:
4- Change the name of subsystem to “3_sines”.

5- From the toolbar, press on the button.

6- Now, you will see the model browser, you can
switch between the main system and the 3_sines
subsystem, I think if what is inside the subsystem is
a lot of things, this method will be a nice help for us.

7- Now switch to 3_sines subsystem and change the
name of the output ports to f1, f2, f3. You will reach
the following figure:
8- Go to the parameters window of the sine wave
generators and make the frequencies 2*pi*f1, 2*pi*f2
and 2*pi*f3 “note f1, f2, f3 will be specified soon”.

9- Go to the main model, and right click the
subsystem and choose Edit mask. You will have the
following beautiful window:
Now click on parameters tab.
10- Now change the input data to be as follows:
We think what happens now should be clarified, all
what we did is that we decided to input the three
frequencies of our small subsystem by an Edit box,
this is similar to send the arguments of a function in
any programming language, if you double click now
on the subsystem, you will have the following dialog
We think things now became clear, we have now 3
Edit boxes, the input for them are sent to f1, f2, f3
respectively and the prompt of them are shown as
determined by the mask designer.
Now we want to write short note on the block and we
want to call it something, this is done by right click
on the subsystem->edit mask-> documentation tab,
then write the name in the “mask type” part, and the
description which will appear when double clicking
the block in the Mask description part, and the help
that you want the user to see in the Mask help part
as shown in the following 2 figures:
Press on the help button also to find the great help
written by us now☺.
These are the most important things in masking the
subsystems, there is a lot of details that we can easy
follow, and for more details, we can see the help.
Now, I think we have good overview of the Simulink
in general, and we can work with its environment, we
can fly in the sky of subsystems, swim in the sea of
masks, and I am sure that we are now interested to
know how the kernel of Simulink works, so in the
next chapter, we will discuss some basic principles
in Simulink, by finishing these concepts, we can
now mask to build strong systems.

Shared By: