modeling and simulation of permanent
TRANSCRIPT
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 1/83
MODELING AND SIMULATION OF PERMANENT
MAGNET SYNCHRONOUS MOTOR DRIVE SYSTEM
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 2/83
Symbols
B- friction
BDCM -Brushless DC Motor
CSI -Current Source Inverter
d -Direct o polar axis
f c -crossover frequency
ia,ib,ic -Three phase currents
id -d-axis current
if -equivalent permanent magnet field current
iq -q-axis current
Im -Peak value of supply current
IGBT -Insolate Gate Bipolar Transistor
IPM -Interior Permanent Magnet
J -inertia
L -self inductance
Ld -d-axis self inductance
Lls -stator leakage inductance
Ldm -d-axis magnetizing inductance
Lqm -q-axis magnetizing inductance
Lq -q-axis self inductance
Ls -equivalent self inductance per phase
P -number of poles
PI - proportional integral
PM- Permanent Magnet
PMSM -Permanent Magnet Synchronous Motorq Quadrature or interpolar axis
Rs-stator resistance
SPM-Surface Permanent Magnet
Te develop torque
TL-load torque
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 3/83
Va,Vb,Vc -Three phase voltage
Vd -d-axis voltage
Vq -q-axis voltage
VSI-Voltage Source Inverter
ρ -derivative operator
λd -flux linkage due d axis
λf -PM flux linkage or Field flux linkage
λq- flux linkage due q axis
θr- rotor position
ωm- rotor speed
ωr -electrical speed
ωrated- motor rated speed
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 4/83
1 INTRODUCTION
Permanent magnet (PM) synchronous motors are widely used in low and mid power applications
such as computer peripheral equipments, robotics, adjustable speed drives and electric vehicles.
The growth in the market of PM motor drives has demanded the need of simulation tools capable
of handling motor drive simulations. Simulations have helped the process of developing new
systems including motor drives, by reducing cost and time. Simulation tools have the capabilities
of performing dynamic simulations of motor drives in a visual environment so as to facilitate the
development of new systems.
In this work, the simulation of a field oriented controlled PM motor drive system is developed
using Simulink. The simulation circuit will include all realistic components of the drive system.
This enables the calculation of currents and voltages in different parts of the inverter and motor
under transient and steady conditions. The losses in different parts can be calculated facilitating
the design of the inverter.
A closed loop control system with a PI controller in the speed loop has been designed to operate
in constant torque and flux weakening regions. Implementation has been done in Simulink. A
comparative study of hysteresis and PWM control schemes associated with current controllers
has been made in terms of harmonic spectrum and total harmonic distortion. Simulation results
are given for two speeds of operation, one below rated and another above rated speed.
1.1 Motivation
Modeling and simulation is usually used in designing PM drives compared to building system
prototypes because of the cost. Having selected all components, the simulation process can start
to calculate steady state and dynamic performance and losses that would have been obtained if
the drive were actually constructed. This practice reduces time, cost of building prototypes and
ensures that requirements are achieved. In works available until now ideal components have been
assumed in the inverter feeding the motor and simulations have been carried out. The voltages
and currents in different parts of the inverter have not been obtained and hence the losses and
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 5/83
efficiency can not be calculated. In this work, the simulation of a PM motor drive system is
developed using Simulink. The simulation circuit includes all realistic components of the drive
system. This enables the calculation of currents and voltages in different parts of the inverter and
motor under transient and steady conditions. The losses in different parts are calculated. A
comparative study associated with hysteresis and PWM control techniques in current controllers
has been made. A speed controller has also been designed for closed loop operation of the drive.
Design method for the PI controller is also given.
1.2 Previous Work
PM motor drives have been a topic of interest for the last twenty years. Different
authors have carried out modeling and simulation of such drives.
In 1986 Sebastian, T., Slemon, G. R. and Rahman, M. A. [1] reviewed permanent
magnet synchronous motor advancements and presented equivalent electric circuit models
for such motors and compared computed parameters with measured parameters.
Experimental results on laboratory motors were also given.
In 1986 Jahns, T.M., Kliman, G.B. and Neumann, T.W. [2] discussed that interior
permanent magnet (IPM) synchronous motors possessed special features for adjustable speed
operation which distinguished them from other classes of ac machines. They were robust
high power density machines capable of operating at high motor and inverter efficiencies
over wide speed ranges, including considerable range of constant power operation. The
magnet cost was minimized by the low magnet weight requirements of the IPM design. The
impact of the buried magnet configuration on the motor’s electromagnetic characteristics was
discussed. The rotor magnetic saliency preferentially increased the quadrature-axis
inductance and introduced a reluctance torque term into the IPM motor’s torque equation.
The electrical excitation requirements for the IPM synchronous motor were also discussed.
The control of the sinusoidal phase currents in magnitude and phase angle with respect to the
rotor orientation provided a means for achieving smooth responsive torque control. A basic
feed forward algorithm for executing this type of current vector torque control was discussed,
including the implications of current regulator saturation at high speeds. The key results were
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 6/83
illustrated using a combination of simulation and prototype IPM drive measurements.
In 1988 Pillay and Krishnan, R. [3], presented PM motor drives and classified them
into two types such as permanent magnet synchronous motor drives (PMSM) and brushless
dc motor (BDCM) drives. The PMSM has a sinusoidal back emf and requires sinusoidal
stator currents to produce constant torque while the BDCM has a trapezoidal back emf and
requires rectangular stator currents to produce constant torque. The PMSM is very similar to
the wound rotor synchronous machine except that the PMSM that is used for servo
applications tends not to have any damper windings and excitation is provided by a
permanent magnet instead of a field winding. Hence the d, q model of the PMSM can be
derived from the well known model of the synchronous machine with the equations of the
damper windings and field current dynamics removed. Equations of the PMSM are derived
in rotor reference frame and the equivalent circuit is presented without dampers. The damper
windings are not considered because the motor is designed to operate in a drive system with
field-oriented control. Because of the nonsinusoidal variation of the mutual inductances
between the stator and rotor in the BDCM, it is also shown in this paper that no particular
advantage exists in transforming the abc equations of the BCDM to the d, q frame.
As an extension of his previous work, Pillay, P. and Krishnan, R. in 1989 [4]
presented the permanent magnet synchronous motor (PMSM) which was one of several types
of permanent magnet ac motor drives available in the drives industry. The motor had a
sinusoidal flux distribution. The application of vector control as well as complete modeling,
simulation, and analysis of the drive system were given. State space models of the motor and
speed controller and real time models of the inverter switches and vector controller were
included. The machine model was derived for the PMSM from the wound rotor synchronous
motor. All the equations were derived in rotor reference frame and the equivalent circuit was
presented without dampers. The damper windings were not considered because the motor
was designed to operate in a drive system with field-oriented control. Performancedifferences due to the use of pulse width modulation (PWM) and hysteresis current
controllers were examined. Particular attention was paid to the motor torque pulsations and
speed response and experimental verification of the drive performance were given.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 7/83
Morimoto, S., Tong, Y., Takeda, Y. and Hirasa, T. in 1994 [5], in their paper aimed
to improve efficiency in permanent magnet (PM) synchronous motor drives. The controllable
electrical loss which consisted of the copper loss and the iron loss could be minimized by the
optimal control of the armature current vector. The control algorithm of current vector
minimizing the electrical loss was proposed and the optimal current vector could be decided
according to the operating speed and the load conditions. The proposed control algorithm
was applied to the experimental PM motor drive system, in which one digital signal
processor was employed to execute the control algorithms, and several drive tests were
carried out. The operating characteristics controlled by the loss minimization control
algorithm were examined in detail by computer simulations and experimental results.
The paper in 1997 by Wijenayake, A.H. and Schmidt, P.B. [6], described the
development of a two-axis circuit model for permanent magnet synchronous motor (PMSM)
by taking machine magnetic parameter variations and core loss into account. The circuit
model was applied to both surface mounted magnet and interior permanent magnet rotor
configurations. A method for on-line parameter identification scheme based on no-load
parameters and saturation level, to improve the model, was discussed in detail. Test schemes to
measure the equivalent circuit parameters, and to calculate saturation constants which
govern the parameter variations were also presented.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 8/83
CHAPTER - 2
2 DESCRIPTION OF THE DRIVE SYSTEM
This chapter deals with the description of the different components such as permanent magnet
motors, position sensors, inverters and current controllers of the drive system. A review of
permanent magnet materials and classification of permanent magnet motors is also given.
2.1 Permanent Magnet Synchronous Motor Drive System
The motor drive consists of four main components, the PM motor, inverter, control unit and the
position sensor. The components are connected as shown in figure 2.1.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 9/83
2.2 Permanent Magnet Synchronous Motor
A permanent magnet synchronous motor (PMSM) is a motor that uses permanent magnets to
produce the air gap magnetic field rather than using electromagnets. These motors have
significant advantages, attracting the interest of researchers and industry for use in manyapplications.
2.2.1 Permanent Magnet Materials
The properties of the permanent magnet material will affect directly the performance of the
motor and proper knowledge is required for the selection of the materials and for understanding
PM motors.
The earliest manufactured magnet materials were hardened steel. Magnets made from steel were
easily magnetized. However, they could hold very low energy and it was easy to demagnetize. In
recent years other magnet materials such as Aluminum Nickel and Cobalt alloys (ALNICO),
Strontium Ferrite or Barium Ferrite (Ferrite), Samarium Cobalt (First generation rare earth
magnet) (SmCo) and Neodymium Iron-Boron (Second generation rare earth magnet) (NdFeB)
have been developed and used for making permanent magnets.
The rare earth magnets are categorized into two classes: Samarium Cobalt (SmCo) magnets and
Neodymium Iron Boride (NdFeB) magnets. SmCo magnets have higher flux density levels but
they are very expensive. NdFeB magnets are the most common rare earth magnets used in
motors these days. A flux density versus magnetizing field for these magnets
is illustrated in figure 2.2.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 10/83
Figure 2.2 Flux Density versus Magnetizing Field of Permanent Magnetic Materials[21]
2.2.2 Classification of Permanent Magnet Motors
2.2.2.1 Direction of field flux
PM motors are broadly classified by the direction of the field flux. The first field flux
classification is radial field motor meaning that the flux is along the radius of the motor. The
second is axial field motor meaning that the flux is perpendicular to the radius of the motor.
Radial field flux is most commonly used in motors and axial field flux have become a topic of
interest for study and used in a few applications.
2.2.2.2 Flux density distribution
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 11/83
PM motors are classified on the basis of the flux density distribution and the shape of current
excitation. They are PMSM and PM brushless motors (BLDC). The PMSM has a sinusoidal-
shaped back EMF and is designed to develop sinusoidal back EMF waveforms.
They have the following:
1. Sinusoidal distribution of magnet flux in the air gap
2. Sinusoidal current waveforms
3. Sinusoidal distribution of stator conductors.
BLDC has a trapezoidal-shaped back EMF and is designed to develop trapezoidal back EMF
waveforms. They have the following:
1. Rectangular distribution of magnet flux in the air gap
2. Rectangular current waveform
3. Concentrated stator windings.
2.2.2.3 Permanent magnet radial field motors
In PM motors, the magnets can be placed in two different ways on the rotor. Depending on the
placement they are called either as surface permanent magnet motor or interior permanent
magnet motor.
Surface mounted PM motors have a surface mounted permanent magnet rotor. Each of the PM is
mounted on the surface of the rotor, making it easy to build, and specially skewed poles are
easily magnetized on this surface mounted type to minimize cogging torque. This configuration
is used for low speed applications because of the limitation that the magnets will fly apart during
high-speed operations. These motors are considered to have small saliency, thus having
practically equal inductances in both axes [22]. The permeability of the permanent magnet is
almost that of the air, thus the magnetic material becoming an extension of the air gap. For a
surface permanent magnet motor Ld = Lq [8].
The rotor has an iron core that may be solid or may be made of punched laminations for
simplicity in manufacturing [23]. Thin permanent magnets are mounted on the surface of this
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 12/83
core using adhesives. Alternating magnets of the opposite magnetization direction produce
radially directed flux density across the air gap. This flux density then reacts with currents in
windings placed in slots on the inner surface of the stator to produce torque.
Figure 2.3 shows the placement of the magnet.
Interior PM motors have interior mounted permanent magnet rotor as shown in figure 2.4.
Each permanent magnet is mounted inside the rotor. It is not as common as the surface mounted
type but it is a good candidate for high-speed operation. There is inductance variation for this
type of rotor because the permanent magnet part is equivalent to air in the magnetic circuit
calculation. These motors are considered to have saliency with q axis inductance greater than the
d axis inductance ( Lq > Ld )[8].
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 13/83
2.3 Position Sensor
Operation of permanent magnet synchronous motors requires position sensors in the rotor shaft
when operated without damper winding. The need of knowing the rotor position requires thedevelopment of devices for position measurement. There are four main devices for the
measurement of position, the potentiometer, linear variable differential transformer, optical
encoder and resolvers. The ones most commonly used for motors are encoders and revolvers.
Depending on the application and performance desired by the motor a position sensor with the
required accuracy can be selected
2.3.1 Optical Encoders
The most popular type of encoder is the optical encoder as shown in figure 2.5, which consists of
a rotating disk, a light source, and a photo detector (light sensor). The disk, is mounted on the
rotating shaft, has coded patterns of opaque and transparent sectors. As the disk rotates, these
patterns interrupt the light emitted onto the photo detector, generating a digital pulse or output
signal.
Optical encoders offer the advantages of digital interface. There are two types of
optical encoders, incremental encoder and absolute encoder.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 14/83
2.3.1.1 Incremental encoders
Incremental encoders have good precision and are simple to implement but they suffer from lack
of information when the motor is at rest position and in order for precise position the motor most
be stop at the starting point.
The most common type of incremental encoder uses two output channels (A and B) to sense
position. Using two code tracks with sectors positioned 90° degrees out of phase, the two output
channels of the quadrature encoder indicate both position and direction of rotation as shown in
figure 2.6. If A leads B, for example, the disk is rotating in a clockwise direction. If B leads A,
then the disk is rotating in a counter-clockwise direction. By monitoring both, the number of
pulses and the relative phase of signals A and B, it's possible to track position and direction of
rotation. Some quadrature encoders also include a third output channel, called a zero or index or
reference signal, which supplies a single pulse per revolution. This single pulse is used for
precise determination of a reference position. The precision of the encoder is fix by its code disk
but it can be increased by detecting the Up and Down transitions on both the A and B channels.
2.3.1.2 Absolute encoders
The absolute encoder, as shown in figure 2.7 captures the exact position of the rotor with a
precision directly related to the number of bits of the encoder. It can rotate indefinitely and even
if the motor stops the position can be measured or obtained.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 15/83
It provides a “whole word” output with a unique code pattern representing each position. This
code is derived from independent tracks on the encoder disc (one for each “bit” of resolution)
corresponding to individual photo detectors. The output from these detectors is
HI (light) or LO (dark) depending on the code disc pattern for that particular position.
Absolute encoders are used in applications where a device is inactive for long periods of time or
moves at a slow rate, such as flood gate control, telescopes, cranes, valves, etc. They are also
recommended in systems that must retain position information through a power outage.
2.3.2 Position Revolver
Position revolver as shown in figure 2.8, also called rotary transformers, works on the
transformer principle. The primary winding is placed on the rotor and depending upon the rotor
shaft angle the induced voltage at the two secondary windings of the transformer shifted by 90°
would be different. The position can be calculated using the two voltages. The resolver is
basically a rotary transformer with one rotating reference winding (Vref ) and two stator windings.
The reference winding is fixed on the rotor, and therefore, it rotates jointly with the shaft passing
the output windings, as is depicted in figure 2.8. Two stator windings are placed in quadrature
(shifted by 90°) with one another and generate the sine and cosine voltages (Vsin , Vcos)
respectively. Both windings will be further referred to as output windings. In consequence of the
excitement applied on the reference winding Vref and along with the angular movement of the
motor shaft θ, the respective voltages are generated by resolver output windings Vsin , Vcos.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 16/83
The frequency of the generated voltages is identical to the reference voltage and their amplitudes
vary according to the sine and cosine of the shaft angle θ. Considering that one of the output
windings is aligned with the reference winding, then it is generated full voltage on that output
winding and zero voltage on the other output winding and vice versa. The rotor angle θ can be
extracted from these voltages shown in figure 2.9.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 17/83
The shaft angle can be determined by an Inverse Tangent [8] function of the quotient of the
sampled resolver output voltages Vsin , Vcos . This determination can be expressed, in terms of
resolver output voltages, as follows:
2.4 Current Controlled Inverter
The motor is fed form a voltage source inverter with current control. The control is performed by
regulating the flow of current through the stator of the motor. Current controllers are used to
generate gate signals for the inverter. Proper selection of the inverter devices and selection of thecontrol technique will guarantee the efficacy of the drive.
2.4.1 Inverter
Voltage Source Inverters are devices that convert a DC voltage to AC voltage of variable
frequency and magnitude. They are very commonly used in adjustable speed drives and are
characterized by a well defined switched voltage wave form in the terminals [23]. Figure 2.10shows a voltage source inverter. The AC voltage frequency can be variable or constant
depending on the application.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 18/83
Three phase inverters consist of six power switches connected as shown in figure 2.10 to a DC
voltage source. The inverter switches must be carefully selected based on the requirements of
operation, ratings and the application. There are several devices available today and these are
thyristors, bipolar junction transistors (BJTs), MOS field effect transistors (MOSFETs), insulated
gate bipolar transistors (IGBTs) and gate turn off thyristors (GTOs). The devices list with their
respective power switching capabilities are shown in table 2.1 MOSFETs and IGBTs are
preferred by industry because of the MOS gating permits high power gain and control
advantages. While MOSFET is considered a universal power device for low power and low
voltage applications, IGBT has wide acceptance for motor drives and other application in the low
and medium power range. The power devices when used in motor drives applications require an
inductive motor current path provided by antiparallel diodes when the switch is turned off.
Inverters with antiparallel diodes are shown in figure 2.11.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 19/83
2.4.2 IGBTs
IGBTs provide high input impedance and are used for high voltage applications. The high input
impedance allows the device to switch with a small amount of energy and for high voltage
applications the device must have large blocking voltage ratings. The device behavior is
described by parameters like voltage drop or on-resistance, turn on time and turn off time. Figure
2.12 shows the characteristic plot of the device (International rectifier IGBT
(IRGIB10B60KD1) Appendix 1).
The symbolic representation and the equivalent circuit of an IGBT are shown infigure 2.13.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 20/83
2.4.3 Current Control
The power converter in a high-performance motor drive used in motion control essentially
functions as a power amplifier, reproducing the low power level control signals generated in thefield orientation controller at power levels appropriate for the driven machine. High-performance
drives utilize control strategies which develop command signals for the AC machine currents.
The basic reason for the selection of current as the controlled variable is the same as for the DC
machine; the stator dynamics (effects of stator resistance, stator inductance, and induced EMF)
are eliminated. Thus, to the extent that the current regulator functions as an ideal current supply,
the order of the system under control is reduced and the complexity of the controller can be
significantly simplified.
Current regulators for AC drives are complex because an AC current regulator must control both
the amplitude and phase of the stator current. The AC drive current regulator forms the inner
loop of the overall motion controller. As such, it must have the widest bandwidth in the system
and must, by necessity, have zero or nearly zero steady-state error. Both current source inverters
(CSI) and voltage source inverters (VSI) can be operated in controlled current modes. The
current source inverter is a "natural" current supply and can readily be adapted to controlled
current operation. The voltage source inverter requires more complexity in the current regulator
but offers much higher bandwidth and elimination of current harmonics as compared to the CSI
and is almost exclusively used for motion control applications.
Current controllers can be classified into two groups, hysteresis and PWM current controllers.
Both types are discussed bellow.
2.4.3.1 PWM Current Controller
PWM current controllers are widely used. The switching frequency is usually kept constant.
They are based in the principle of comparing a triangular carrier wave of desire switching
frequency and is compared with error of the controlled signal. The error signal comes from the
sum of the reference signal generated in the controller and the negative of the actual motor
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 21/83
current. The comparison will result in a voltage control signal that goes to the gates of the
voltage source inverter to generate the desire output. Its control will respond according to the
error. If the error command is greater than the triangle waveform, the inverter leg is held
switched to the positive polarity (upper switch on). When the error command is less than the
triangle waveform, the inverter leg is switched to the negative polarity (lower switch on). This
will generate a PWM signal like in figure 2.14. The inverter leg is forced to switch at the
frequency of the triangle wave and produces an output voltage proportional to the current error
command. The nature of the controlled output current consists of a reproduction of the reference
current with high-frequency PWM ripple superimposed[23].
2.4.3.2 Hysteresis current controller
Hysteresis current controller can also be implemented to control the inverter currents. The
controller will generate the reference currents with the inverter within a range which is fixed by
the width of the band gap. In this controller the desired current of a given phase is summed with
the negative of the measured current. The error is fed to a comparator having a hysteresis band.
When the error crosses the lower limit of the hysteresis band, the upper switch of the inverter leg
is turned on. But when the current attempts to become less than the upper reference band, the
bottom switch is turned on. Figure 2.15 shows the hysteresis band with the actual current and the
resulting gate signals. This controller does not have a specific switching frequency and changes
continuously but it is related with the band width [4] [23].
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 22/83
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 23/83
3 MODELING OF PM DRIVE SYSTEM
This chapter deals with the detailed modeling of a permanent magnet synchronous motor. Field
oriented control of the motor in constant torque and flux-weakening regions are discussed.
Closed loop control of the motor is developed using a PI controller in the speed loop. Design of
the speed controller is discussed.
3.1 Detailed Modeling of PMSM
Detailed modeling of PM motor drive system is required for proper simulation of the system.
The d-q model has been developed on rotor reference frame as shown in figure 3.1. At any time
t, the rotating rotor d-axis makes and angle θr with the fixed stator phase axis and rotating stator
mmf makes an angle α with the rotor d-axis. Stator mmf rotates at the same speed as that of the
rotor.
The model of PMSM without damper winding has been developed on rotor reference
frame using the following assumptions:
1) Saturation is neglected.
2) The induced EMF is sinusoidal.
3) Eddy currents and hysteresis losses are negligible.
4) There are no field current dynamics.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 24/83
Voltage equations are given by:
V q = Rsiq +ωr λd + ρλq 3.1
d sd r q d V = R i −ω λ + ρλ 3.2
Flux Linkages are given by
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 25/83
In the above equations ωr is the rotor electrical speed where as ωm is the rotor
mechanical speed.
3.1.1 Parks Transformation and Dynamic d q Modeling
The dynamic d q modeling is used for the study of motor during transient and steady state. It is
done by converting the three phase voltages an currents to dqo variables by using Parks
transformation[8].
Converting the phase voltages variables vabc to vdqo variables in rotor reference frame the
following equations are obtained
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 26/83
3.1.2 Equivalent Circuit of Permanent Magnet Synchronous Motor
Equivalent circuits of the motors are used for study and simulation of motors. From the d-q
modeling of the motor using the stator voltage equations the equivalent circuit of the motor can
be derived. Assuming rotor d axis flux from the permanent magnets is represented by a constant
current source as described in the following equationλ f = Ldmi f , figure 3.2 is
obtained.
3.2 PM Motor Control
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 27/83
Control of PM motors is performed using field oriented control for the operation of synchronous
motor as a dc motor. The stator windings of the motor are fed by an inverter that generates a
variable frequency variable voltage. Instead of controlling the inverter frequency independently,
the frequency and phase of the output wave are controlled using a position sensor as shown in
figure 3.3.
Field oriented control was invented in the beginning of 1970s and it demonstrates that an
induction motor or synchronous motor could be controlled like a separately excited dc motor by
the orientation of the stator mmf or current vector in relation to the rotor flux to achieve a desired
objective. In order for the motor to behave like DC motor, the control needs knowledge of the
position of the instantaneous rotor flux or rotor position of permanent magnet motor. This needs
a resolver or an absolute optical encoder. Knowing the position, the three phase currents can be
calculated. Its calculation using the current matrix depends on the control desired. Some control
options are constant torque and flux weakening. These options are based in the physical
limitation of the motor and the inverter. The limit is established by the rated speed of the motor,
at which speed the constant torque operation finishes and the flux weakening starts as shown in
figure 3.4.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 28/83
3.2.1 Field Oriented Control of PM Motors
The PMSM control is equivalent to that of the dc motor by a decoupling control known as field
oriented control or vector control. The vector control separates the torque component of current
and flux channels in the motor through its stator excitation. The vector control of the PM
synchronous motor is derived from its dynamic model. Considering the currents as inputs, the
three currents are:
Writing equations 3.14 to 3.16 in the matrix form:
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 29/83
Where α is the angle between the rotor field and stator current phasor, r ω is the electrical rotor
speed.
The previous currents obtained are the stator currents that must be transformed to the rotor
reference frame with the rotor speed r ω , using Park’s transformation. The q and d axis currents
are constants in the rotor reference frames since α is a constant for a given load torque. As these
constants, they are similar to the armature and field currents in the separately excited dc
machine. The q axis current is distinctly equivalent to the armature current of the dc machine; the
d axis current is field current, but not in its entirety. It is only a partial field current; the other part
is contributed by the equivalent current source representing the permanent magnet field. For this
reason the q axis current is called the torque producing component of the stator current and the d
axis current is called the flux producing component of the stator current.Substituting equation 3.17 and 3.12 is obtain id and iq in terms of Im as follows
Using equations 3.1, 3.2, 3.8 and 3.18 the electromagnetic torque equation is obtained
as given below.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 30/83
3.2.1.1 Constant torque operation
Constant torque control strategy is derived from field oriented control, where the maximum
possible torque is desired at all times like the dc motor. This is performed by making the torque
producing current iq equal to the supply current Im. That results in selecting the α angle to be 90 º
degrees according to equation 3.18. By making the id current equal to zero the torque equation
can be rewritten as:
Like the dc motor, the torque is dependent of the motor current.
3.2.1.2 Flux-weakening
Flux weakening is the process of reducing the flux in the d axis direction of the motor which
results in an increased speed range. The motor drive is operated with rated flux linkages up to a
speed where the ratio between the induced emf and stator frequency (V/f) is maintained constant.
After the base frequency, the V/f ratio is reduced due to the limit of the inverter dc voltage
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 31/83
source which is fixed. The weakening of the field flux is required for operation above the base
frequency.
This reduces the V/f ratio. This operation results in a reduction of the torque proportional to a
change in the frequency and the motor operates in the constant power region[22]. The rotor flux
of PMSM is generated by permanent magnet which can not be directly reduced as induction
motor. The principle of flux-weakening control of PMSM is to increase negative direct axis
current and use armature reaction to reduce air gap flux, which equivalently reduces flux and
achieves the purpose of flux-weakening control[28]. This method changes torque by altering the
angle between the stator MMF and the rotor d axis. In the flux weakening region where ωr >
ωrated angle α is controlled by proper control of id and iq for the same value of stator current. Since
iq is reduced the output torque is also reduced. The angle α can be obtained as:
Flux-weakening control realization
The realization process of equivalent flux-weakening control is as follows,
1) Measuring rotor position and speed ωr from a sensor which is set in motor rotation axis.
2) The motor at the flux weakening region with a speed loop, Te* is obtained from the PI
controller.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 32/83
3.3 Speed Control of PM Motor
Many applications, such as robotics and factory automation, require precise control of speed and
position. Speed Control Systems allow one to easily set and adjust the speed of a motor. The
control system consists of a speed feedback system, a motor, an inverter, a controller and a speed
setting device. A properly designed feedback controller makes the system insensible to
disturbance and changes of the parameters.
The purpose of a motor speed controller is to take a signal representing the demanded\ speed,and to drive a motor at that speed. Closed Loop speed control systems have fast response, but
become expensive due to the need of feed back components such as speed sensors.
3.3.1 Implementation of the Speed Control Loop
For a PM motor drive system with a full speed range the system will consist of a motor, an
inverter, a controller (constant torque and flux weakening operation, generation of reference
currents and PI controller ) as shown in figure 3.5.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 33/83
The operation of the controller must be according to the speed range. For operation up to rated
speed it will operate in constant torque region and for speeds above rated speed it will operate in
flux-weakening region. In this region the d-axis flux and the developed torque are reduced. The
process can be easily understood with the flow diagram in figure 3.6.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 34/83
Speed controller calculates the difference between the reference speed and the actual speed
producing an error, which is fed to the PI controller. PI controllers are used widely for motion
control systems. They consist of a proportional gain that produces an output proportional to the
input error and an integration to make the steady state error zero for a step change in the input.Block diagram of the PI controller is shown in figure 3.7.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 35/83
Speed control of motors mainly consist of two loops the inner loop for current and the outer loop
for speed. The order of the loops is due to their response, how fast they can be changed. This
requires a current loop at least 10 times faster than the speed loop. Since the PMSM is operated
using field oriented control, it can be modeled like a dc motor. The design begins with the
innermost current loop by drawing the block diagram. But in PMSM drive system the motor has
current controllers which make the current loop. The current control is performed by the
comparison of the reference currents with the actual motor currents.
The design of the speed loop assumes that the current loop is at least 10 times faster than speed
loop, allowing to reduce the system block diagram by considering the current loop to be of unity
gain as shown in figure 3.8.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 36/83
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 37/83
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 38/83
Chapter-4
MATLAB SIMULINK INTRODUCTION
Introduction to MATLABWhat is MATLAB?
MATLAB (short for MATrix LABoratory) is a special-purpose computer program optimized
to perform engineering and scientific calculations. It is a high-performance language for
technical computing. It integrates computation, visualization, and programming in an easy-to-use
environment where problems and solutions are expressed in familiar mathematical notation.
Typical uses include:
Math and computation
Algorithm development
Modelling, simulation and prototyping
Data analysis, exploration and visualization
Scientific and engineering graphics
Application development, including Graphical User Interface (GUI) building
MATLAB is an interactive system whose basic data element is an array that does not require
dimensioning. This allows you to solve many technical computing problems, especially those
with matrix and vector formulations, in a fraction of the time it would take to write a program in
a scalar non-interactive language such as C, C++ or Fortran.
MATLAB has evolved over a period of years with input from many users. In university
environments, it is the standard instructional tool for introductory and advanced courses in
mathematics, engineering and science. In industry, MATLAB is the tool of choice for high-
productivity research, development and analysis.
MATLAB features a family of application-specific solution called Toolboxes. Very important to
most users of MATLAB, toolboxes allow you to learn and apply specialized technology.
Toolboxes are comprehensive collections of MATLAB function (m-files) that extend the
MATLAB environment to solve particular classes of problems. Areas in which toolboxes are
available include signal processing, control systems, neural networks, fuzzy logic, wavelets,
image processing, simulation and many others.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 39/83
MATLAB System
The MATLAB system consists of five main parts:
1. The MATLAB language. This is a high-level matrix/array language with control flow
statements, functions, data structures, input/output, and object-oriented programming
features. It allows both “programming in the small” to rapidly create quick and dirty
throw-away programs, and “programming in the large” to create complete large and
complex application programs.
2. The MATLAB working environment. This is the set of tools and facilities that you work
with as the MATLAB user or programmer. It includes facilities for managing the
variables in your workspace and importing and exporting data. It also includes tools for
developing, managing, debugging, and profiling M-files, MATLAB’s applications.
3. Handle Graphics. This is the MATLAB graphics system. It includes high-level
commands for two-dimensional and three-dimensional data visualization, image
processing, animation, and presentation graphics. It also includes low-level commands
that allow you to fully customize the appearance of graphics as well as to build complete
Graphical User Interfaces on your MATLAB applications.
4. The MATLAB mathematical function library. This is a vast collection of computational
algorithms ranging from elementary functions like sum, sine, cosine, and complex
arithmetic, to more sophisticated functions like matrix inverse, matrix eigenvalues,
Bessel functions, and fast Fourier transforms.
5. The MATLAB Application Program Interface (API). This is a library that allows you
to write C and Fortran programs that interact with MATLAB. It include facilities for
calling routines from MATLAB (dynamic linking), calling MATLAB as a computational
engine, and for reading and writing MAT-files.
The Advantages of MATLAB
MATLAB has many advantages compared to conventional computer languages for technical
problem solving. Among them are:
1. Ease of Use. MATLAB is an interpreted language. Program may be easily written and
modified with the built-in integrated development environment and debugged with the
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 40/83
MATLAB debugger. Because the language is so easy to use, it is ideal for the rapid
prototyping of new programs.
2. Platform Independence. MATLAB is supported on many different computer systems,
providing a large measure of platform independence. At the time of this writing, the
language is supported on Windows NT/2000/XP, Linux, several versions of UNIX and
the Macintosh.
3. Predefined Function. MATLAB comes complete with an extensive library of predefined
functions that provide tested and pre-packaged solutions to many basic technical tasks.
For examples, the arithmetic mean, standard deviation, median, etc. these and hundreds
of other functions are built right into the MATLAB language, making your job much
easier. In addition to the large library of function built into the basic MATLAB language,
there are many special-purpose toolboxes available to help solve complex problems in
specific areas. There is also an extensive collection of free user-contributed MATLAB
programs that are shared through the MATLAB Web site.
4. Device-Independent Plotting. Unlike most other computer languages, MATLAB has
many integral plotting and imaging commands. The plots and images can be displayed on
any graphical output device supported by the computer on which MATLAB is running.
5. Graphical User Interface. MATLAB includes tools that allow a programmer to
interactively construct a graphical user interface, (GUI) for his or her program. With this
capability, the programmer can design sophisticated data-analysis programs that can be
operated by relatively inexperienced users.
6. MATLAB Compiler. MATLAB’s flexibility and platform independence is achieved by
compiling MATLAB programs into a device-independent p-code, and then interpreting
the p-code instructions at runtime. Unfortunately, the resulting programs can sometimes
execute slowly because the MATLAB code is interpreted rather than compiled.
Disadvantages of MATLAB
MATLAB has two principal disadvantages. The first is that it is an interpreted language and
therefore can execute more slowly than compiled languages. This problem can be mitigated by
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 41/83
properly structuring the MATLAB program, and by the use of the MATLAB compiler to
compile the final MATLAB program before distribution and general use.
The second disadvantage is cost: a full copy of MATLAB is five to ten times more expensive
than a conventional C or Fortran compiler. This relatively high cost is more than offset by then
reduced time required for an engineer or scientist to create a working program, so MATLAB is
cost-effective for businesses. However, it is too expensive for most individuals to consider
purchasing. Fortunately, there is also an inexpensive Student Edition of MATLAB, which is a
great tool for students wishing to learn the language. The Student Edition of MATLAB is
essentially identical to the full edition.
Getting Started
Starting MATLAB
You can start MATLAB by double-clicking on the MATLAB icon or invoking the application
from the Start menu of Windows. The main MATLAB window, called the MATLAB Desktop,
will then pop-up and it will look like this:
Figure 2.1: The Default MATLAB desktop
When MATLAB executes, it can display several types of windows that accept commands or
display information. It integrates many tools for managing files, variables and applications
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 42/83
within the MATLAB environment. The major tools within or accessible from the MATLAB
desktop are:
1. The Current Directory Browser
2. The Workspace Window
3. The Command Window
4. The Command History Window
5. The Start Button
6. The Help Window
If desired, this arrangement can be modified by selecting an alternate choice from [View]
[Desktop Layout]. By default, most MATLAB tools are “docked” to the desktop, so that they
appear inside the desktop window. However, you can choose to “undock” any or all tools,
making them appear in windows separate from the desktop.
The Command Window
The Command Window is where the command line prompt for interactive commands is
located. Once started, you will notice that inside the MATLAB command window is the
text:
Click in the command window to make it active. When a window becomes active, its titlebar
darkens. The “>>” is called the Command Prompt, and there will be a blinking cursor right after
it waiting for you to type something. You can enter interactive commands at the command
prompt (>>) and they will be executed on the spot.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 43/83
As an example, let’s enter a simple MATLAB command, which is the date command. Click
the mouse where the blinking cursor is and then type date and press the ENTER key.
MATLAB should then return something like this:
Where the current date should be returned to you instead of 01-Sep-2006. Congratulation! You
have just successfully executed your first MATLAB command!
The Command History Window
Figure 2.3: The Command History Window
The Command History Window, contains a log of commands that have been executed within
the command window. This is a convenient feature for tracking when developing or debugging
programs or to confirm that commands were executed in a particular sequence during a multi-
step calculation from the command line.
The Current Directory Browser
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 44/83
Figure 2.4: The Directory Browser
The Current Directory Browser displays a current directory with a listing of its contents. There
is navigation capability for resetting the current directory to any directory among those set in the
path. This window is useful for finding the location of particular files and scripts so that they can
be edited, moved, renamed or deleted. The default directory is the Work subdirectory of the
original MATLAB installation directory.
The Workspace Window
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 45/83
Figure 2.5: The Workspace Window
The Workspace Window provides an inventory of all the items in the workspace that are
currently defined, either by assignment or calculation in the Command Window or by importing
with a load or similar command from the MATLAB command line prompt. These items consist
of the set of arrays whose elements are variables or constants and which have been constructed
or loaded during the current MATLAB session and have remained stored in memory. Those
which have been cleared and no longer are in memory will not be included. The Workspace
Window shows the name of each variable, its value, its array size, its size in bytes, and the class.
Values of a variable or constant can be edited in an Array Editor which is launched by double
clicking its icon in the Workspace Window.
The Help Window
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 46/83
Figure 2.6: The Help Window
You can access the online help in one of several ways. Typing help at the command prompt will
reveal a long list of topics on which help is available. Just to illustrate, try typing help general.
Now you see a long list of “general purpose” MATLAB commands. In addition, you can also get
help on the certain command. For example, date command. The output of help also refers to
other functions that are related. In this example the help also tells you, See also NOW, CLOCK,
DATENUM. You can now get help on these functions using the three different commands as
well.
There is a much more user-friendly way to access the online help, namely via the MATLAB
Help Browser. Separate from the main desktop layout is a Help desktop with its own layout.
This utility can be launched by selecting [Help] [MATLAB Help] from the Help pull down
menu. This Help desktop has a right side which contains links to help with functions, help with
graphics, and tutorial type documentation.
The Start Button
The Start Button (see figure 2.1) allows a user to access MATLAB tools, desktop tools, help
files, etc. it works just like the Start button on a Windows desktop. To start a particular tool, just
click on the Start Button and select the tool from the appropriate sub-menu.
Interrupting Calculations
If MATLAB is hung up in a calculation, or is just taking too long to perform an operation,
you can usually abort it by typing [CTRL + C] (that is, hold down the key labeled CTRL, and
press C).
Ending a Session
One final note, when you are all done with your MATLAB session you need to exit MATLAB.
To exit MATLAB, simply type quit or exit at the prompt. You can also click on the special
symbol that closes your windows (usually an × in the upper right-hand corner). Another way to
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 47/83
exit is by selecting [File] [Exit MATLAB]. Before you exit MATLAB, you should be sure to
save any variables, print any graphics or other files you need, and in general clean up after
yourself.
MATLAB Basics
Variables and Arrays
The fundamental unit of data in any MATLAB program is the array. An array is a collection
of data values organized into rows and columns and known by a single name. Individual data
values within an array are accessed by including the name of the array followed by subscripts in
parentheses that identify the row and column of the particular value. Even scalars are treated as
arrays by MATLAB – they are simply arrays with only one row and one column. There are three
fundamental concepts in MATLAB, and in linear algebra, are scalars, vectors and matrices.
1. A scalar is simply just a fancy word for a number (a single value).
2. A vector is an ordered list of numbers (one-dimensional). In MATLAB they can be
represented as a row-vector or a column-vector.
3. A matrix is a rectangular array of numbers (multi-dimensional). In MATLAB, a two-
dimensional matrix is defined by its number of rows and columns.
In MATLAB matricies are defined inside a pair of square braces ([]). Punctuation marks of a
comma (,), and semicolon (;) are used as a row separator and column separator, respectfully.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 48/83
You can also use a space as a row separator, and a carriage return (the ENTER key) as a column
separator as well.
Examples 3.1
Below are examples of how a scalar, vector and matrix can be created in MATLAB.
Indexing into an Array
Once a vector or a matrix is created you might needed to extract only a subset of the data, and
this is done through indexing.
Figure 3.1: An array is a collection of data values organized into rows and columns
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 49/83
Individual elements in an array are addressed by the array name followed by the row and
column of the particular element. If the array is a row or column vector, then only one subscript
is required. For example, according to the example 3.1:
o my_vector2(2) is 5
o my_matrix(3,2) is 4 or my_matrix(7) is 4
The Colon Operator
The colon (:) is one of MATLAB’s most important operators. It occurs in several different
forms.
Examples 3.2
1. To create an incremental or a decrement vector
∗ NOTES: If the colon is used by itself within subscript, it refers to all the elements in a row or
column of a matrix!
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 50/83
Concatenating Matrices
Matrix concatenation is the process of joining one or more matrices to make a new matrix. The
expression C = [A B] horizontally concatenates matrices A and B. The expression C = [A; B]
vertically concatenates them.
Examples 3.3
Reshaping a Matrix
Here are a few examples to illustrate some of the ways you can reshape matrices.
Examples 3.4
Reshape 3-by-4 matrix A to have dimensions 2-by-6.
Examples 3.5
Transpose A so that the row elements become columns or vice versa. You can use either the
transpose function or the transpose operator (’). To do this:
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 51/83
General Function for Matrix and Vector
There are many MATLAB features which cannot be included in these introductory notes.
Listed below are some of the MATLAB functions regard to matrix and vector.
Basic Vector Function
MATLAB includes a number of built-in functions that you can use to determine a number of
characteristics of a vector. The following are the most commonly used such functions.
Examples 3.6
The following example demonstrates the use some of these functions.
Functions to Create a Matrix
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 52/83
This following section summarizes the principal functions used in creating and handling
matrices. Most of these functions work on multi-dimensional arrays as well.
Examples 3.7
The following example demonstrates the use some of these functions.
Arithmetic Operations
MATLAB can be used to evaluate simple and complex mathematical expressions. When we
move from scalars to vectors (and matrices), some confusion arises when performing arithmetic
operations because we can perform some operations either on an element-by-element (array
operation) or matrices as whole entities (matrix operation). Expressions use familiar arithmetic
operators:
Array Operators
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 53/83
Examples 3.8
The following example demonstrates the use some of these operations.
Matrix Operators
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 54/83
Examples 3.9
Built-in Variables
MATLAB uses a small number of names for built-in variables. An example is the ans variable,
which is automatically created whenever a mathematical expression is not assigned to another
variable. Table below lists the built-in variables and their meanings. Although you can reassign
the values of these built-in variables, it is not a good idea to do so, because they are used by the
built-in functions.
Examples 3.10
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 55/83
Common MATLAB Functions
A few of the most common and useful MATLAB functions are shown in table below. These
functions will be used in many times. It really helps you when one needs to manage variables
and workspace and to perform an elementary mathematical operation.
Managing Variables and Workspace
Examples 3.11
Built-in Function of Elementary Math
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 56/83
Examples 3.12
Plotting and Visualization
Plotting in MATLAB
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 57/83
MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as
annotating and printing these graphs. This section describes a few of the most important graphics
functions and provides examples of some typical applications.
Creating a Plot
The plot function has different forms, depending on the input arguments. If y is a vector,
plot(y) produces a piecewise linear graph of the elements of y versus the index of the elements of
y. If you specify two vectors as arguments, plot(x,y) produces a graph of y versus x.
For example, to plot the value of the sine function from zero to 2π, use:
This is the basic command of plotting a graph. Besides that, MATLAB has commands which
will let you add titles and labels and others in order to make your figures more readable.
However, you need to keep the figure window open while executing these commands.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 58/83
The current limits of this plot can be determined from the basic axis function. So, in order to
modify the x-axis within [0 2π], you need to run this function:
Annotating Plots
You can adjust the axis tick-mark locations and the labels appearing at each tick mark. For
example, this plot of the sine function relabels the x-axis with more meaningful values.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 59/83
Creating a Semilogarithmic Plot
Semilogarithmic plot is another type of figuring a graph by rescaling if the new data falls outside
the range of the previous axis limits.
Specifying the Color and Size of Lines
You can control a number of line style characteristics by specifying values for line properties.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 60/83
Multiple Plots
Often, it is desirable to place more than one plot in a single figure window. This is achieved
by three ways:
The subplot Function
The subplot Function breaks the figure window into an m-by-n matrix of small subplots and
selects the ith subplot for the current plot. The plots are numbered along the top row of the figure
window, then the second row, and so forth.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 61/83
Multiple plots
You can assign different line styles to each data set by passing line style identifier strings to plotand placing a legend on the plot to identify curves drawn with different symbol and line types.
The hold Function
The hold command will add new plots on top of previously existing plots.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 62/83
Line Plots in Three-Dimensions
Now, the three-dimension analog of the plot function is plot3. if x, y and z are three vectors of the
same length, plot3(x,y,z) generates a line in 3-D through the points whose coordinates are the
elements of x, y and z and then produces a 2-D projection of that line on the screen.
Three-Dimensional Surface Mesh Plots
The first step in displaying a function of two variables, z = f(x,y), is to generate X and Y matrices
consisting of repeated rows and columns, respectively, over the domain of the function. Then use
these matrices to evaluate and graph the function. Meshgrid function transforms the domain
specified by two-vectors, x and y, into matrices X and Y .
Programming
Data Types
There are many different types of data that you can work with in MATLAB. You can build
matrices and arrays of floating point and integer data, characters and strings, logical true and
false states, etc. you can also develop your own data types using MATLAB classes. Two of the
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 63/83
MATLAB data types, structures and cell arrays, provide a way to store dissimilar types of data in
the same array.
There are 15 fundamental data types (or classes) in MATLAB. Each of these data types is in the
form of an array. This array is a minimum of 0-by-0 in size and can grow to an n-dimensional
array of any size. Two-dimensional versions of these arrays are called matrices. All of the
fundamental data types are shown in lowercase text in the diagram below. Additional data types
are user-defined, object-oriented user classes (a subclass of structure), and java classes, that you
can use with the MATLAB interface to Java. Matrices of type double and logical may be either
full or sparse. For matrices having a small number of nonzero elements, a sparse matrix requires
a fraction of the storage space required for an equivalent full matrix. Sparse matrices invoke
special methods especially tailored to solve sparse problems.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 64/83
M-File Programming
MATLAB provides a full programming language that enables you to write a series of MATLAB
statements into a file and then execute them with a single command. You write your program in
an ordinary text file, giving the file a name of filename.m. The term you use for filename
becomes the new command that MATLAB associates with the program. The file extension of .m
makes this a MATLAB M-file. M-files can be scripts that simply execute a series of MATLAB
statements, or they can be functions that also accept arguments and produce output. You create
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 65/83
M-files using a text editor, then use them as you would any other MATLAB function or
command. The process looks like this:
Kinds of M-files
There are two kinds of M-files
Functions
Functions are M-files that accept input arguments and return output arguments. They operate on
variables within their own workspace. This is separate from the workspace you access at the
MATLAB command prompt
Example 5.2
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 66/83
If you would like, try entering these commands in an M-file called average.m. The average
function accepts a single input argument and returns a single output argument. To call the
average function, enter
The Function Definition Line
The function definition line informs MATLAB that the M-file contains a function, and specifies
the argument calling sequence of the function. The function definition line for the average
function is
All MATLAB functions have a function definition line that follows this pattern.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 67/83
The Function Name - MATLAB function names have the same constraints as variable names.
The name must begin with a letter, which may be followed by any combination of letters, digits,
and underscores. Making all letters in the name lowercase is recommended as it makes your M-
files portable between platforms.
Flow Control
MATLAB has several flow control constructs:
1. if
2. continue
3. break
4. switch and case
5. for
6. while
If
The if statement evaluates a logical expression and executes a group of statements when the
expression is true. The optional elseif and else keywords provide for the execution of alternate
groups of statements. An end keyword, which matches the if, terminates the last group of
statements. The groups of statements are delineated by the four keywords--no braces or brackets
are involved
Continue
The continue statement passes control to the next iteration of the for or while loop in which it
appears, skipping any remaining statements in the body of the loop. In nested loops, continue
passes control to the next iteration of the for or while loop enclosing it.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 68/83
Break
The break statement lets you exit early from a for or while loop. In nested loops, break exits from
the innermost loop only.
Switch and Case
The switch statement executes groups of statements based on the value of a variable or
expression. The keywords case and otherwise delineate the groups. Only the first matching case
is executed. There must always be an end to match the switch.
For
The for loop repeats a group of statements a fixed, predetermined number of times. A matching
end delineates the statements.
While
The while loop repeats a group of statements an indefinite number of times under control of alogical condition. A matching end delineates the statements.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 69/83
SIMULINK
Simulink is a graphical extension to MATLAB for the modeling and simulation of
systems. In Simulink, systems are drawn on screen as block diagrams. Many elements of block
diagrams are available (such as transfer functions, summing junctions, etc.), as well as virtual
input devices (such as function generators) and output devices (such as oscilloscopes). Simulink
is integrated with MATLAB and data can be easily transferred between the programs. In this
tutorial, we will introduce the basics of using Simulink to model and simulate a system.
Simulink is supported on Unix, Macintosh, and Windows environments, and it is
included in the student version of MATLAB for personal computers. For more information on
Simulink, contact the MathWorks.
The idea behind these tutorials is that you can view them in one window while running Simulink
in another window. Do not confuse the windows, icons, and menus in the tutorials for your
actual Simulink windows. Most images in these tutorials are not live - they simply display what
you should see in your own Simulink windows. All Simulink operations should be done in your
Simulink windows.
STARTING SIMULINK
Simulink is started from the MATLAB command prompt by entering the following command:
simulink
Alternatively, you can click on the "Simulink Library Browser" button at the top of the
MATLAB
command window as shown below:
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 70/83
The Simulink Library Browser window should now appear on the screen. Most of the blocks
needed for modeling basic systems can be found in the subfolders of the main "Simulink" folder
(opened by clicking on the "+" in front of "Simulink"). Once the "Simulink" folder has been
opened, the Library Browser window should look like:
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 71/83
Basic Elements
There are two major classes of elements in Simulink: blocks and lines. Blocks are used to
generate, modify, combine, output, and display signals. Lines are used to transfer signals from
one block to another.
Blocks
The subfolders underneath the "Simulink" folder indicate the general classes of blocks available
for us to use:
· Continuous: Linear, continuous-time system elements (integrators, transfer functions,
state-space models, etc.)
· Discrete: Linear, discrete-time system elements (integrators, transfer functions, statespace
models, etc.)
· Functions & Tables: User-defined functions and tables for interpolating function values
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 72/83
· Math: Mathematical operators (sum, gain, dot product, etc.)
· Nonlinear: Nonlinear operators (coulomb/viscous friction, switches, relays, etc.)
· Signals & Systems: Blocks for controlling/monitoring signal(s) and for creating
subsystems
· Sinks: Used to output or display signals (displays, scopes, graphs, etc.)
· Sources: Used to generate various signals (step, ramp, sinusoidal, etc.)
Blocks have zero to several input terminals and zero to several output terminals. Unused input
terminals are indicated by a small open triangle. Unused output terminals are indicated by a
small triangular point. The block shown below has an unused input terminal on the left and an
unused output terminal on the right.
Lines
Lines transmit signals in the direction indicated by the arrow. Lines must always transmit signals
from the output terminal of one block to the input terminal of another block. One exception to
this is that a line can tap off of another line. This sends the original signal to each of two (or
more) destination blocks, as shown below:
Lines can never inject a signal into another line; lines must be combined through the use of a
block such as a summing junction.
A signal can be either a scalar signal or a vector signal. For Single-Input, Single-Output systems,
scalar signals are generally used. For Multi-Input, Multi-Output systems, vector signals are often
used, consisting of two or more scalar signals. The lines used to transmit scalar and vector
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 73/83
signals are identical. The type of signal carried by a line is determined by the blocks on either
end of the line.
Building a System
To demonstrate how a system is represented using Simulink, we will build the block diagram for
a simple model consisting of a sinusoidal input multiplied by a constant gain, which is shown
below:
This model will consist of three blocks: Sine Wave, Gain, and Scope. The Sine Wave is a Source
Block from which a sinusoidal input signal originates. This signal is transferred through a line in
the direction indicated by the arrow to the Gain Math Block. The Gain block modifies its input
signal (multiplies it by a constant value) and outputs a new signal through a line to the Scope
block. The Scope is a Sink Block used to display a signal (much like an oscilloscope). We begin
building our system by bringing up a new model window in which to create the block diagram.
This is done by clicking on the "New Model" button in the toolbar of the Simulink Library
Browser (looks like a blank page).
Building the system model is then accomplished through a series of steps:
1. The necessary blocks are gathered from the Library Browser and placed in the model
window.
2. The parameters of the blocks are then modified to correspond with the system we are
modelling.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 74/83
3. Finally, the blocks are connected with lines to complete the model.
Each of these steps will be explained in detail using our example system. Once a system is built,
simulations are run to analyze its behavior.
Gathering Blocks
Each of the blocks we will use in our example model will be taken from the Simulink Library
Browser. To place the Sine Wave block into the model window, follow these steps:
1. Click on the "+" in front of "Sources" (this is a subfolder beneath the "Simulink" folder) to
display the various source blocks available for us to use.
2. Scroll down until you see the "Sine Wave" block. Clicking on this will display a short
explanation of what that block does in the space below the folder list:
3. To insert a Sine Wave block into your model window, click on it in the Library Browser
and drag the block into your workspace.
The same method can be used to place the Gain and Scope blocks in the model window. The
"Gain" block can be found in the "Math" subfolder and the "Scope" block is located in the "Sink"
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 75/83
subfolder. Arrange the three blocks in the workspace (done by selecting and dragging an
individual block to a new location) so that they look similar to the following:
Modifying the Blocks
Simulink allows us to modify the blocks in our model so that they accurately reflect the
characteristics of the system we are analyzing. For example, we can modify the Sine Wave block
by double-clicking on it. Doing so will cause the following window to appear:
This window allows us to adjust the amplitude, frequency, and phase shift of the sinusoidal
input. The "Sample time" value indicates the time interval between successive readings of the
signal. Setting this value to 0 indicates the signal is sampled continuously.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 76/83
Let us assume that our system's sinusoidal input has:
· Amplitude = 2
· Frequency = pi
· Phase = pi/2
Enter these values into the appropriate fields (leave the "Sample time" set to 0) and click "OK" to
accept them and exit the window. Note that the frequency and phase for our system contain 'pi'
(3.1415...). These values can be entered into Simulink just as they have been shown. Next, we
modify the Gain block by double-clicking on it in the model window. The following window
will then appear:
Note that Simulink gives a brief explanation of the block's function in the top portion of this
window. In the case of the Gain block, the signal input to the block (u) is multiplied by a
constant (k) to create the block's output signal (y). Changing the "Gain" parameter in this
window changes the value of k.
For our system, we will let k = 5. Enter this value in the "Gain" field, and click "OK" to close
the window.
The Scope block simply plots its input signal as a function of time, and thus there are no system
parameters that we can change for it. We will look at the Scope block in more detail after we
have run our simulation.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 77/83
Connecting the Blocks
For a block diagram to accurately reflect the system we are modeling, the Simulink blocks must
be properly connected. In our example system, the signal output by the Sine Wave block is
transmitted to the Gain block. The Gain block amplifies this signal and outputs its new value to
the Scope block, which graphs the signal as a function of time. Thus, we need to draw lines from
the output of the Sine Wave block to the input of the Gain block, and from the output of the Gain
block to the input of the Scope block.
Lines are drawn by dragging the mouse from where a signal starts (output terminal of a
block) to where it ends (input terminal of another block). When drawing lines, it is important to
make sure that the signal reaches each of its intended terminals. Simulink will turn the mouse
pointer into a crosshair when it is close enough to an output terminal to begin drawing a line, and
the pointer will change into a double crosshair when it is close enough to snap to an input
terminal. A signal is properly connected if its arrowhead is filled in. If the arrowhead is open, it
means the signal is not connected to both blocks. To fix an open signal, you can treat the open
arrowhead as an output terminal and continue drawing the line to an input terminal in the same
manner as explained below
Properly Connected Signal Open Signal
When drawing lines, you do not need to worry about the path you follow. The lines will route
themselves automatically. Once blocks are connected, they can be repositioned for a neater
appearance. This is done by clicking on and dragging each block to its desired location (signals
will stay properly connected and will re-route themselves).
After drawing in the lines and repositioning the blocks, the example system model should look
like:
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 78/83
In some models, it will be necessary to branch a signal so that it is transmitted to two or more
different input terminals. This is done by first placing the mouse cursor at the location where the
signal is to branch. Then, using either the CTRL key in conjunction with the left mouse buttonor just the right mouse button, drag the new line to its intended destination. This method was
used to construct the branch in the Sine Wave output signal shown below:
The routing of lines and the location of branches can be changed by dragging them to their
desired new position. To delete an incorrectly drawn line, simply click on it to select it, and hit
the DELETE key.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 79/83
Running Simulations
Now that our model has been constructed, we are ready to simulate the system. To do this, go to
the Simulation menu and click on Start, or just click on the "Start/Pause Simulation" button in
the model window toolbar (looks like the "Play" button on a VCR). Because our example is a
relatively simple model, its simulation runs almost instantaneously. With more complicated
systems, however, you will be able to see the progress of the simulation by observing its running
time in the the lower box of the model window. Double-click the Scope block to view the output
of the Gain block for the simulation as a function of time. Once the Scope window appears, click
the "Autoscale" button in its toolbar (looks like a pair of binoculars) to scale the graph to better
fit the window. Having done this, you should see the following:
Note that the output of our system appears as a cosine curve with a period of 2 seconds and
amplitude equal to 10. Does this result agree with the system parameters we set? Its amplitude
makes sense when we consider that the amplitude of the input signal was 2 and the constant gain
of the system was 5 (2 x 5 = 10). The output's period should be the same as that of the input
signal, and this value is a function of the frequency we entered for the Sine Wave block (which
was set equal to pi). Finally, the output's shape as a cosine curve is due to the phase value of pi/2we set for the input (sine and cosine graphs differ by a phase shift of pi/2).
What if we were to modify the gain of the system to be 0.5? How would this affect the output of
the Gain block as observed by the Scope? Make this change by double-clicking on the Gain
block and changing the gain value to 0.5. Then, re-run the simulation and view the Scope (the
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 80/83
Scope graph will not change unless the simulation is re-run, even though the gain value has been
modified). The Scope graph should now look like the following:
Note that the only difference between this output and the one from our original system is the
amplitude of the cosine curve. In the second case, the amplitude is equal to 1, or 1/10th of 10,
which is a result of the gain value being 1/10th as large as it originally was.
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 81/83
CHAPTER-5
SIMULATION RESULTS
SIMULINK BLOCK DIAGRAM OF PERMANENT MAGNET SYNCHRONOUS MACHINE
8/3/2019 Modeling and Simulation of Permanent
http://slidepdf.com/reader/full/modeling-and-simulation-of-permanent 82/83
SPEED CONTROL OF PMSM