You are on page 1of 34

MATLAB-SIMULINK

 Matlab Tutorial
 MATLAB - Home
 MATLAB - Overview
 MATLAB - Environment Setup
 MATLAB - Syntax
 MATLAB - Variables
 MATLAB - Commands
 MATLAB - M-Files
 MATLAB - Data Types
 MATLAB - Operators
 MATLAB - Decisions
 MATLAB - Loops
 MATLAB - Vectors
 MATLAB - Matrix
 MATLAB - Arrays
 MATLAB - Colon Notation
 MATLAB - Numbers
 MATLAB - Strings
 MATLAB - Functions
 MATLAB - Data Import
 MATLAB - Data Output

 MATLAB Advanced
 MATLAB - Plotting
 MATLAB - Graphics
 MATLAB - Algebra
 MATLAB - Calculus
 MATLAB - Differential
 MATLAB - Integration
 MATLAB - Polynomials
 MATLAB - Transforms
 MATLAB - GNU Octave
 MATLAB - Simulink
MATLAB is a programming language developed by MathWorks. It started out as a
matrix programming language where linear algebra programming was simple. It can
be run both under interactive sessions and as a batch job. This tutorial gives you
aggressively a gentle introduction of MATLAB programming language. It is
designed to give students fluency in MATLAB programming language. Problem-
based MATLAB examples have been given in simple and easy way to make your
learning fast and effective.

Audience
This tutorial has been prepared for the beginners to help them understand basic to
advanced functionality of MATLAB. After completing this tutorial you will find
yourself at a moderate level of expertise in using MATLAB from where you can take
yourself to next levels.

Prerequisites
We assume you have a little knowledge of any computer programming and
understand concepts like variables, constants, expression, statements, etc. 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.
MATLAB (matrix laboratory) is a fourth-generation high-level programming
language and interactive environment for numerical computation, visualization and
programming.
MATLAB is developed by MathWorks.

It allows matrix manipulations; plotting of functions and data; implementation of


algorithms; creation of user interfaces; interfacing with programs written in other
languages, including C, C++, Java, and FORTRAN; analyze data; develop
algorithms; and create models and applications.
It has numerous built-in commands and math functions that help you in
mathematical calculations, generating plots, and performing numerical methods.

MATLAB's Power of Computational Mathematics


MATLAB is used in every facet of computational mathematics. Following are some
commonly used mathematical calculations where it is used most commonly −

 Dealing with Matrices and Arrays


 2-D and 3-D Plotting and graphics
 Linear Algebra
 Algebraic Equations
 Non-linear Functions
 Statistics
 Data Analysis
 Calculus and Differential Equations
 Numerical Calculations
 Integration
 Transforms
 Curve Fitting
 Various other special functions

Features of MATLAB
Following are the basic features of MATLAB −
 It is a high-level language for numerical computation, visualization and application
development.
 It also provides an interactive environment for iterative exploration, design and problem
solving.
 It provides vast library of mathematical functions for linear algebra, statistics, Fourier
analysis, filtering, optimization, numerical integration and solving ordinary differential
equations.
 It provides built-in graphics for visualizing data and tools for creating custom plots.
 MATLAB's programming interface gives development tools for improving code quality
maintainability and maximizing performance.
 It provides tools for building applications with custom graphical interfaces.
 It provides functions for integrating MATLAB based algorithms with external applications
and languages such as C, Java, .NET and Microsoft Excel.

Uses of MATLAB
MATLAB is widely used as a computational tool in science and engineering
encompassing the fields of physics, chemistry, math and all engineering streams. It
is used in a range of applications including −

 Signal Processing and Communications


 Image and Video Processing
 Control Systems
 Test and Measurement
 Computational Finance
 Computational Biology

Local Environment Setup


Setting up MATLAB environment is a matter of few clicks. The installer can be
downloaded from here.
MathWorks provides the licensed product, a trial version and a student version as
well. You need to log into the site and wait a little for their approval.
After downloading the installer the software can be installed through few clicks.
Understanding the MATLAB Environment
MATLAB development IDE can be launched from the icon created on the desktop.
The main working window in MATLAB is called the desktop. When MATLAB is
started, the desktop appears in its default layout −
The desktop has the following panels −
 Current Folder − This panel allows you to access the project folders and files.

 Command Window − This is the main area where commands can be entered at the
