Introduction To Matlab/Simulink Objectives
Introduction To Matlab/Simulink Objectives
Experiment 2: Simulation
Introduction to Matlab/Simulink
Modified 01-12-05
Introduction to Matlab/Simulink
Objectives: We have two main objectives in this experiment
Introduce Matlab/Simulink
Simulate three electrical circuits
Information on Matlab/Simulink:
1. General Information
SIMULINK is a toolbox extension of the Matlab program. It is a program for simulating dynamic systems. Briefly,
the steps of using SIMULINK involve first defining a model or mathematical representation and the parameters of
your system, picking a suitable integration method, and setting up the run conditions, such as run time and initial
conditions. In SIMULINK model definition is facilitated by the graphical interface and the library of templates or
function blocks that are commonly used in mathematical descriptions of dynamic systems. As mentioned before,
SIMULINK has block libraries shown in Fig. 1: Continuous, Discrete, Functions &Tables, Math, Nonlinear,
Signal & Systems, Sources, Sinks, Discrete, Linear, Nonlinear and Connections. To examine the properties of
SIMULINK, please follow the given steps below:
Start Matlab (Start/matlab): The Matlab program starts with a display indicating the version of Matlab
program after which it will display the Matlab prompt >> in a Matlab command window.
Type simulink after the Matlab prompt >> in the Matlab command window. You will see the block
libraries as shown in Fig.1 for MATLAB 6.0. Spend time exploring the components in the libraries.
C.N./S.A./S.C
ECE-P 352
Experiment 2: Simulation
Introduction to Matlab/Simulink
Modified 01-12-05
Double clicking on a menu heading will open up a display of menu commands under that heading. For example, if
you want to create a new SIMULINK model, click the create a new model box in Fig.1 to produce a blank
SIMULINK model screen onto which you can then select and drag components from the block library to assemble
your SIMULINK simulation. Note that the screen will initially be named Untitled. You must give it a name using
the Save As menu command under the File menu heading. The assigned filename is automatically appended with
an .mdl extension.
A variety of function blocks or templates are grouped under different library blocks. A template can be copied
from a library block onto the SIMULINK model screen by first selecting the template and then dragging it to the
desired location in the SIMULINK model screen, or by a sequence of Copy and Paste commands, which are found
under the Edit menu. The combined actions of selecting and dragging are carried out by clicking on the desired
template with left-most button, keeping that button depressed, and moving the pointer to the desired location on the
SIMULINK model screen.
To open the templates of each library block, please double-click the block. This will display all the templates
contained in that block. For example, if you need derivatives and integrators, you first open up the Continuous
library block by double clicking on the icon of the continuous block to display its contents. Figure 2 shows the
contents of the continuous library block, in which you will find the derivative, integrator, and many more
components.
Many templates have internal parameters which you must specify before you use these templates in a simulation.
To view or set up these parameters, you must double-click on the template, upon which a dialog window will appear
with boxes for parameter values to be inserted.
Exercises
Exercise 1: Variable Frequency Oscillator
In this exercise, you will go through the steps to construct a SIMULINK simulation to generate an orthogonal set of
sine and cosine time functions of fixed amplitude but adjustable frequency beginning with the following equation of
an oscillator:
d 2 y1
= 2 y1
2
dt
where
C.N./S.A./S.C
ECE-P 352
Experiment 2: Simulation
Introduction to Matlab/Simulink
Modified 01-12-05
To implement the oscilltor equation, we will first convert the second-order differential equation into two first-order
differential equations and then express them in integral form: Lets introduce a new state as:
y2 = ( 1 )
dy1
dt
and we obtain
dy2
= y1
dt
Rewriting the above equation and then defining y2 in integral form, we have:
y2 = y1dt and y1 = y2 dt
To simulate the variable frequency oscilltor, draw the block diagram shown in Figure 3. While building the diagram
answer the following questions:
1) Why does the constant block, , require a value of 377? What are the units associated with this number?
2) What is the function of the simout block?
3) The black vertical bar in the diagram below is a Mux. The Mux is located in the signal routing library.
What is the function of the Mux?
C.N./S.A./S.C
ECE-P 352
Experiment 2: Simulation
Introduction to Matlab/Simulink
Modified 01-12-05
step size = auto, relative tolerance =1e-5, absolute tolerance =1e-6, output options = refine output and Refine factor
is equal to one (1).
Run simulation-Simulation/Start
Double-click scope to see the plots.
Once you finish the simulation, input the following Matlab code in the Matlab command window to get the plot and
label the axis:
plot(tout,simout(:,1),tout,simout(:,2))
xlabel('time in sec')
ylabel('y1 and y2')
C.N./S.A./S.C
ECE-P 352
Experiment 2: Simulation
Introduction to Matlab/Simulink
Modified 01-12-05
If this folder is not located on the desktop have the TA retrieve it for you from:
Network Neighborhood\ Entire Network\Microsoft Windows Network\Ece\Ece dept server\course
ware\CEPE files\Simulink\C2
Open the simulation file called S2 by typing S2 in the Matlab command window
Check the connections of the various blocks in S2 to confirm that the simulation agrees with the mathematical
model of the circuit that will be provided during the experiment.
The simulation parameters and initial conditions are already set up using the box initialize m2SIM. Double-click
on this box. This box calls an M-file, M2init.m. Open the M-File M2 and record the simulation and circuit
parameters.
Run simulation-Simulation/Start
Plot the graph by double clicking Plot results box. This will give the plot of source and inductor currents and
voltage across the capacitor, as shown in Figure 7.
In your report, supply the differential equations required to solve the circuit in Figure 5.
iL
is
ic
Rs
Vs
Vc
C.N./S.A./S.C
ECE-P 352
Experiment 2: Simulation
Introduction to Matlab/Simulink
Modified 01-12-05
C.N./S.A./S.C
ECE-P 352
Experiment 2: Simulation
Introduction to Matlab/Simulink
Modified 01-12-05
i( t ) =
1t
( Vac iR )dt + i( 0 )
L0
R
i
L
Vac
C.N./S.A./S.C
ECE-P 352
Experiment 2: Simulation
Introduction to Matlab/Simulink
Modified 01-12-05
Repeat the simulation for two different values of ac voltage phase angle,
(use function atan( ) ) where
e = 314 .
and
= tan -1
e L
R
Vac in V
50
0
-50
-100
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
0.45
0.5
0.35
0.4
0.45
0.5
mesh current
15
i in A
10
5
0
-5
-10
0
0.05
0.1
0.15
0.2
0.25
0.3
time in sec.
C.N./S.A./S.C
=0