Current Commutated Chopper Through Simulink
Current Commutated Chopper Through Simulink
Current Commutated Chopper Through Simulink
A BRIEF INTRODUCTION
1. INTRODUCTION
1.1
IMPORTANCE OF COMMUTATION
Figure 1.2 Top: A three-phase Phase Angle Converter; bottom: The input
three-phase voltage waveforms
The AC-DC Phase Angle Converter, (PAC) continues to be used in much
high power and very high power converters where the application is non-
1.2
COMMUTATION IN PAC
A three phase PAC is shown in Figure 1.2. Nominally balanced three phase
voltages V , V and V are connected to the three legs of the converter
R Y
B
via three inductances LS, which can be considered to represent the leakage
reactance of the supply transformer. At any instant, two devices are
conducting, say SCR and SCR at the time instant indicated by the
1
6
dashed line in Figure, 1.2, bottom. At that instant, phase voltage V is
R
most positive and V most negative.
B
Figure 1.4 Short circuit currents between incoming and outgoing SCRs
for various trigger angles
1.3
APPLICATIONS
Switched-mode power supply (SMPS), DC motor control, battery Charger.
CHAPTER 2 :
BASIC CHOPPERS
2.1
CLASSIFICATION OF CHOPPERS
In step down chopper output voltage is less than input voltage in step up
chopper output voltage is more than input voltage.
2.2
Figure 2.1 shows a stepdown chopper with resistive load. The thyristor in
the circuit acts as a switch. When thyristor is ON, supply voltage appears
across the load and when thyristor is OFF, the voltage across the load will
be zero.
Step-up chopper is used to obtain a load voltage higher than Vo . The input
voltage V. The values of L and C are chosen depending upon their
requirement of output voltage and Current. When the chopper is ON, the
inductor L is connected across the supply. The inductor current I rises and
the Inductor stores energy during the ON time of the chopper, tON. When
the chopper is off, the inductor current I is forced to flow through the
diode D and load for a period, tOFF. The current tends to decrease
resulting in reversing the polarity of induced EMF in L.
2.6
For convenience the chopper operation is divided into five modes:1) Mode-1
2) Mode-2
3) Mode-3
4) Mode-4
5) Mode-5
Choppers are classified as follows
1) Class A Chopper
2) Class B Chopper
3) Class C Chopper
4) Class D Chopper
5) Class E Chopper
10
CHAPTER 3 :
BASIC COMMUTATION
3.1
Aux
C is charged with the dot as positive. When the Main SCR is triggered, it
carries the load current, which is held practically level by the large filter
inductance, L and the Free-wheeling diode. Additionally, the charged
F
Capacitor swings half a cycle through Th , L and D ending with a
M
negative at the dot. The reverse voltage may be less than its positive value
as some energy is lost in the various components in the path. The half
cycle capacitor current adds to the load current and is taken by the Main
SCR.
With the negative at the dot C-Th
When Th
Aux
is enabled to commutate Th .
Aux
M
is triggered the negative charge of the capacitor is impressed
11
onto Th
and it immediately turns off. The SCR does take the reverse
M
recovery current in the process. Thereafter, the level load current charges
the capacitor linearly to the supply voltage with the dot again as positive.
The Load voltage peaks by the addition of the capacitor voltage to the
supply when Th
is triggered. The voltage falls as the capacitor
Aux
discharges both changes being linear because of the level load current.
When the Capacitor voltage returns to zero, the load voltage equals supply
voltage. The turn-off time offered by the commutation circuit to the SCR
lasts till this stage starting from the triggering of Th
. Now the
Aux
capacitor is progressively positively charged and the load voltage is
equally diminished from the supply voltage. Th
is naturally
Aux
commutated when the capacitor is fully charged and a small excess voltage
12
switches on the freewheeling diode. With the positive at the dot the
capacitor is again ready for the next cycle. Here Th
must be switched
Aux
before Th to charge C to desired polarity.
M
Voltage commutation may be chosen for comparatively fast switching and
it can be identified from the steep fall of the SCR current. There is no
overlapping operation between the incoming and the outgoing devices and
both currents fall and rise sharply. Stresses on all the three semiconductors
can be expected to be high here.
3.3
CURRENT COMMUTATION
The circuit of Figure 3.1 can be converted into a current commuted one
just by interchanging the positions of the diode and the capacitor. Here the
Capacitor is automatically charged through D-L-L -Load with the dot as
F
positive. Any of the SCRs can thus be switched on first. If Th is
M
triggered first, it immediately takes the load current turning off D . When
F
ThAux is triggered, it takes a half cycle of the ringing current in the L-C
circuit and the polarity of the charge across the capacitor reverses. As it
swings back, Th
is turned off and the path through D-C-L shares the
Aux
load current which may again be considered to be reasonably level. The
Current-share of TH is thus reduced in a sinusoidal (damped) manner.
M
Turn-off process is consequently accompanied by an overlap between
Th and the diode D in the D-C-L path. Once the main SCR is turned off,
M
the capacitor current becomes level and the voltage decreases linearly. A
voltage spike appears across the load when the voltage across the
commutating inductance collapses and the capacitance voltage adds to the
supply voltage.
The free-wheeling diode also turns on through an overlap with D when the
capacitor voltage just exceeds the supply voltage and this extra voltage
drives the commutating current through the path D-Supply-D -L. Thus
F
there is soft switching of all devices during this period.
Further an additional diode may be connected across the main SCR. It
ensures soft turn-off by conducting the excess current in the ringing L-C
circuit. The low forward voltage appearing across the SCR causes it to
turn-off slowly. Consequently switching frequencies have to be low. Note
13
that such a diode cannot be connected across the Main SCR in the voltagecommutated circuit.
3.4
LOAD COMMUTATION
14
15
CHAPTER 4 :
CHOPPER
class A
class C
16
class D
class E
Step-up chopper
Parameters
Step
down
chopper
Step up chopper
Range
of
output voltage
0 to V volts
V to + volts
Position
of
chopper switch
In series with
load
Expression for
output voltage
VL dc = D x V
volts
Vo = V/ ( 1 D )
volts
External
inductance
Not required
Required
for
boosting the output
voltage
Use
For motoring
operation, for
motor load
For
regenerative
braking for motor
load.
17
Type
chopper
of
Quadrant
operation
of
Applications
Single quadrant
Single quadrant
1st quadrant
1st quadrant
Motor
control
Battery
charging/voltage
boosters
speed
First quadrant
Two quadrant
Four quadrant
On basis of commutation method:
Voltage commutated
Current commutated
Load commutated
Impulse commutated
Most modern uses also use alternative nomenclature which helps to clarify
which particular type of circuit is being discussed. These include:
18
4.2
APPLICATIONS OF CHOPPER
Variable-frequency drive
Battery chargers
4.3
CHOPPER AMPLIFIRES
One classic use for a chopper circuit and where the term is still in use is
in chopper amplifiers. These are DC amplifiers. Some types of signals that
need amplifying can be so small that an incredibly high gain is required,
but very high gain DC amplifiers are much harder to build with low offset
and 1/ noise, and reasonable stability and bandwidth. It's much easier to
build an AC amplifier instead. A chopper circuit is used to break up the
input signal so that it can be processed as if it were an AC signal, then
integrated back to a DC signal at the output. In this way, extremely small
DC signals can be amplified. This approach is often used in electronic
instrumentation where stability and accuracy are essential; for example, it
19
amplifiers
CHAPTER 5 :
SIMULINK MODEL AND RESULTS
5.1
BLOCKS USED
20
are
1. DC Voltage Source
2. Diode
3. Diode1
4. Diode2
5. Ideal Switch
6. Multimeter
7. Pulse Generator
8. Pulse Generator1
9. Series RLC Branch
10.Series RLC Branch1
11.Series RLC Branch2
12.Series RLC Branch3
13.Step
14.Terminator
15.Thyristor
16.Thyristor1
17.powergui
5.2
SIMULATION MODEL
21
5.3
PROCESS
22
5.4
OUTPUT WAVEFORM
23
CHAPTER 6 :
CONCLUSION
24
APPENDIX A
Power electronics is the application of solid-state electronics to the control
and conversion of electric power. It also refers to a subject of research in
electronic and electrical engineering which deals with the design, control,
computation and integration of nonlinear, time-varying energy-processing
electronic systems with fast dynamics.
The first high power electronic devices were mercury-arc valves. In
modern systems the conversion is performed with semiconductor
switching devices such as diodes, thyristors and transistors, pioneered
by R. D. Middle brook and others beginning in the 1950s. In contrast to
electronic systems concerned with transmission and processing of signals
and data, in power electronics substantial amounts of electrical energy are
processed. An AC/DC converter (rectifier) is the most typical power
electronics device found in many consumer electronic devices,
e.g. television sets, personal computers, battery chargers, etc. The power
range is typically from tens of watts to several hundred watts. In industry a
common application is the variable speed drive (VSD) that is used to
control an induction motor. The power range of VSDs start from a few
hundred watts and end at tens of megawatts.
The power conversion systems can be classified according to the type of
the input and output power
AC to DC (rectifier)
DC to AC (inverter)
DC to DC (DC-to-DC converter)
AC to AC (AC-to-AC converter)
1A History
Power electronics started with the development of the mercury arc
rectifier. Invented by Peter Cooper Hewitt in 1902, it was used to convert
alternating current (AC) into direct current (DC). From the 1920s on,
research continued on applying thyratrons and grid-controlled mercury arc
valves to power transmission. Uno Lamm developed a mercury valve with
grading electrodes making them suitable for high voltage direct
current power transmission. In 1933 selenium rectifiers were invented.
In 1947 the bipolar point-contact transistor was invented by Walter H.
Brattain and John Bardeen under the direction of William Shockley at Bell
Labs. In 1948 Shockley's invention of the bipolar junction transistor (BJT)
improved the stability and performance of transistors, and reduced costs.
25
2A Devices
The capabilities and economy of power electronics system are determined
by the active devices that are available. Their characteristics and
limitations are a key element in the design of power electronics systems.
Formerly, the mercury arc valve, the high-vacuum and gas-filled diode
thermionic rectifiers, and triggered devices such as the thyratron and
ignitron were widely used in power electronics. As the ratings of solidstate devices improved in both voltage and current-handling capacity,
vacuum devices have been nearly entirely replaced by solid-state devices.
Power electronic devices may be used as switches, or as
amplifiers. An ideal switch is either open or closed and so dissipates no
power; it withstands an applied voltage and passes no current, or passes
any amount of current with no voltage drop. Semiconductor devices used
as switches can approximate this ideal property and so most power
electronic applications rely on switching devices on and off, which makes
systems very efficient as very little power is wasted in the switch. By
contrast, in the case of the amplifier, the current through the device varies
continuously according to a controlled input. The voltage and current at
the device terminals follow a load line, and the power dissipation inside
the device is large compared with the power delivered to the load.
Several attributes dictate how devices are used. Devices such
as diodes conduct when a forward voltage is applied and have no external
control of the start of conduction. Power devices such as silicon controlled
rectifiers and thyristors (as well as the mercury valve and thyratron) allow
control of the start of conduction, but rely on periodic reversal of current
flow to turn them off. Devices such as gate turn-off thyristors, BJT and
MOSFET transistors provide full switching control and can be turned on
or off without regard to the current flow through them. Transistor devices
also allow proportional amplification, but this is rarely used for systems
26
rated more than a few hundred watts. The control input characteristics of a
device also greatly affect design; sometimes the control input is at a very
high voltage with respect to ground and must be driven by an isolated
source.
As efficiency is at a premium in a power electronic converter, the losses
that a power electronic device generates should be as low as possible.
Devices vary in switching speed. Some diodes and thyristors are suited for
relatively slow speed and are useful for power frequency switching and
control; certain thyristors are useful at a few kilohertz. Devices such as
MOSFETS and BJTs can switch at tens of kilohertz up to a few megahertz
in power applications, but with decreasing power levels. Vacuum tube
devices dominate high power (hundreds of kilowatts) at very high
frequency (hundreds or thousands of megahertz) applications. Faster
switching devices minimize energy lost in the transitions from on to off
and back, but may create problems with radiated electromagnetic
interference. Gate drive (or equivalent) circuits must be designed to supply
sufficient drive current to achieve the full switching speed possible with a
device. A device without sufficient drive to switch rapidly may be
destroyed by excess heating.
Practical devices have non-zero voltage drop and dissipate power when on,
and take some time to pass through an active region until they reach the
"on" or "off" state. These losses are a significant part of the total lost
power in a converter.
Power handling and dissipation of devices is also a critical factor in
design. Power electronic devices may have to dissipate tens or hundreds of
watts of waste heat, even switching as efficiently as possible between
conducting and non-conducting states. In the switching mode, the power
controlled is much larger than the power dissipated in the switch. The
forward voltage drop in the conducting state translates into heat that must
be dissipated. High power semiconductors require specialized heat sinks or
active cooling systems to manage their junction temperature; exotic
semiconductors such as silicon carbide have an advantage over straight
silicon in this respect, and germanium, once the main-stay of solid-state
electronics is now little used due to its unfavorable high temperature
properties.
Semiconductor devices exist with ratings up to a few kilovolts in a single
device. Where very high voltage must be controlled, multiple devices must
be used in series, with networks to equalize voltage across all devices.
Again, switching speed is a critical factor since the slowest-switching
device will have to withstand a disproportionate share of the overall
voltage. Mercury valves were once available with ratings to 100 kV in a
single unit, simplifying their application in HVDC systems.
27
3A Solid-state devices
Table A1 : Different devices and their descriptions with ratings
Device
Description
Ratings
Diode
Up
to
3000
amperes and 5000
volts in a single
silicon
device.
High
voltage
requires multiple
series
silicon
devices.
Silicon-controlled
rectifier(SCR)
Up
to
3000
amperes,
5000
volts in a single
silicon device.
Thyristor
28
Triac
Bipolar
junction The BJT cannot be used at high power; they are
transistor(BJT)
slower and have more resistive losses when
compared to MOSFET type devices. To carry
high current, BJTs must have relatively large
base currents, thus these devices have high
power losses when compared to MOSFET
devices. BJTs along with MOSFETs, are also
29
30
31
32
5A
33
34
As was true for PWM, both switches in a leg for square wave modulation
cannot be turned on at the same time, as this would cause a short across the
voltage source. The switching scheme requires that both S+ and S- be on
for a half cycle of the AC output period. The fundamental AC output
amplitude is equal to vo1 = vaN = 2vi/ .
Its harmonics have an amplitude of voh = vo1/h.
Therefore, the AC output voltage is not controlled by the inverter, but
rather by the magnitude of the DC input voltage of the inverter.
Using selective harmonic elimination (SHE) as a modulation technique
allows the switching of the inverter to selectively eliminate intrinsic
harmonics. The fundamental component of the AC output voltage can also
be adjusted within a desirable range. Since the AC output voltage obtained
from this modulation technique has odd half and odd quarter wave
symmetry, even harmonics do not exist. Any undesirable odd (N-1)
intrinsic harmonics from the output waveform can be eliminated.
6A
Figure A4: Carrier and Modulating Signals for the Bipolar Pulse width
Modulation Technique
The full-bridge inverter is similar to the half bridge-inverter, but it has an
additional leg to connect the neutral point to the load. Figure A3 shows the
circuit schematic of the single-phase voltage source full-bridge inverter.
35
To avoid shorting out the voltage source, S1+ and S1- cannot be on at the
same time, and S2+ and S2- also cannot be on at the same time. Any
modulating technique used for the full-bridge configuration should have
either the top or the bottom switch of each leg on at any given time. Due to
the extra leg, the maximum amplitude of the output waveform is Vi, and is
twice as large as the maximum achievable output amplitude for the halfbridge configuration.
States 1 and 2 are used to generate the AC output voltage with bipolar
SPWM. The AC output voltage can take on only two values, either Vi or
Vi. To generate these same states using a half-bridge configuration, a
carrier based technique can be used. S+ being on for the half-bridge
corresponds to S1+ and S2- being on for the full-bridge. Similarly, Sbeing on for the half-bridge corresponds to S1- and S2+ being on for the
full bridge. The output voltage for this modulation technique is more or
less sinusoidal, with a fundamental component that has an amplitude in the
linear region of ma less than or equal to one vo1 =vab1= vi ma.
Unlike the bipolar PWM technique, the unipolar approach uses states 1, 2,
3 and 4 from to generate its AC output voltage. Therefore, the AC output
voltage can take on the values Vi, 0 or Vi. To generate these states, two
sinusoidal modulating signals, Vc and Vc, are needed, as seen in Figure
A4.
Vc is used to generate VaN, while Vc is used to generate VbN. The
following relationship is called unipolar carrier-based SPWMvo1 =2 vaN1=
vi ma.
The phase voltages VaN and VbN are identical, but 180 degrees out of
phase with each other. The output voltage is equal to the difference of the
two phase voltages, and do not contain any even harmonics. Therefore, if
mf is taken, even the AC output voltage harmonics will appear at
normalized odd frequencies, fh. These frequencies are centered on double
the value of the normalized carrier frequency. This particular feature
allows for smaller filtering components when trying to obtain a higher
quality output waveform.
As was the case for the half-bridge SHE, the AC output voltage contains
no even harmonics due to its odd half and odd quarter wave symmetry.
7A
36
8A
AC/AC converters
Converting AC power to AC power allows control of the voltage,
frequency, and phase of the waveform applied to a load from a supplied
AC system. The two main categories that can be used to separate the types
of converters are whether the frequency of the waveform is
changed. AC/AC converters that don't allow the user to modify the
frequencies are known as AC Voltage Controllers, or AC Regulators. AC
converters that allow the user to change the frequency are simply referred
37
AC voltage controller:
The purpose of an AC Voltage Controller, or AC Regulator, is to vary the
RMS voltage across the load while at a constant frequency. Three control
methods that are generally accepted are ON/OFF Control, Phase-Angle
Control, and Pulse Width Modulation AC Chopper Control (PWM AC
Chopper Control). All three of these methods can be implemented not only
in single-phase circuits, but three-phase circuits as well.
PWM AC Chopper Control: The other two control methods often have
poor harmonics, output current quality, and input power factor. In order to
improve these values PWM can be used instead of the other methods.
What PWM AC Chopper does is have switches that turn on and off several
times within alternate half-cycles of input voltage.
10A
38
Single-Phase to Single-Phase Cycloconverters: Single-Phase to SinglePhase Cycloconverters started drawing more interest recently, because of
the decrease in both size and price of the power electronics switches. The
single-phase high frequency ac voltage can be either sinusoidal or
trapezoidal. These might be zero voltage intervals for control purpose or
zero voltage commutation.
39
strategy can be applied by changing the switching state of the input section
while the output section is in a freewheeling mode. This commutation
algorithm is significantly less complexity and higher reliability as
compared to a conventional direct matrix converter.
11A
DC link converters:
Hybrid matrix converters are relatively new for AC/AC converters. These
converters combine the AC/DC/AC design with the matrix converter
design. Multiple types of hybrid converters have been developed in this
new category, an example being a converter that uses uni-directional
switches and two converter stages without the dc-link; without the
capacitors or inductors needed for a dc-link, the weight and size of the
converter is reduced. Two sub-categories exist from the hybrid converters,
named hybrid direct matrix converter (HDMC) and hybrid indirect matrix
converter (HIMC). HDMC convert the voltage and current in one stage,
while the HIMC utilizes separate stages, like the AC/DC/AC converter, but
without the use of an intermediate storage element.
13A
Applications:
Below is a list of common applications that each converter is used in.
40
41
AC/AC converters are used to change either the voltage level or the
frequency (international power adapters, light dimmer). In power
distribution networks AC/AC converters may be used to exchange
power between utility frequency 50 Hz and 60 Hz power grids.
Motor drives are found in pumps, blowers, and mill drives for textile,
paper, cement and other such facilities. Drives may be used for power
conversion and for motion control. For AC motors, applications
include variable-frequency drives, motor soft starters and excitation
systems.
In hybrid electric vehicles (HEVs), power electronics are used in two
formats: series hybrid and parallel hybrid. The difference between a series
hybrid and a parallel hybrid is the relationship of the electric motor to
the internal combustion engine (ICE). Devices used in electric vehicles
consist mostly of dc/dc converters for battery charging and dc/ac
converters to power the propulsion motor. Electric trains use power
electronic devices to obtain power, as well as for vector control using pulse
width modulation (PWM) rectifiers. The trains obtain their power from
power lines. Another new usage for power electronics is in elevator
systems. These systems may use thyristors, inverters, magnet motors, or
various hybrid systems that incorporate PWM systems and standard
motors.
14A
Inverters
42
cause the inverter to generate output currents that compensate for the
harmonic content. This configuration requires no real power consumption,
as it is fully fed by the line; the DC link is simply a capacitor that is kept at
a constant voltage by the control system. In this configuration, output
currents are in phase with line voltages to produce a unity power factor.
Conversely, VAR compensation is possible in a similar configuration
where output currents lead line voltages to improve the overall power
factor.
In facilities that require energy at all times, such as hospitals and airports,
UPS systems are utilized. In a standby system, an inverter is brought
online when the normally supplying grid is interrupted. Power is
instantaneously drawn from onsite batteries and converted into usable AC
voltage by the VSI, until grid power is restored, or until backup generators
are brought online. In an online UPS system, a rectifier-DC-link-inverter is
used to protect the load from transients and harmonic content. A battery in
parallel with the DC-link is kept fully charged by the output in case the
grid power is interrupted, while the output of the inverter is fed through a
low pass filter to the load. High power quality and independence from
disturbances is achieved.
Various AC motor drives have been developed for speed, torque, and
position control of AC motors. These drives can be categorized as lowperformance or as high-performance, based on whether they are scalarcontrolled or vector-controlled, respectively. In scalar-controlled drives,
fundamental stator current, or voltage frequency and amplitude, are the
only controllable quantities. Therefore, these drives are employed in
applications where high quality control is not required, such as fans and
compressors. On the other hand, vector-controlled drives allow for
instantaneous current and voltage values to be controlled continuously.
This high performance is necessary for applications such as elevators and
electric cars.
Inverters are also vital to many renewable energy applications. In
photovoltaic purposes, the inverter, which is usually a PWM VSI, gets fed
by the DC electrical energy output of a photovoltaic module or array. The
inverter then converts this into an AC voltage to be interfaced with either a
load or the utility grid. Inverters may also be employed in other renewable
systems, such as wind turbines. In these applications, the turbine speed
usually varies causing changes in voltage frequency and sometimes in the
magnitude. In this case, the generated voltage can be rectified and then
inverted to stabilize frequency and magnitude.
15A
Smart grid
43
Power electronics can be used to help utilities adapt to the rapid increase in
distributed residential/commercial solar power generation. Germany and
parts of Hawaii, California and New Jersey require costly studies to be
conducted before approving new solar installations. Relatively small-scale
ground- or pole-mounted devices create the potential for a distributed
control infrastructure to monitor and manage the flow of power.
Traditional electromechanical systems, such as capacitor banks or voltage
regulators at substations, can take minutes to adjust voltage and can be
distant from the solar installations where the problems originate. If voltage
on a neighborhood circuit goes too high, it can endanger utility crews and
cause damage to both utility and customer equipment. Further, a grid fault
causes photovoltaic generators to shut down immediately, spiking demand
for grid power. Smart grid-based regulators are more controllable than far
more numerous consumer devices.
44
45
APPENDIX B
B1
MATLAB
MATLAB (matrix laboratory)
is
a multi-paradigm numerical
computing environment and fourth-generation programming language.
A proprietary
programming
language developed
by MathWorks,
MATLAB allows matrix manipulations, plotting of functions and data,
implementation of algorithms, creation of user interfaces, and interfacing
with programs written in other languages, including C,C+
+, Java, Fortran and Python.
Although MATLAB is intended primarily for numerical computing, an
optional toolbox uses the MuPAD symbolic engine, allowing access
to symbolic computing capabilities. An additional package, Simulink, adds
graphical
multi-domain
simulation
and model-based
design for dynamic and embedded systems.
In 2004, MATLAB had around one million users across industry and
academia. MATLAB
users
come
from various
backgrounds
of engineering, science, and economics.
B2
History
Cleve Moler, the chairman of the computer science department at
the University of New Mexico, started developing MATLAB in the late
1970s. He designed it to give his students access to LINPACK and
EISPACK without them having to learn Fortran. It soon spread to other
universities and found a strong audience within the applied
mathematics community. Jack Little, an engineer, was exposed to it during
a visit Moler made to Stanford University in 1983. Recognizing its
commercial potential, he joined with Moler and Steve Bangert. They
rewrote MATLAB in C and founded MathWorks in 1984 to continue its
development. These rewritten libraries were known as JACKPAC. In 2000,
MATLAB was rewritten to use a newer set of libraries for matrix
manipulation, LAPACK.
MATLAB was first adopted by researchers and practitioners in control
engineering, Little's specialty, but quickly spread to many other domains.
It is now also used in education, in particular the teaching of
linear, numerical analysis, and is popular amongst scientists involved
in image processing.
B3
Syntax
The MATLAB application is built around the MATLAB scripting
language. Common usage of the MATLAB application involves using the
46
B4
47
>>array=1:3:9
array=
147
the increment value can actually be left out of this syntax (along with one
of the colons), to use a default value of 1.
>>ari=1:5
ari=
12345
assigns to the variable named ari an array with the values 1, 2, 3, 4, and 5,
since the default value of 1 is used as the incrementer.
Indexing is one-based, which is the usual convention for matrices in
mathematics, although not for some programming languages such as C,
C++, and Java.
Matrices can be defined by separating the elements of a row with blank
space or comma and using a semicolon to terminate each row. The list of
elements should be surrounded by square brackets: []. Parentheses: () are
used to access elements and sub arrays (they are also used to denote a
function argument list).
>>A=[163213;510118;96712;415141]
A=
163213
510118
96712
415141
>>A(2,3)
ans=
11
Sets of indices can be specified by expressions such as "2:4", which
evaluates to [2, 3, 4]. For example, a sub matrix taken from rows 2 through
4 and columns 3 through 4 can be written as:
>>A(2:4,3:4)
ans=
118
712
141
A square identity matrix of size n can be generated using the function eye,
and matrices of any size with zeros or ones can be generated with the
functions zeros and ones, respectively.
>>eye(3,3)
ans=
48
100
010
001
>>zeros(2,3)
ans=
000
000
>>ones(2,3)
ans=
111
111
Most MATLAB functions can accept matrices and will apply themselves
to each element. For example, mod(2*J,n) will multiply every element in
"J" by 2, and then reduce each element modulo "n". MATLAB does
include standard "for" and "while" loops, but (as in other similar
applications such as R), using the vectorized notation often produces code
that is faster to execute. This code, excerpted from the function magic.m,
creates
a magic
square M for
odd
values
of n (MATLAB
functionmeshgrid is used here to generate square matrices I and J
containing 1:n).
[J,I]=meshgrid(1:n);
A=mod(I+J-(n+3)/2,n);
B=mod(I+2*J-2,n);
M=n*A+B+1;
B5
Structures
MATLAB has structure data types. Since all variables in MATLAB are
arrays, a more adequate name is "structure array", where each element of
the array has the same field names. In addition, MATLAB supports
dynamic field names (field look-ups by name, field manipulations, etc.).
Unfortunately, MATLAB JIT does not support MATLAB structures,
therefore just a simple bundling of various variables into a structure will
come at a cost.
B6
Functions
When creating a MATLAB function, the name of the file should match the
name of the first function in the file. Valid function names begin with an
alphabetic character, and can contain letters, numbers, or underscores.
49
B7
Function handles
MATLAB supports elements of lambda calculus by introducing function
handles, or function references, which are implemented either in .m files or
anonymous nested functions.
B8
B9
50
x=0:pi/100:2*pi;
y=sin(x);
plot(x,y)
produces the following figure of the sine function:
[X,Y]=meshgrid(-10:0.25:10,-10:0.25:10);
f=sinc(sqrt((X/pi).^2+(Y/pi).^2));
mesh(X,Y,f);
axis([-1010-1010-0.31])
xlabel('{\bfx}')
ylabel('{\bfy}')
zlabel('{\bfsinc} ({\bfR})')
hiddenoff
This code produces a wireframe 3D plot of the twodimensional unnormalized sine function:
51
B10
SIMULINK
52
53
REFERENCES
54