command line. It is indicated by the command prompt (>>).

 Workspace − The workspace shows all the variables created and/or imported from files.
 Command History − This panel shows or return commands that are entered at the
command line.

Set up GNU Octave


If you are willing to use Octave on your machine ( Linux, BSD, OS X or Windows ),
then kindly download latest version from Download GNU Octave. You can check
the given installation instructions for your machine.
MATLAB environment behaves like a super-complex calculator. You can enter
commands at the >> command prompt.
MATLAB is an interpreted environment. In other words, you give a command and
MATLAB executes it right away.

Hands on Practice
Type a valid expression, for example,
Live Demo

5 + 5

And press ENTER


When you click the Execute button, or type Ctrl+E, MATLAB executes it
immediately and the result returned is −
ans = 10
Let us take up few more examples −
Live Demo

3 ^ 2 % 3 raised to the power of 2

When you click the Execute button, or type Ctrl+E, MATLAB executes it
immediately and the result returned is −
ans = 9
Another example,
Live Demo

sin(pi /2) % sine of angle 90 o

When you click the Execute button, or type Ctrl+E, MATLAB executes it
immediately and the result returned is −
ans = 1
Another example,
Live Demo

7/0 % Divide by zero

When you click the Execute button, or type Ctrl+E, MATLAB executes it
immediately and the result returned is −
ans = Inf
warning: division by zero
Another example,
Live Demo

732 * 20.3

When you click the Execute button, or type Ctrl+E, MATLAB executes it
immediately and the result returned is −
ans = 1.4860e+04
MATLAB provides some special expressions for some mathematical symbols, like
pi for π, Inf for ∞, i (and j) for √-1 etc. Nan stands for 'not a number'.

Use of Semicolon (;) in MATLAB


Semicolon (;) indicates end of statement. However, if you want to suppress and
hide the MATLAB output for an expression, add a semicolon after the expression.
For example,
Live Demo

x = 3;
y = x + 5
When you click the Execute button, or type Ctrl+E, MATLAB executes it
immediately and the result returned is −
y = 8
Adding Comments
The percent symbol (%) is used for indicating a comment line. For example,
x = 9 % assign the value 9 to x

You can also write a block of comments using the block comment operators % { and
% }.
The MATLAB editor includes tools and context menu items to help you add,
remove, or change the format of comments.

Commonly used Operators and Special Characters


MATLAB supports the following commonly used operators and special characters −

Operator Purpose

+ Plus; addition operator.

- Minus; subtraction operator.

* Scalar and matrix multiplication operator.

.* Array multiplication operator.

^ Scalar and matrix exponentiation operator.

.^ Array exponentiation operator.

\ Left-division operator.

/ Right-division operator.

.\ Array left-division operator.

./ Array right-division operator.


: Colon; generates regularly spaced elements and represents an entire row or
column.

() Parentheses; encloses function arguments and array indices; overrides


precedence.

[] Brackets; enclosures array elements.

. Decimal point.

… Ellipsis; line-continuation operator

, Comma; separates statements and elements in a row

; Semicolon; separates columns and suppresses display.

% Percent sign; designates a comment and specifies formatting.

_ Quote sign and transpose operator.

._ Nonconjugated transpose operator.

= Assignment operator.

Special Variables and Constants


MATLAB supports the following special variables and constants −

Name Meaning

ans Most recent answer.

eps Accuracy of floating-point precision.

i,j The imaginary unit √-1.


Inf Infinity.

NaN Undefined numerical result (not a number).

pi The number π

Naming Variables
Variable names consist of a letter followed by any number of letters, digits or
underscore.
MATLAB is case-sensitive.
Variable names can be of any length, however, MATLAB uses only first N
characters, where N is given by the function namelengthmax.

Saving Your Work


The save command is used for saving all the variables in the workspace, as a file
with .mat extension, in the current directory.
For example,
save myfile
You can reload the file anytime later using the load command.
Get Started with Simulink
Simulation and Model-Based Design

Simulink® is a block diagram environment for multidomain simulation and Model-Based Design. It
supports system-level design, simulation, automatic code generation, and continuous test and
verification of embedded systems. Simulink provides a graphical editor, customizable block libraries,
and solvers for modeling and simulating dynamic systems. It is integrated with MATLAB ®, enabling
you to incorporate MATLAB algorithms into models and export simulation results to MATLAB for
further analysis.

