Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
115 views

1 hMATLAB - Simulink - Tutorial

The document provides an overview of MATLAB and Simulink, which are tools for technical computing and simulations widely used in engineering. It describes the basic functionality of MATLAB as a programming language and Simulink as an environment for graphical model-based simulation. The document then demonstrates constructing and simulating a simple circuit model in Simulink to illustrate its capabilities. It shows how to build the model using blocks from the Simulink library, run the simulation, and view the output waveform.

Uploaded by

Wasim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views

1 hMATLAB - Simulink - Tutorial

The document provides an overview of MATLAB and Simulink, which are tools for technical computing and simulations widely used in engineering. It describes the basic functionality of MATLAB as a programming language and Simulink as an environment for graphical model-based simulation. The document then demonstrates constructing and simulating a simple circuit model in Simulink to illustrate its capabilities. It shows how to build the model using blocks from the Simulink library, run the simulation, and view the output waveform.

Uploaded by

Wasim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

MATLAB/Simulink tutorial

ECEN 2060
MATLAB/Simulink
• MathWorks tools for technical computing and simulations, widely used
across various engineering and science disciplines
• MATLAB
 Programming language and interactive environment well suited for
computing, algorithms, data processing and visualization
• Simulink
 Environment for graphical, model-based simulation of dynamic systems
• Available in all computer labs in the Engineering building
• Personal copy py (full
( version,, but for students only)
y) can be purchased
p at
www,mathworks.com for $99. This is not required for ECEN2060
• Tutorial objectives: very basic introduction to the tools at the level
sufficient to understand ECEN2060 simulation models and do homework
assignments

ECEN2060 2
Start MATLAB, then start Simulink
Click here to start Simulink Choose Current Directory

MATLAB commands
and scripts can be
executed
interactively in the
“Command Window”

ECEN2060 3
Simulink Library Browser
• Library Browser gives access to various
standard or additional blocks that are
used to build more complicated models
• ECEN2060 models will be constructed
using standard Simulink blocks from the
Simulink library
• Click File - New – Model (or Ctrl-N) to
start a new model window

ECEN2060 4
Constructing and simulating a simple circuit model

iR Circuit equation: iR = (1/R) vac


+
“Sine Wave”
vac vR R
10  Simulink: output block from
VM = 1 V “Gain” Sources

Block from
Math Operations

Connect block inputs and outputs according to


Drag an drop Drag an drop Drag an drop the circuit equation
Sine Wave block Gain block from Scope block Double-click a block to change parameter
from Sources in Math Operations from Sinks in the values
the Library in the Library Library
To better document the model, double-click on
the block name or on the connection line to
change block and signal names as desired
ECEN2060 5
Constructing and simulating a simple circuit model
Total simulation time (10 seconds in
Click here to start simulation this example) can be changed here

Autoscale

Double-click on the Scope


block to display the output Scope
waveform (current iR) parameters

Explore various menu options, block


properties, etc. For example:
• Add another axis to the Scope
and display both iR and vR
• Repeat simulations for different
values of the sinewave amplitude
or frequency, or different R
ECEN2060 6
Notes
• Simulink
Si li k blblocks
k hhave zero, one or more iinputs and
d
zero, one or more outputs
• Inputs
I t andd outputs
t t are allll considered
id d ““signals”
i l ”
• Unlike circuit-oriented simulators (e.g. Spice),
Simulink has no knowledge of whether a signal is
voltage, current, power, torque, speed, …, which
 makes it a very general tool for simulations of various
dynamical systems, but
 requires a user to decide which signals are inputs and
which signals are outputs, and make block connections to
correctly model system equations; as a result, Simulink
block diagrams may not be as intuitive as circuit diagrams

ECEN2060 7
Another example
Make sure you have downloaded pv1.mdl and findMPP.m to Set MATLAB
a working folder (files are available on the course website, Current
MATLAB/Simulink page) Directory to
the folder
where you
downloaded
pv1.mdl and
findMPP.m

Double-
click
pv1.mdl to
open the
PV cell
Simulink
model

ECEN2060 8
Simple PV cell Simulink model pv1.mdl
Circuit model Model equations input
iPV

ISC
iD +

vD
+

vPV
 
i D  I o e vD / VT  1 , v D  v PV

  i PV  I SC  i D
output

Product block from Math XY Graph


G h block
bl k
Operations from Sinks
ECEN2060
PV cell characteristics PV power

Repeating Vpv
Ppv
sequence Ppv
p Ipv PV

block from Product To Workspace


Fcn block from User-
Sources
Defined Functions
To Workspace
Vpv
1e-9*(exp(u/26e-3)-1) I-V characteristic block from Sinks
Vpv PN-junction characteristic Id
sends simulation
Mux block from results to
Signal Routing MATLAB
1000 1/1000
ISC Ipv
combines 3 workspace for
Insolation Insolation to
ISC current gain signals into one further
vector output processing
Constant block from Sources
pv1.mdl Simulink model
ECEN2060 9
Run pv1 simulation
Output power Ppv (i.e the product
Output current iPV as a function of
of iPV and vPV) as a function of vPV
vPV is immediately displayed in
is immediately displayed in a X-Y
another X-Y
X Y Plot window
Pl t window
Plot i d

Output power Ppv, current iPV, voltage vPV, and simulation time are
stored in a “structure” variable PV, which is made available (using the
“To Workspace” block) for ffurther
rther processing in the MATLAB
Command Window
ECEN2060 10
Example of MATLAB processing of simulation results

Type “findMPP” and Enter in the MATLAB Command Window. This runs
the MATLAB script findMPP.m, which takes the simulation results and
finds the maximum power point (power, voltage and current) and again
plots power Ppv and Ipv as functions of Vpv.

Double-click on the
findMPP.m file to open
the script and examine
the MATLAB code

ECEN2060 11
More notes
• Si
Simulink
li k model
d l and d MATLAB Fi Figure windows
i d iinclude
l d a
“Copy” function in the “Edit” menu. This is useful for
reporting
p g results: yyou can simply
p y copy
py and p paste yyour
models or graphical results into a Word or PowerPoint
document
• You may want to explore other options in the MATLAB
Figure window. For example, find out how add a grid,
change the line type, thickness or color, change the x-axis or
y-axis scales, etc.
• This tutorial is very limited in scope, just to get you started
with the tools we will be using to model and test various
electrical or electro-mechanical energy systems in
ECEN2060. You may want to browse through
Si li k/MATLAB HELP d
Simulink/MATLAB documentation
t ti tto ffurther
th explorel
the tool capabilities
ECEN2060 12

You might also like