Tutorials
 Simulink Block Diagrams

Learn the basics of Simulink.


 Create a Simple Model

Model a simple system in Simulink.


 Navigate Model

Navigate the hierarchy and connections in a system.


Model-Based Design with Simulink

Simulink Block Diagrams
Simulink® is a graphical modeling and simulation environment for dynamic systems. You can create
block diagrams, where blocks represent parts of a system. A block can represent a physical
component, a small system, or a function. An input/output relationship fully characterizes a block.
Consider these examples:
 A faucet fills a bucket — Water goes into the bucket at a certain flow rate, and the bucket gets
heavier. A block can represent the bucket, with flow rate as the input and its weight as the output.
 You use a megaphone to make your voice heard — The sound produced at one end of the
megaphone is amplified at the other end. The megaphone is the block, the input is the sound wave at
its source, and the output is the sound wave as you hear it.
 You push a cart and it moves — The cart is the block, the force you apply is the input, and the
cart's position is the output.
The definition of a block is only complete with its inputs and outputs defined; this task relates to the
goal of the model. For example, the cart velocity may be a natural choice as an output if the modeling
goal does not involve its location.
Simulink provides block libraries that are collections of blocks grouped by functionality. For example,
to model a megaphone that multiplies its input by a constant, you use a Gain block from the Math
Operations library.
A sound wave goes into the megaphone as its input, and a louder version of the same wave comes
out as its output.
The > signs denote the inputs and outputs of a block, which can be connected to other blocks.

You can connect blocks to other blocks to form systems and represent more complex functionality.
For example, an audio player turns a digital file into sound. A digital representation is read from
storage, is interpreted mathematically, and then turned into physical sound. The software that
processes the digital file to compute the sound waveform can be one block; the speaker that takes the
waveform and turns it into sound can be another block. A component that generates the input is
another block.
To model the sine wave input to the megaphone in Simulink, include a Sine Wave source.

The primary function of Simulink is to simulate behavior of system components over time. In its
simplest form, this task involves keeping a clock, determining the order in which the blocks are to be
simulated, and propagating the outputs computed in the block diagram to the next block. Consider the
megaphone. At each time step, Simulink must compute the value of the sine wave, propagate it to the
megaphone, and then compute the value of its output.

At each time step, each block computes its outputs from its inputs. Once all of the signals in a
diagram are computed at a given time step, Simulink determines the next time step (based on the
model configuration and numerical solver algorithms) and advances the simulation clock. Then each
block computes their output for this new time step.

In simulation, time progresses differently from a real clock. Each time step takes as much time as it
takes to finish the computations for that time step, whether that time step represents a fraction of a
second or a few years.
Often, the effect of a component's input on its output is not instantaneous. For example, turning on a
heater does not result in an instant change in temperature. Rather, this action provides input to a
differential equation. The history of the temperature (a state) is also a factor. When simulation
requires solving a differential or difference equation, Simulink employs memory and numerical solvers
to compute the state values for the time step.
Simulink handles data in three categories:
 Signals — Block inputs and outputs, computed during simulation
 States — Internal values, representing the dynamics of the block, computed during simulation
 Parameters — Values that affect the behavior of a block, controlled by the user
At each time step, Simulink computes new values for signals and states. By contrast, you specify
parameters when you build the model and can occasionally change them while simulation is running.
Create a Simple Model
You can use Simulink® to model a system and then simulate the dynamic behavior of that system. The
basic techniques you use to create a simple model in this tutorial are the same as those you use for
more complex models. This example simulates simplified motion of a car. A car is typically in motion
while the gas pedal is pressed. After the pedal is released, the car idles and comes to a stop.
A Simulink block is a model element that defines a mathematical relationship between its input and
output. To create this simple model, you need four Simulink blocks.

Block Name Block Purpose Model Purpose

Pulse Generator Generate an input signal for the model Represent the accelerator pe

Gain Multiply the input signal by a constant value Calculate how pressing the a

Integrator, Second-Order Integrate the input signal twice Obtain position from acceler

Outport Designate a signal as an output from the model Designate the position as an

Simulating this model integrates a brief pulse twice to get a ramp. The results display in a Scope
window. The input pulse represents a press of the gas pedal — 1 when the pedal is pressed and 0
when it is not. The output ramp is the increasing distance from the starting point.

Open New Model


Use the Simulink Editor to build your models.

1. Start MATLAB . From the MATLAB toolstrip, click the Simulink button 


®
.
2. Click the Blank Model template.
The Simulink Editor opens.

3. From the Simulation tab, select Save > Save as. In the File name text box, enter a
name for your model. For example, simple_model. Click Save. The model is saved with
the file extension .slx.
Open Simulink Library Browser
Simulink provides a set of block libraries, organized by functionality in the Library Browser.
The following libraries are common to most workflows:
 Continuous — Blocks for systems with continuous states
 Discrete — Blocks for systems with discrete states
 Math Operations — Blocks that implement algebraic and logical equations
 Sinks — Blocks that store and show the signals that connect to them
 Sources — Blocks that generate the signal values that drive the model

1. From the Simulation tab, click the Library Browser button  .

2. Set the Library Browser to stay on top of the other desktop windows. On the Simulink
Library Browser toolbar, select the Stay on top button  .
To browse through the block libraries, select a category and then a functional area in the left
pane. To search all of the available block libraries, enter a search term.
For example, find the Pulse Generator block. In the search box on the browser toolbar,
enter pulse, and then press Enter. Simulink searches the libraries for blocks with pulse in
their name or description and then displays the blocks.
Get detailed information about a block. Right-click the Pulse Generator block, and then
select Help for the Pulse Generator block. The Help browser opens with the reference page
for the block.
Blocks typically have several parameters. You can access all block parameters by double-
clicking the block.
Add Blocks to a Model
To start building the model, browse the library and add the blocks.
1. From the Sources library, drag the Pulse Generator block to the Simulink Editor. A
copy of the Pulse Generator block appears in your model with a text box for the value of
the Amplitude parameter. Enter 1.

Parameter values are held throughout the simulation.


2. Add the following blocks to your model using the same approach.
Block Library

Gain Simulink/Math Operations

Integrator, Second-Order Simulink/Continuous

Outport Simulink/Sinks

3. Add a second Outport block by copying the existing one and pasting it at another


point using keyboard shortcuts.
4. Your model now has the blocks you need.
5. Arrange the blocks by clicking and dragging each block. To resize a block, drag a
corner.

Connect Blocks
Connect the blocks by creating lines between output ports and input ports.
1. Click the output port on the right side of the Pulse Generator block.
The output port and all input ports suitable for a connection are highlighted.

2. Click the input port of the Gain block.


Simulink connects the blocks with a line and an arrow indicating the direction of signal
flow.

3. Connect the output port of the Gain block to the input port on the Integrator, Second-
Order block.
4. Connect the two outputs of the Integrator, Second-Order block to the
two Outport blocks.
5. Save your model. In the Simulation tab, click the Save button.

Add Signal Viewer


To view simulation results, connect the first output to a Signal Viewer.
Click the signal. In the Simulation tab under Prepare, click Add Viewer. Select Scope. A
viewer icon appears on the signal and a scope window opens.

You can open the scope at any time by double-clicking the icon.
Run Simulation
After you define the configuration parameters, you are ready to simulate your model.
1. In the Simulation tab, set the simulation stop time by changing the value in the
toolbar.
The default stop time of 10.0 is appropriate for this model. This time value has no unit.
The time unit in Simulink depends on how the equations are constructed. This example
simulates the simplified motion of a car for 10 seconds — other models could have time
units in milliseconds or years.

2. To run the simulation, click the Run button  .


The simulation runs and produces the output in the viewer.

Refine Model
This example takes an existing model, moving_car.slx, and models a proximity sensor based
on this motion model. In this scenario, a digital sensor measures the distance between the car
and an obstacle 10 m (30 ft) away. The model outputs the sensor measurement and the
position of the car, taking these conditions into consideration:
 The car comes to a hard stop when it reaches the obstacle.
 In the physical world, a sensor measures the distance imprecisely, causing random
numerical errors.
 A digital sensor operates at fixed time intervals.
Change Block Parameters
View MATLAB Command

To start, open the moving_car model. At the MATLAB command line, enter:


open_system('moving_car.slx')

You first need to model the hard stop when the car position reaches 10 . The Integrator,
Second-Order block has a parameter for that purpose.
1. Double-click the Integrator, Second-Order block. The Block Parameters dialog box
appears.
2. Select Limit x and enter 10 for Upper limit x. The background color for the
parameter changes to indicate a modification that is not applied to the model. Click OK to
apply the changes and close the dialog box.
Add New Blocks and Connections
Add a sensor that measures the distance from the obstacle.
1. Modify the model. Expand the model window to accommodate the new blocks as
necessary.
o Find the actual distance. To find the distance between the obstacle position
and the vehicle position, add the Subtract block from the Math Operations library. Also
add the Constant block from the Sources library to set the constant value of 10 for the
position of the obstacle.
o Model the imperfect measurement that would be typical to a real sensor.
Generate noise by using the Band-Limited White Noise block from the Sources library.
Set the Noise power parameter to 0.001. Add the noise to the measurement by using
an Add block from the Math Operations library.
o Model a digital sensor that fires every 0.1 seconds. In Simulink, sampling of a
signal at a given interval requires a sample and hold. Add the Zero-Order Hold block
from the Discrete library. After you add the block to the model, change the Sample
Time parameter to 0.1.
o Add another Outport to connect to the sensor output. Keep the default value of
the Port number parameter.
2. Connect the new blocks. The output of the Integrator, Second-Order block is already
connected to another port. To create a branch in that signal, left-click the signal to
highlight potential ports for connection, and click the appropriate port.

Annotate Signals
Add signal names to the model.
1. Double-click the signal and type the signal name.

2. To finish, click away from the text box.


3. Repeat these steps to add the names as shown.

Compare Multiple Signals


Compare the actual distance signal with the measured distance signal.
1. Create and connect a Scope Viewer to the actual distance signal. Right-click the
signal and select Create & Connect Viewer > Simulink > Scope. The name of the
signal appears in the viewer title.
2. Add the measured distance signal to the same viewer. Right-click the signal and
select Connect to Viewer > Scope1. Make sure that you are connecting to the viewer you
created in the previous step.

3. Run the model. The Viewer shows the two signals, actual distance in yellow
and measured distance in blue.
4. Zoom into the graph to observe the effect of noise and sampling. Click
the Zoom button  . Left-click and drag a window around the region you want to see
more closely.

You can repeatedly zoom in to observe the details.


From the plot, note that the measurement can deviate from the actual value by as much as 0.3
m. This information becomes useful when designing a safety feature, for example, a collision
warning.

Navigate Model
Simulink® models can be organized into hierarchical components. In a hierarchical model, you can
choose to view the system at a high level, or navigate down the model hierarchy to see increasing
levels of model detail.

Navigate Through Model Hierarchy


View MATLAB Command
To start, open the smart_braking model. At the MATLAB command line, enter:
open_system('smart_braking.slx')

In the model:
 A vehicle moves as the gas pedal is pressed.
 A proximity sensor measures the distance between the vehicle and an obstacle.
 An alert system generates an alarm based on that proximity.
 The alarm automatically controls the brake to prevent a collision.
When you build a model, you connect blocks together to model complex components that
represent system dynamics. In this model, Vehicle, Proximity sensor, and Alert system are all
complex components with multiple blocks that exist in a hierarchy of subsystems. To view
the contents of a subsystem, double-click the subsystem.
To view a representation of the complete model hierarchy, click the Hide/Show Model
Browser button at the bottom left corner of the model window.

The Model Browser shows that all subsystems you view at the top level have subsystems of
their own. Expand each subsystem node to see the subsystems it contains. You can navigate
through the hierarchy in the Model Browser. For example, expand the Proximity sensor node
and then select the Sensor model subsystem.
The address bar shows which subsystem you are viewing. To open the subsystem in a
separate window, right-click the subsystem and select Open In New Window.
Every input or output port on a subsystem has a corresponding Inport or Outport block inside
the subsystem. These blocks represent data transfer between a subsystem and its parent.
When a system contains multiple input or output ports, the number on the Inport or Outport
blocks indicates the position of the port on the subsystem interface.
View Signal Attributes
Signal lines in Simulink indicate data transfer from block to block. Signals have properties
corresponding to their function in the model:
 Dimensions — Scalar, vector, or matrix
 Data type — String, double, unsigned integer, etc.
 Sample time — A fixed time interval at which the signal has an updated value, or
continuous sampling
To show the data type of all signals in a model, in the Debug tab, under Information
Overlays, click Port Data Type.

The model displays data types along the signal lines. Most signals are double, except the
output of the Alert system. Double-click the subsystem to investigate.
The data type labels in this subsystem show that data type change occurs in the Alert device
subsystem. Double-click the subsystem to investigate.

The Alert device component converts the Alert index signal from a double to an integer.
You can set the data type at sources, or use a Data Type Conversion block from the Signal
Attributes library. Double, the default data type, provides the best numerical precision and is
supported in all blocks. The double data type also uses the most memory and computing
power. Other numerical data types can be used to model embedded systems where memory
and computing power are limited.
To show sample times, in the Debug tab, under Information Overlays, click Colors from
the Sample Time section. The model updates to show different colors for each sample time in
the model, along with a legend.

 A block or signal with continuous dynamics is black. Signals with continuous sample
time update as often as Simulink requires to make the computations as close to the physical
world as possible.
 A block or signal that is constant is magenta. They remain unchanged through
simulation.
 A discrete block or signal that updates at the lowest fixed interval is red. Signals with
discrete sample time update at a fixed interval. If the model contains components with
different fixed sample times, each discrete sample time has a different color.
 Multirate subsystems, which contain a mix of discrete and continuous signals, are
yellow.
Trace a Signal
This model has a constant input and a discrete output. To determine where the sampling
scheme changes, trace the output signal through blocks.

1. To open the Model Browser, click the Hide/Show Model Browser button  .


2. To highlight the output signal, in the Signal tab, click the Trace to
Source button  .
The editor is now in highlight mode. Click the editor to continue.

3. To continue tracing the signal to its source, press the left arrow key.

4. Keep tracing the signal to its source until you reach the Alert logic subsystem. You
see that the Subtract block has two inputs. Choose the signal path from the Inport by
pressing the down arrow key.

5. To find the source of the discretization, keep pressing the left arrow and note the
colors of port names that reflect the sample time.

The Zero-Order Hold block in the Sensor model subsystem coverts the signal from
continuous to discrete.
Inverter (Three-Phase)
Implements a three-phase inverter model for AC Motor Drives

Library
Simscape / Electrical / Specialized Power Systems / Electric Drives / Fundamental Drive Blocks

Description
The Inverter (Three-Phase) block models a standard three-leg, two-level inverter model (detailed
mode) or an average-value inverter model (average mode). Average mode has multiple instances,
depending on the AC motor drive type.

Detailed mode
In detailed mode, the Inverter (Three-Phase) block is an instance of the Universal Bridge block
configured as a three-arm (three-phase), forced-commutated converter.

Average Mode
In average mode, the Inverter (Three-Phase) block implements an average-value inverter model for a
specific AC drive type. The average-value inverter model can be a current source type with AC
current reference signal, voltage source type with an AC voltage reference signal, or voltage source
type with AC current reference signal.
Current Source Type with AC Current Reference Signal
This model is used for an AC drive type based on field-oriented control, WFSM vector control, or
PMSM vector control.
The inverter is represented by current sources on the AC side during normal operation. The AC
current reference signal generates the three-phase currents at the inverter output. When the inverter
is saturated, it operates in square-wave mode, and the current sources are replaced with voltage
sources. The average-value inverter model of this type is shown in the figure.
The model is composed of one controlled current source on the DC side and of two controlled current
sources and three controlled voltage sources on the AC side. The DC current source allows the
representation of the average DC bus current behavior following the equation
Idc = (Pac + Plosses) / Vdc,
with Pac being the AC side instantaneous power, Plosses the losses in the power electronics devices,
and Vdc the DC bus voltage.
On the AC side, the current sources represent the average phase currents fed to the motor. The
current values are set equal to the current references sent by the current regulator. A small current is
injected to compensate for the current drawn by the three-phase load (needed because of the inverter
current sources in series with the inductive motor).
The currents are fed by three controlled voltage sources during loss of current tracking due to
insufficient inverter voltage. These voltage sources represent the square wave mode and allow good
representation of the phase currents during inverter saturation. Each voltage source outputs
either Vin or 0, depending on the values of the pulses (1 or 0) send by the current controller. This mode
of operation is detected from the Saturation detection block using the DC bus voltage and the counter
electro-motive force generated by the AC machine.
Voltage Source Type with AC Voltage Reference Signal
This model is used for AC drive type based on space vector modulation.
The inverter is represented with voltage sources on the AC side. The AC voltage reference signal
generates the three-phase voltage at the inverter output. The average-value inverter model of this
type is shown in the figure.
The model is composed of one controlled current source on the DC side and three controlled voltage
sources on the AC side. The DC current source allows the representation of the average DC bus
current behavior, following the equation
Idc = αaIa + αbIb + αcIc,
with αa, αb, αc being the PWM duty cycles (or phase-voltage-to-DC-bus-voltage ratio) of the inverter
legs A, B, and C respectively, and Ia, Ib, Ic the corresponding three-phase currents. The three AC
voltage sources represent the average voltage values of the three-phase inverter voltages Va, Vb, Vc,
following the equation
Va = αaVin
Vb = αbVin
Vc = αcVin,
with Vin being the input DC bus voltage value.
Voltage Source Type with AC Current Reference Signal
This average-value inverter model is used for the Brushless DC current control AC drive type.
The inverter is represented with voltage sources on the AC side. The AC machine parameters are
required together with the AC current reference signal to generate the three-phase voltages at the
inverter output. The figure shows the average-value inverter model of this type for a trapezoidal
PMSM drive.
The model is composed of one controlled current source on the DC side and two controlled voltage
sources on the AC side. The DC current source allows the representation of the DC bus current
behavior described by the equation
Idc = (Pout + Plosses) / Vin,
with Pout being the output AC power, Plosses the losses in the power electronic devices, and Vin the DC bus
voltage.
On the AC side, the voltage sources are fed by the instantaneous voltages provided by the
Trapezoidal PMSM dynamic model (see the PMSM documentation for the machine model). This
dynamic model takes the AC reference currents (the rate of these currents has been limited to
represent the real-life currents), the measured BEMF voltages, and the machine speed to compute
the terminal voltages to apply to the machine.
The dynamic rate limiter limits the rate of the reference currents when transitions occur. The rate
depends on the inverter saturation degree.
During loss of current tracking due to insufficient inverter voltage, the dynamic rate limiter saturates
the reference current according to this operation mode.

Parameters
Model detail level
Specify the model detail level to use:
 Detailed (default)
 Average
Sample Time
The sample time of the inverter, in seconds. The default value is 2e-6.
Snubber resistance Rs (Ohms)
The snubber resistance, in ohms. Set the Snubber resistance Rs parameter to inf to
eliminate the snubbers from the model. The default value is 10e3.
Snubber capacitance Cs (F)
The snubber capacitance, in farads. Set the Snubber capacitance Cs parameter to 0 to
eliminate the snubbers or to inf to get a resistive snubber. The default value is inf.
Power electronic device
Select the type of power electronic device to use in the bridge.
 GTO / Diodes (default)
 MOSFET / Diodes
 IGBT / Diodes
Drive type
Specify the drive type to use. This parameter is visible only when the Model detail
level parameter is set to Average. Select one of these values:

 Field-oriented control (default)
 Space vector modulation
 WFSM vector control
 PMSM vector control
 Brushless DC
Ron (Ohms)
Internal resistance of the switch, in ohms. The default value is 1e-3.
Forward voltages (V) [Vf, Vfd]
Forward voltages, in volts, of the forced-commutated devices (GTO, MOSFET, or IGBT) and
of the antiparallel diodes. This parameter is available when the selected Power electronic
device is GTO/Diodes or IGBT/Diodes. The default value is [1.2,1.2].
Fall time and tail time (s) [Tf, Tt]
Fall time Tf and tail time Tt, in seconds, for the GTO or the IGBT devices. The default value
is [1e-6,2e-6].
The default value is[1e-6,2e-6].
Measurements
Default is None.
Select Device voltages to measure the voltages across the six power electronic device
terminals.
Select Device currents to measure the currents flowing through the six power electronic
devices. If antiparallel diodes are used, the measured current is the total current in the forced-
commutated device (GTO, MOSFET, or IGBT) and in the antiparallel diode. A positive current
therefore indicates a current flowing in the forced-commutated device and a negative current
indicates a current flowing in the diode. If snubber devices are defined, the measured currents
are the ones flowing through the power electronic devices only.
Select UAB UBC UCA UDC voltages to measure the terminal voltages (AC and DC) of
the Inverter (Three-Phase) block.
Select All voltages and currents to measure all voltages and currents defined for
the Inverter (Three-Phase) block.
Place a Multimeter block in your model to display the selected measurements during the
simulation. In the Available Measurements menu of the Multimeter block, the measurement
is identified by a label followed by the block name.

Measurement
Device voltages
Branch current
Terminal voltages
Source Frequency (Hz)
Synchronous frequency of the machine, in hertz. This parameter is visible only when
the Model detail level parameter is set to Average. The default value is 60.
Reference frame
Specifies the reference frame that is used to convert input voltages (abc reference frame) to
the dq reference frame, and output currents (dq reference frame) to the abc reference frame.
You can choose from the following reference frame transformations:
 Rotor (default)
 Stationary
 Synchronous
This parameter is visible only when the Model detail level parameter is set to Average and
the Drive type parameter is set to Field-oriented control.
Stator [Rs (Ohms), Lls (H)]
The stator resistance, in ohms, and leakage inductance, in henry, of the motor. This
parameter is visible only when the Model detail level parameter is set to Average and
the Drive type parameter is set to Field-oriented control .The default value is [14.85e-
3,0.3027e-3].
Stator [Rs (Ohms), Ll, Lmd, Lmq (H)]
The stator resistance, in ohms, leakage inductance, in henry, and the d and q mutual
inductances of the motor, in henry. This parameter is visible only when the Model detail
level parameter is set to Average and the Drive type parameter is set to WFSM vector
control. The default value is [2.01e-3,4.289e-4,4.477e-3,1.354e-3].
Rotor [ Rr' (Ohms) Llr' (H)]
The rotor resistance, in ohms, and leakage inductance, in henry, both referred to the stator.
This parameter is visible only when the Model detail level parameter is set to Average and
the Drive type parameter is set to Field-oriented control. The default value is [9.295e-
3,0.3027e-3].
Mutual inductance Lm (H)
The magnetizing inductance of the motor, in henry. This parameter is visible only when
the Model detail level parameter is set to Average and the Drive type parameter is set
to Field-oriented control. The default value is 10.46e-3.
The default value is10.46e-3.
Inductances (H) [Ld, Lq]
The phase-to-neutral Ld and Lq inductances in the d-axis and q-axis of the sinusoidal model
with salient-pole rotor. This parameter is visible only when the Model detail level parameter
is set to Average and the Drive type parameter is set to PMSM vector control.
The default value is [8.5e-3,8.5e-3].
Inductance (H)
The armature inductance of the sinusoidal model with round rotor (Ld is equal to Lq). This
parameter is visible only when the Model detail level parameter is set to Average and
the Drive type parameter is set to Brushless DC . The default value is 8.5e-3.
Resistance (Ohms)
The stator phase resistance Rs, in ohms, of the motor. This parameter is visible only when
the Model detail level parameter is set to Average and the Drive type parameter is set
to PMSM vector control. The default value is 0.2.
Flux induced by magnets (Wb)
The constant flux, in weber, per pole pairs induced in the stator windings by the magnets of
the motor. This parameter is visible only when the Model detail level parameter is set
to Average and the Drive type parameter is set to PMSM vector control or Brushless DC.
The default value is 0.175.
Pairs of poles
The number of pole pairs of the machine controlled by the inverter. This parameter is visible
only when the Model detail level parameter is set to Average. The default value is 4.

Inputs and Outputs


g
The gate input for the controlled switch devices. Pulses are sent to upper and lower switches
of inverter legs A, B, and C. This input is visible only when the Model detail level parameter
is set to Detailed.
ctrl
Control signals from the appropriate controller. In average mode, the Inverter (Three-
Phase) block no longer receives pulses, but receives various types of other signals that are
drive-type specific. This input is visible only when the Model detail level parameter is set
to Average and the Drive type parameter is set to Field-oriented control, WFSM vector
control, or PMSM vector control.
Duty
The PWM duty cycles (or phase-voltage-to-DC-bus-voltage ratio) of the inverter legs A, B,
and C. This input is visible only when the Model detail level parameter is set to Average and
the Drive type parameter is set to Space vector modulation.
+
The positive terminal on the DC side.
-
The negative terminal on the DC side.
A, B, C
The three-phase terminals on the AC side.

Composite Three-Phase Rectifier


View MATLAB Command

This is the base model for analysis workflow examples.

Model

You might also like