harmonic models of common converter topologies for accurate harmonic analysis of distribution

246
Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution Systems by Philippe A. Gray A thesis submitted in conformity with the requirements for the degree of Master’s of Applied Science Graduate Department of Electrical and Computer Engineering University of Toronto Copyright 2013 by Philippe A. Gray

Upload: others

Post on 11-Feb-2022

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Harmonic Models of Common Converter Topologies for

Accurate Harmonic Analysis of Distribution Systems

by

Philippe A. Gray

A thesis submitted in conformity with the requirementsfor the degree of Master’s of Applied Science

Graduate Department of Electrical and Computer Engineering

University of Toronto

Copyright© 2013 by Philippe A. Gray

Page 2: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Abstract

Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of

Distribution Systems

Philippe A. Gray

Master’s of Applied Science

Graduate Department of Electrical and Computer Engineering

University of Toronto

2013

Harmonic distortion in a power system can excite non-characteristic harmonics from

converter interfaced loads and generators which can then propagate back into the sys-

tem, exciting other harmonics in the system. In this thesis, a harmonic analysis tool is

presented that is designed to perform high accuracy, computationally efficient, steady-

state harmonic analysis of distribution systems when multiple converter interfaced loads

and generators exist in the system. The harmonic analysis tool requires less detail and

engineering time than PSCAD/EMTDC while offering reliable assessment of harmonic

coupling problems that are not captured by existing frequency-domain harmonic analysis

tools. To do this, 5 harmonic models of common power electronic converter topologies

were developed and implemented into this tool. The harmonic models are shown to be

highly accurate; when tested in an unbalanced system with even and odd harmonic dis-

tortion, the harmonic models showed a maximum error of less than 0.4% when compared

to PSCAD/EMTDC.

ii

Page 3: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Acknowledgements

I would like to first thank my supervisor, Prof. Peter W. Lehn. His support, insights

and encyclopaedic knowledge of power systems and power electronics were instrumental

in putting together this thesis.

Thank you to the University of Toronto for providing the funding that allowed me to

do this work. I would also like to thank my labmates Farhad Yahyaie, Greg Kish, Kia

Filsoof, John Zong, Dominic Paradis, Adrian Amanci, Jin Chang and Theo Soong for

making these past couple of years an extremely enjoyable experience.

Finally, I would like to thank my parents, Pauline andWayne, for their endless support

and encouragement.

iii

Page 4: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Contents

1 Introduction 1

1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.2 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.3 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.4 Literature Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1.5 Overview of Thesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2 Harmonic Modelling Approach 7

2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2.2 Overview of Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2.3 FCM Derivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.3.1 Submatrix C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

2.3.2 Submatrices D and E . . . . . . . . . . . . . . . . . . . . . . . . 16

2.4 Summary of Chapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

3 Voltage Source Converter Harmonic Model 18

3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

3.2 Assumed Topology and Modes of Operation . . . . . . . . . . . . . . . . 18

3.3 Control Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3.4 Harmonic Modelling Approach . . . . . . . . . . . . . . . . . . . . . . . . 21

3.4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

3.4.2 Control Parameter Initialization . . . . . . . . . . . . . . . . . . . 23

3.4.3 FCM Derivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

3.4.4 Evaluation of Constraint Equations . . . . . . . . . . . . . . . . . 28

3.4.5 Control Parameter Update . . . . . . . . . . . . . . . . . . . . . . 29

3.4.6 Summary of Approach . . . . . . . . . . . . . . . . . . . . . . . . 30

iv

Page 5: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

3.5 Summary of Chapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

4 Line Commutated Converter Harmonic Models 31

4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

4.2 Overview of Harmonic Models . . . . . . . . . . . . . . . . . . . . . . . . 31

4.3 Assumed Topologies and Modes of Operation . . . . . . . . . . . . . . . 35

4.3.1 6-Pulse Converter . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

4.3.2 12-Pulse Converter . . . . . . . . . . . . . . . . . . . . . . . . . . 37

4.4 Control Scheme for Thyristor-Switched Converter . . . . . . . . . . . . . 39

4.5 Harmonic Modelling Approach . . . . . . . . . . . . . . . . . . . . . . . . 40

4.5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

4.5.2 Control Parameter Initialization . . . . . . . . . . . . . . . . . . . 41

4.5.3 Outer Iterative Loop . . . . . . . . . . . . . . . . . . . . . . . . . 43

4.5.4 Inner Iterative Loop . . . . . . . . . . . . . . . . . . . . . . . . . 44

4.5.5 FCM Derivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

4.5.6 Constraint Equation Evaluation . . . . . . . . . . . . . . . . . . . 55

4.5.7 Control Parameter Update . . . . . . . . . . . . . . . . . . . . . . 61

4.5.8 Summary of Approach . . . . . . . . . . . . . . . . . . . . . . . . 64

4.6 Summary of Chapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

5 Harmonic Analysis Tool 65

6 Results 69

6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

6.2 Evaluating Accuracy of Harmonic Models and OpenHarmonics . . . . . . 69

6.2.1 Harmonic Models . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

6.2.2 OpenHarmonics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

6.3 Evaluating Computation Time of Harmonic Models and OpenHarmonics 89

6.3.1 Harmonic Models . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

6.3.2 OpenHarmonics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

6.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

7 Conclusions and Future Work 96

7.1 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

7.2 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

v

Page 6: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

References 98

A Harmonic Model Derivations 102

A.1 VSC Harmonic Model Differential Equations . . . . . . . . . . . . . . . . 102

A.2 6-Pulse Topology Differential Equations . . . . . . . . . . . . . . . . . . . 105

A.2.1 Commutation Interval . . . . . . . . . . . . . . . . . . . . . . . . . 105

A.2.2 Conduction Interval . . . . . . . . . . . . . . . . . . . . . . . . . . 107

A.3 12-Pulse Topology Differential Equations . . . . . . . . . . . . . . . . . . 109

A.3.1 Relating Primary and Secondary Sides of 12-Pulse Topology . . . . 109

A.3.2 Conduction Interval . . . . . . . . . . . . . . . . . . . . . . . . . . 111

A.3.3 Commutation Interval 1 . . . . . . . . . . . . . . . . . . . . . . . . 113

A.3.4 Commutation Interval 2 . . . . . . . . . . . . . . . . . . . . . . . . 116

A.4 Initializing Control Parameters . . . . . . . . . . . . . . . . . . . . . . . . 120

A.4.1 VSC Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

A.4.2 Line Commutated Converter Models . . . . . . . . . . . . . . . . . 121

B MATLAB Source Code 127

B.1 Source Code for OpenHarmonics . . . . . . . . . . . . . . . . . . . . . . . 127

B.2 Source Code for Harmonic Models . . . . . . . . . . . . . . . . . . . . . . 143

B.2.1 VSC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

B.2.2 Thyristor 6-Pulse Rectifier . . . . . . . . . . . . . . . . . . . . . . . 155

B.2.3 Diode 6-Pulse Rectifier . . . . . . . . . . . . . . . . . . . . . . . . . 175

B.2.4 Thyristor 12-Pulse Rectifier . . . . . . . . . . . . . . . . . . . . . . 195

B.2.5 Diode 12-Pulse Rectifier . . . . . . . . . . . . . . . . . . . . . . . . 216

vi

Page 7: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 1

Introduction

1.1 Background

Harmonic distortion in a power system can have significant negative impacts on utilities,

industry, commercial and residential consumers. These negative impacts include: excita-

tion of resonant frequencies, premature ageing and malfunctioning equipment, reduced

efficiency of the power system and distortion of communication signals [1,2]. One of the

primary sources of these harmonics are loads and generators interfaced to the system

through power electronics [2]. Some common power electronics seen on power systems,

include three-phase voltage source converters (VSCs), which are used in HVDC appli-

cations, static var compensators, and for interfacing distributed generation (DG) from

sources such as wind and solar photovoltaics to the system; and 6 and 12 pulse con-

trolled and uncontrolled rectifiers, which are used in industrial processes for interfacing

three-phase machines to the system [3, 4].

Power electronic interfaced loads and generators represent a significant proportion of

the loads and generators on a power system and this proportion is growing. Therefore, it

is becoming increasingly important to analyze the steady-state harmonics of power sys-

tems. The harmonic analysis tools, used to perform harmonic studies of power systems,

either employ a frequency or a time domain derived approach. Time-domain harmonic

analysis tools, such as EMTDC/PSCAD, can be used to perform high-accuracy harmonic

analysis studies but tend to suffer from long computation times and the accuracy of the

results is sensitive to the time-step and simulation length. Frequency-domain harmonic

analysis tools, such as CYME or ETAP, can be used to perform computationally effi-

cient analysis of power system harmonics, but the accuracy of the results is sensitive

1

Page 8: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 1. Introduction 2

to harmonic truncation. Furthermore, the studied frequency-domain harmonic analysis

tools were all shown to feature harmonic models of converters that were highly simpli-

fied. These harmonic models were represented as fixed current sources with an associated

harmonic spectrum—which assumes that the power system is balanced with negligible

voltage harmonic distortion. This approach, is potentially problematic as uncharacteris-

tic converter harmonics would be entirely absent from harmonic analysis results.

1.2 Motivation

The need to perform higher accuracy harmonic simulation studies of systems with multi-

ple sources of harmonics is becoming an increasingly important issue. The tools currently

available either have the capacity to perform high accuracy harmonic analysis studies but

are too computationally intensive for the simulation of larger, more complicated, power

systems, or they are computationally efficient but the harmonic models are too oversim-

plified to provide accurate results in systems with significant levels of harmonic distortion.

Furthermore, the harmonic models in literature do not all feature inputs and outputs that

allow them to be easily interfaced with a common frequency-domain harmonic analysis

tool.

1.3 Objective

A harmonic analysis software tool is developed for this thesis, called OpenHarmonics.

OpenHarmonics is developed in MATLAB and is a frequency-domain based, steady-

state, harmonic analysis tool that is designed to accurately analyze the harmonics on a

power system with multiple converter interfaced loads and generators. OpenHarmonics

is built on top of the open source, harmonic analysis tool called, OpenDSS, and uses

OpenDSS to perform the harmonic analysis studies. For OpenHarmonics to accurately

analyze harmonics from converter interfaced loads and generators, high accuracy har-

monic models of common converter topologies were developed and implemented into the

OpenHarmonics tool. The following 5 harmonic models are developed for this thesis:

three-phase two-level VSC, 6-pulse diode rectifier, 12-pulse diode rectifier, 6-pulse thyris-

tor rectifier and a 12-pulse thyristor rectifier. These harmonic models are designed to

accommodate unbalanced systems with significant harmonic distortion. The models of-

fer a high level of accuracy yet avoid reliance on converter control system parameters

Page 9: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 1. Introduction 3

User assigned converter

reference values (ex. P, Q, etc.)

PCC

Time Domain Analytical

Converter Solution

Harmonic Domain Network

Solution

OpenDSSDeveloped MATLAB models

Iharmonics

Vharmonics

Figure 1.1: How OpenHarmonics and OpenDSS are Interfaced

that are generally unavailable to systems engineers. A flowchart outlining how Open-

Harmonics is interfaced to OpenDSS is shown in Fig. 1.1 and the solution algorithm of

OpenHarmonics is outlined in Fig. 1.2.

Each harmonic model of a converter interfaced load or generator is represented in

OpenDSS as a three-phase current source with a fixed harmonic spectrum. The harmonic

spectra of these loads and generators are computed in OpenHarmonics. Referring to

Fig. 1.1, the harmonic models of the common converter topologies take as an input the

user assigned converter reference values, such as average power Pdc and average dc-link

voltage Vdc, as well as the point of common coupling (PCC) voltage harmonics from

the OpenDSS solution of the ac network. The harmonic models then use these inputs

to solve for the harmonic spectra of the converter currents. However, the PCC voltage

harmonics, obtained from the OpenDSS solution, are functions of the harmonic spectra of

the converter currents. Therefore, an iterative loop is required to converge on the injected

current harmonic spectra for the harmonic models such that the differences in PCC

harmonic amplitudes, from consecutive iterations, are within a tolerance requirement.

This iterative loop in OpenHarmonics is outlined in Fig. 1.2. Each iteration involves

solving for the PCC voltage harmonics in OpenDSS; using the results to re-solve the

harmonic models in OpenHarmonics; and then using the results from OpenHarmonics to

update the harmonic spectra in OpenDSS. However there is an inherent incompatibility

Page 10: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 1. Introduction 4

Start

MATLAB

VSC, Thyristor,

Diode Models

OpenDSS

Network

Have PCC voltages

converged?

Stop

Yes

Vharmonics

No

Iharmonics

Figure 1.2: OpenHarmonics Solution Algorithm

between OpenDSS and OpenHarmonics. In OpenDSS the analysis is in the frequency-

domain and in OpenHarmonics the analysis of the harmonic models is in the time-domain.

As such, the PCC voltage harmonics are converted to the time-domain prior to analysis

of the harmonic models. After the harmonic models are solved, the solution is converted

back to the frequency-domain such that the harmonic spectra of the three-phase current

sources in OpenDSS, that represent the harmonic models, can be updated.

The core contribution of thesis is the converter models and their solution. The soft-

ware tool OpenHarmonics that has been developed provides one possible application of

these models.

Page 11: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 1. Introduction 5

1.4 Literature Review

The harmonic models of power electronic converters in literature tend to be derived either

through a transfer function derived approach or through a frequency coupling matrix

(FCM)—alternatively termed the harmonic admittance matrix—approach. The transfer

function approach involves deriving a switching function for the converter and using this

function to relate the dc-side states of the converter to the ac-side states [5–9]. The FCM

is a matrix that couples the ac and dc side states of a converter—this approach is adopted

in [4,10–17]. The FCM can be derived either by a frequency-domain derived approach or

through an analytical approach. If the FCM is derived using a frequency-domain derived

approach, harmonic truncation errors are introduced into the solution. The analytical

approach for the derivation of the FCM is discussed in [10, 11]. The advantages of the

approach in [10,11] are that the harmonics are directly solved for, i.e. transients are not

solved for which offers a significant computational efficiency advantage over time-domain

derived methods which do solve for transients even when only interested in the steady-

state solution. Furthermore, this approach does not introduce harmonic truncation errors

into the solution.

Many harmonic models of converter topologies have been developed in literature.

In [6,8,9], VSC harmonic models are derived using the transfer function derived approach.

The disadvantage of using these harmonic models are that they introduce error into

the solution through either neglecting switching harmonics from the derived switching

function or by linearization about an operating point, which neglects the interaction of

harmonics of different frequencies. In [10,18–20], VSC harmonic models are analytically

derived. In [18, 19], a three-phase VSC harmonic model is derived. The disadvantage

of the approach used is that the impact of harmonic distortion on both the ac side and

dc side of the converter is neglected. The harmonic model of the VSC in [10], builds on

the research work of [18, 19] by using a FCM matrix approach to derive the harmonic

model. The disadvantages of the approach used in this paper are that it uses an open

loop formulation and it involves computing a complex valued FCM.

Line commutated converter harmonic models have also been developed in literature.

In [5, 7], a three-phase 6-pulse thyristor rectifier harmonic model is developed using the

transfer function derived approach. Some disadvantages of the approach proposed is

that the harmonic model of [5] involves linearization about an operating point, and

the harmonic model of [16] assumes ripple free dc-side current. In [14, 16], a three-

Page 12: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 1. Introduction 6

phase thyristor rectifier harmonic model is developed using a FCM derived approach.

The problems with the proposed approaches are that several assumptions about the

system are made, such as: balanced PCC, negligible harmonic distortion on the PCC,

negligible harmonic distortion in the dc-side current and the approaches approximate

the switching waveforms. In [21] a closed form harmonic solution for a thyristor bridge

converter is analytically derived. However this harmonic model is for balanced systems

with characteristic ac-side harmonics. In [22, 23], diode rectifier harmonic models are

derived using an analytical approach. The harmonic model of [22] is an extension of

the harmonic model of [23] to three phases. The disadvantages of the harmonic model

of [22] are that it assumes balanced systems operation with negligible voltage harmonic

distortion. In [24] an alternate approach is discussed to harmonic modelling of three-

phase diode rectifiers also using an analytical approach, but the analysis is extensive and

is difficult to implement.

1.5 Overview of Thesis

The remainder of this thesis is structured as follows. Chapter 2, discusses the general

approach used to derive the 5 harmonic models of this thesis. Chapter 3, presents the VSC

harmonic model, this includes a description of the assumed topology, modes of operation

and control scheme, as well as description of how the harmonic model was derived.

Chapter 4, discusses the line commutated converter harmonic models, this includes a

description of the assumed topologies, modes of operation and control schemes, as well

as description of how the harmonic models were derived. In Chapter 5, the harmonic

analysis tool, OpenHarmonics, is presented. In Chapter 6, the accuracy of the harmonic

models and the harmonic analysis tool, is evaluated. In Chapter 7, the conclusions and

future research work are presented.

Page 13: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 2

Harmonic Modelling Approach

2.1 Introduction

In this thesis, 5 harmonic models of common converter topologies are developed. These

models are each designed to read in a set of inputs, process these inputs, and output

a vector containing the Fourier coefficients of the harmonic multiples of the unknown

converter states. A common approach is used to derive these harmonic models and in

this chapter this approach is presented. This common approach is a modified form of the

approach developed by K. Lian and P. Lehn [10,22]. Chapters 3 and 4 describe how the

approach is adapted to derive the specific harmonic models for each converter type.

2.2 Overview of Approach

A high-level flow chart outlining the approach used to derive the harmonic models is

shown in Fig. 2.1. The inputs to the models include: i) the impedance values of the circuit

elements; ii) the Fourier coefficients of the harmonic multiples of the known converter

states—the known converter states generally depend on the converter topology being

modelled, however the PCC voltages are considered as known converter states for each of

the 5 modelled converter topologies—and iii) the controlled converter state values (i.e. the

real power drawn by the converter is a controlled converter state for the thyristor-switched

harmonic models). The output of the harmonic models, are the Fourier coefficients of

the harmonic multiples of the desired converter states. The desired converter states

generally depend on the converter topology being modelled, however the ac-side currents

are considered as desired states for each of the 5 modelled converter topologies. The

7

Page 14: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 2. Harmonic Modelling Approach 8

Initialize Control ParametersInitialize Control Parameters

Calculate FCMCalculate FCM

Have Constraint

Requirements

Been Met?

Evaluate Constraint

Equations

Evaluate Constraint

Equations

Yes

Calculate Switching Times

and Switch States

Calculate Switching Times

and Switch States

Update Control

Parameters

Update Control

Parameters

No

Read in Inputs

Write Outputs

Calculate Exact

Jacobian

Calculate Exact

Jacobian

1.

2.

4.

3.

5.

Figure 2.1: Harmonic Modelling Approach

general procedure, outlined in Fig. 2.1, used to obtain the Fourier coefficients of the

desired converter states is briefly described here:

1. First, the control parameters of the converter are initialized. An example of a

control parameter is the firing angle for the thyristor-switched converters.

2. Using the control parameters, the switching times and switch states of the converter

are solved, for an entire steady-state period.

3. Using the switching times and switch states, the FCM of the converter is solved.

4. Using the FCM in combination with the inputs to the model, the converter con-

straint equations are evaluated.

5. Finally, if the constraint requirements are met, the loop is exited and the con-

verter outputs are written. Otherwise, the control parameters are updated, using

a Newton-Raphson technique, and the model is re-solved, starting at Step 2.

Page 15: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 2. Harmonic Modelling Approach 9

The next section discusses Step 3 in more detail, i.e. how the FCMs of the converter

models are derived. The other steps, Steps 1, 2, 4 and 5, are more specific to the converter

topology being modelled, and are therefore discussed in Chapters 3 and 4.

2.3 FCM Derivation

A FCM that maps the known converter states at time t, contained in input vector ~u, to

the unknown converter states, contained in output vector ~y, is shown in (2.1).

~y = [FCM(t1, . . . , tn)]~u (2.1)

where, t1, . . . , tn are all the switching times of the converter for an entire steady-state

period for the interval [t, t+ T ]. In this thesis, for readability purposes, FCM(t1, . . . , tn)

is referred to as FCM.

If (2.1) is applied to the ac/dc converter model of Fig. 2.2, and supposing the input

vector, ~u, contains the harmonics of states idc and vac and, the output vector, ~y, contains

the harmonics of states iac and vdc, (2.1) can be re-expressed as shown in (2.2),

ac

dcvac vdc

iac idc

Figure 2.2: Generalized ac/dc Converter Model

[

~iac

~vdc

]

= [FCM]

[

~vac~idc

]

(2.2)

where, the elements of the 4 vectors of (2.2) can be represented in the space vector

reference frame as shown here,

Page 16: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 2. Harmonic Modelling Approach 10

~iac =

i−hacα

i−hacβ...

i+hacα

i+hacβ

, ~vac =

v−hacα

v−hacβ...

v+hacα

v+hacβ

, ~idc =

Idc

ReI1dcejωLtImI1dcejωLt

...

ReImdcejmωLtImImdcejmωLt

, ~vdc =

Vdc

ReV 1

dcejωLt

ImV 1

dcejωLt

...

ReV m

dcejmωLt

ImV m

dcejmωLt

where, subscript h refers to the number of analyzed ac-side harmonics. subscript m refers to the number of analyzed dc-side harmonics. ~iac is a vector containing the positive and negative sequence harmonics of the ac-side

phase currents at time t expressed in the space-vector reference frame. ~vac is a vector containing the positive and negative sequence harmonics of the PCC

voltage at time t expressed in the space-vector reference frame. ~idc is a vector containing the real and imaginary components of the dc-side current

harmonics at time t. ~vdc is a vector containing the real and imaginary components of the dc-side voltage

harmonics at time t.

It should be noted that i) implicit in the formulation of the vectors of (2.2) is the elim-

ination of the zero-sequence voltage component of the PCC voltage from the analysis;

and ii) the converter topologies assumed for the harmonic models of this thesis do not

include a neutral path; therefore, no assumptions are made in the formulation of vector,

~iac, which does not include zero-sequence components.

For illustration purposes, the calculation of the vector elements of ~vac, for harmonic

multiple k, is shown here, where k ∈ [−h,−(h− 1), . . . ,+h],

vkacα + jvkacβ =(

V kacα + jV k

acβ

)

ejkωLt (2.3)

where, V kacα and V k

acβare the Fourier coefficients of the space-vector representation of the

PCC voltage for harmonic multiple k. As such, at t = 0 the vector elements corresponding

to harmonic multiple k are equal to the Fourier coefficients for harmonic multiple k. If

Page 17: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 2. Harmonic Modelling Approach 11

k < 0, then vkacα and vkacβ correspond to the space-vector components of the negative

sequence, kth harmonic, of the PCC voltage. Conversely if k > 0, then vkacα and vkacβcorrespond to the space-vector components of the positive sequence, kth harmonic, of the

PCC voltage. The elements of vector ~iac are defined similarly.

Again, for illustration purposes, vector element~idc for harmonic multiple r, is defined

as shown in (2.4), where r ∈ [1, 2, . . . , m],

irdc = ReIrdcejrωLt (2.4)

The elements of vector ~vdc are defined similarly.

A power electronic converter exhibits non-linear behaviour due to the switching of

the converter’s power electronic switches. This non-linear behaviour can be modelled,

over an arbitrary time interval, using piecewise linear equations, if it is known how the

states of the switches change over that time interval.

At any time instant t, each switch, assuming ideal switches, has a defined state

of either off or on. Therefore, at any time instant t, the switches can be replaced with

passive circuit elements, which leads to an equivalent circuit representation that is linear.

Furthermore, any time interval can be represented as a series of sub time-intervals, in

which the switch states do not change state. Therefore, if the time instants at which

these sub time-intervals begin and end are known, and the states of the switches during

these sub-intervals are known, a piecewise formulation of linear equations can be used

to model the converter for the time interval of interest. For the harmonic models of

this thesis, only the steady-state time interval is of interest and therefore to model the

converter over this time interval the states of the switches and the time instants when

a switch changes states must be solved for. The calculation of the switching times is

unique to the converter topology being modelled and the control scheme assumed for

that topology and therefore the calculations of the switching times are discussed later,

in Chapter 3 and 4.

It is important to note, before proceeding in the discussion, that the elements of

input vector ~u, in (2.1), are specified for an arbitrary time instant t during steady-state

operation. In deriving the FCM of the converters, it is often convenient to rotate the

input vector in time, such that the input vector at this new time corresponds to a fixed

event, such as the firing of a particular thyristor in the thyristor-switched converter

models. By rotating the input vector and conducting the analysis relative to this rotated

Page 18: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 2. Harmonic Modelling Approach 12

input vector, the derivation of the FCM can be greatly simplified without effecting the

accuracy of the solution. Eqn. (2.5) shows how to advance input vector ~u, specified at

t = 0, forward in time by ∆t = t1, i.e. from t = 0 to t = t1.

~u(t1) = Rt1~u(0) (2.5)

where,

Rt1 =

coshωLt1 sinhωLt1

− sinhωLt1 coshωLt1. . .

coshωLt1 − sinhωLt1

sinhωLt1 coshωLt1

0

. . .

cosmωLt1 − sinmωLt1

sinmωLt1 cosmωLt1

(2.6)

The output vector ~y is then solved for at time t1 using ~u(t1) in place of ~u(0) as is shown

in (2.7),

~y(t1) = [FCM]~u(t1) (2.7)

In order to derive the FCM, the input vector ~u and the output vector ~y, are represented

as state variables of an extended dynamic system. If the states variables are combined

into a single vector, the autonomous system of (2.8) results—which is valid for a time t,

where tk < t < tk+1.

d

dt

iacα

iacβ

vdc

~u

~y

= Mk

iacα

iacβ

vdc

~u

~y

(2.8)

where, iacα is specified in the time-domain and is the α-component of the ac-side phase

currents represented in space vector format. iacβ is specified in the time-domain and is the β-component of the ac-side phase

currents represented in space vector format.

Page 19: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 2. Harmonic Modelling Approach 13 vdc is specified in the time-domain and is the dc-side voltage. Mk is a linear time-invariant matrix and is valid for the time interval tk < t < tk+1.

For improving the readability of this thesis, (2.8) is re-written as (2.9), where vector ~x

contains the time-domain states,

d

dt

~x

~u

~y

= Mk

~x

~u

~y

(2.9)

For any given converter topology there is a finite number of combinations of switch

states. As such, a finite number of time-invariant Mk matrices can be derived that fully

describe the steady-state operation of the converter. Due to the properties of the elements

contained in ~x, ~u, and ~y, the Mk matrices have the structure shown in (2.10),

Mk =

Ak Bk 0

0 C 0

D 0 E

(2.10)

where, Ak is a 3-by-3 submatrix; Bk is a 3-by-(4h+2m+3) submatrix; C is a (4h+2m+3)-

by-(4h+2m+3) submatrix; D is a (4h+2m+3)-by-3 submatrix; and E is a (4h+2m+3)-

by-(4h+ 2m+ 3) submatrix

The values of the Ak and Bk submatrices depends on the converter topology as well

as the switch states; as such these submatrices are derived in Chapter 3 and 4, for the

specific converters. The value of submatrix C depends on the elements of ~u and the

values of the D and E submatrices depends on the elements of ~y. The derivation of the

C, D and E submatrices is discussed at the end of this chapter.

Assuming that all Mk matrices, switching times and switch states, are known for an

entire steady-state period, (2.9) can be integrated with respect to time from t = t1 to

t = t1 + T . The result of the this integration is (2.11),

~x(T + t1)

~u(T + t1)

~y(T + t1)

=n−1∏

k=1

eMk(tk+1−tk)

~x(t1)

~u(t1)

~y(t1)

(2.11)

where, Mk ∈ [M1, . . . ,Mj ], with j referring to the number of converter configurations,

Page 20: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 2. Harmonic Modelling Approach 14

and n refers to the number of switching times during steady-state.

For convenience reasons, from this point on in the thesis, when discussing the Mk, Ak

and Bk matrices, M , A and B are used instead of Mk, Ak and Bk. Due to the structure of

the M matrices, shown in (2.10),∏n−1

k=1 exp(Mk(tk+1 − tk)) (which is assigned to variable

Φ) necessarily has the following structure, as described by K. Lian and P. Lehn [10],

Φ =

AT BT 0

0 CT 0

DT FT ET

(2.12)

where, Φ is a matrix that maps the elements of ~x, ~u, and ~y from one period to the next.

The following two equations can be extrapolated from the result of substituting (2.12)

into (2.11),

~y(T + t1) =DT~x(t1) + FT~u(t1) + ET~y(t1) (2.13a)

~x(T + t1) =AT~x(t1) +BT~u(t1) (2.13b)

Because of the periodicity of steady-state signals, ~x(t1) = ~x(T + t1). This can be substi-

tuted into (2.13b), resulting in (2.14),

~x(t1) = (I − AT )−1BT~u(t1) (2.14)

where, I is a 3-by-3 identity matrix

Substituting (2.14) into (2.13a), yields (2.15),

~y(T + t1) = (DT [I − AT ]−1BT + FT )~u(t1) + ET~y(t1) (2.15)

If ~y(t1) is initialized to 0, (2.15) will be equivalent to (2.7) because ~u(t1+T ) = ~u(t1). As

such, the expression for the FCM, shown in (2.16), can be extracted from (2.15),

[FCM] = DT [I −AT ]−1BT + FT (2.16)

The output vector ~y at t = 0 is obtained by rotating the vector ~y(t1) by −t1 as is shown

in (2.17),

~y(0) = R(−t1)[FCM]~u(t1) (2.17)

Page 21: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 2. Harmonic Modelling Approach 15

The output vector ~y(0) in (2.17) contains the ac-side current and dc-side voltage har-

monics at time t = 0. The FCMs for the 5 harmonic models are all derived this way.

Before discussing the specific harmonic converter models, the C, D and E submatrices

of the M matrices are derived.

2.3.1 Submatrix C

The elements of input vector ~u, are sinusoidally time-varying inputs, with values that

are independent of the converter operation. To derive submatrix C, it is illustrative to

solve for the time derivative of one harmonic multiple and then to extend this analysis

to the other harmonic multiples included in submatrix C. The time derivative of ~vkacαβis

derived here,

d

dtvkacα + j

d

dtvkacβ =

(

V kacα + jV k

acβ

) d

dtejkωLt (2.18a)

= jkωL

(

vkacα + jvkacβ

)

(2.18b)

=⇒ d

dtvkacα = −kωLv

kacβ

(2.19)

=⇒ d

dtvkacβ = +kωLv

kacα (2.20)

Eqn. (2.21) is the result of combining (2.19) and (2.20) into vector format,

d

dt

[

vkacα

vkacβ

]

=

[

0 −kωL

+kωL 0

][

vkacα

vkacβ

]

(2.21)

By induction, the analysis used to calculate (2.21) can be applied to all elements of vector

~u. Submatrix C, shown in (2.22), was derived for an input vector ~u, containing ac-side

voltage harmonics from harmonic multiple −h to +h and dc-side current harmonics from

Page 22: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 2. Harmonic Modelling Approach 16

harmonic multiple 0 to m,

C =

0 +hω

−hω 0. . .

0 −hω

hω 0

0. . .

0 −mω

+mω 0

(2.22)

2.3.2 Submatrices D and E

A Fourier series decomposition is used to solve for the harmonic output variables of vector

~y. The variables may be found from [10]. The variables for the kth harmonic multiple of

the ac-side current, where −h < k < +h, are shown in (2.23),

d

dt

[

ikacα

ikacβ

]

=

[

0 −kωL

+kωL 0

][

ikacα

ikacβ

]

+1

T

[

iacα

iacβ

]

(2.23)

This can be converted to complex number format, as shown in (2.24),

d

dtikacα + j

d

dtikacβ = jkωL(i

kacα + jikacβ) +

1

T

(

iacα + jiacβ)

(2.24)

The solution of (2.24), if the limits of integration are from t = 0 to t = T , is the following,

ikacα(T ) + jikacβ(T ) = ejkωLT(

iksα(0) + jiksβ(0))

+1

T

T∫

0

e−jkωLt(

iacα + jiacβ)

dt (2.25)

This can be re-written as shown in (2.26), if iacα(0) and iacβ(0) are initialized to 0,

iacα(T ) + jiacβ(T ) =1

T

T∫

0

e−jkωLt(

iacα + jiacβ)

dt (2.26)

Page 23: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 2. Harmonic Modelling Approach 17

The analysis of the dc-side voltage harmonics is similar. Therefore just the results are

presented in (2.27), for harmonic multiple r, where r ∈ [0, m],

d

dt

[

ReV r

dcejrωLt

ImV r

dcejrωLt

]

=

[

0 −rωL

+rωL 0

][

ReV r

dcejrωLt

ImV r

dcejrωLt

]

+1

T

[

1

0

]

vdc (2.27)

The submatrices D and E can be solved by extending the results of (2.23) and (2.27) to

include ∀k ∈ [−h,+h] and ∀r ∈ [0, m], as is shown in (2.28) and (2.29),

D =

1/T 0 0

0 1/T 0...

1/T 0 0

0 1/T 0

0 0 1/T...

0 0 1/T

(2.28)

E =

0 +hω

−hω 0. . .

0 −mω

+mω 0

(2.29)

2.4 Summary of Chapter

This chapter presents the common modelling approach used to derive the harmonic mod-

els of this thesis. First, the step-by-step procedure used to solve the harmonic models of

the converters was discussed. Then, it was described how the FCM approach is used in

the harmonic models of this thesis. Solving the FCM was shown to require i) the switch-

ing times and switch states for an entire steady-state period, and ii) the time-derivatives

of the converter states. Finally, the time-derivatives of input vector ~u and output vector

~y, were derived for the harmonic models.

Page 24: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 3

Voltage Source Converter Harmonic

Model

3.1 Introduction

In this chapter the VSC harmonic model is presented. First, the topology, assumed

modes of operation, and control scheme from which the VSC harmonic model is derived

is described. This is followed by a discussion of the harmonic modelling approach used

for the VSC harmonic model.

3.2 Assumed Topology and Modes of Operation

The VSC harmonic model assumes the three-phase VSC topology shown in Fig. 3.1. The

system voltages are represented by the voltage sources vsa, vsb and vsc; and the interface

transformer equivalent impedance, system impedance, line impedances, and the resistive

switching losses are represented by impedances R and L. The control scheme assumed

is the sample-and-hold sinusoidal PWM scheme.

The inputs to the VSC model are the following: ~vs, ~idc, Vdc, Qac and the impedances

R, L, Cdc and Rdc, which are shown in Fig. 3.1. The outputs of the VSC model are the

following: ~is and ~vdc. ~vs is a vector containing the positive and negative sequence harmonics of the PCC

voltage at time t expressed in the space-vector reference frame.

18

Page 25: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 3. Voltage Source Converter Harmonic Model 19

R

L

RR

L L

isbisc isa

vdc

Qac

Sa Sb Sc

Sa’ Sb’ Sc’

idcCdc

Pdc

vtab

vtbc

Rdc

vsa

vsb

vsc

Figure 3.1: VSC Topology ~idc is a vector containing the real and imaginary components of the dc-side current

harmonics at time t. Vdc is the average dc-link voltage. Qac is the total reactive power absorbed by the converter. ~is is a vector containing the positive and negative sequence harmonics of the ac-side

phase currents at time t expressed in the space-vector reference frame. ~vdc is a vector containing the real and imaginary components of the dc-side voltage

harmonics at time t.

The average power Pdc is indirectly specified via the average dc-side average current Idc

and the average dc-link voltage Vdc.

Page 26: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 3. Voltage Source Converter Harmonic Model 20

3.3 Control Scheme

A sample-and-hold sinusoidal PWM control scheme is assumed for the derivation of the

VSC harmonic model. Through use of this control scheme, the VSC controls the positive-

sequence line-frequency component of the voltage at the converter’s terminals, v+1tαβ . This

voltage is controlled by two control parameters: the modulation index and phase angle

offset. The modulation index, represented as ma in (3.1a), is the ratio of the magnitude

of the terminal voltage of the converter with respect to half the average dc-link voltage.

The phase angle offset, represented as δ in (3.1b), is the phase angle difference of the

positive-sequence line-frequency voltage component at the PCC, v+1sαβ , with respect to

v+1tαβ .

ma =|v+1

tαβ |Vdc/2

(3.1a)

δ =∠v+1tαβ − ∠v+1

sαβ (3.1b)

The control scheme assumes that each phase (phase a,b and c) has the same modulation

index and phase angle offset. The reference waveforms used to control the phase a, b

and c voltages at the converter’s terminals are shown in (3.2),

vrefta =maVdc

2cos(

δ + ∠v+1sαβ

)

(3.2a)

vreftb =maVdc

2cos

(

δ + ∠v+1sαβ −

3

)

(3.2b)

vreftc =maVdc

2cos

(

δ + ∠v+1sαβ +

3

)

(3.2c)

The control scheme, applied to the phase a reference waveform, vrefta , is graphically illus-

trated in Fig. 3.2, for a fraction of a steady-state period. The carrier signal for the PWM

switching scheme is a triangular waveform with a magnitude of Vdc

2and a frequency equal

to fsw Hz.

The control scheme works as follows. At the beginning of each carrier half-cycle, t =[

0, 12fsw

, 22fsw

, · · · , 2fsw/fL−12fsw

]

, the reference waveforms are sampled. These sampled values

are calculated using (3.2). Before, the next carrier half-cycle, the triangular waveform

will intersect with the 3 sampled values of the reference waveforms. The instants at which

these intersections occur corresponds to switching times. For the half-periods where the

Page 27: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 3. Voltage Source Converter Harmonic Model 21

Carrier

t1 t4t3t2 t7t6t5 t8

ref

tav

1

0

aS

Figure 3.2: Sample-And-Hold Sinusoidal PWM Control Scheme Applied to Phase a

carrier has a negative slope at the switching time, the upper leg switch changes state

from off to on, and the lower leg switch, changes state from on to off. This is because the

upper and lower leg switches, for each phase, are switched in a complementary fashion.

For the half-periods where the carrier has a positive slope, the upper leg switch changes

state from on to off, and the lower leg switch changes state from off to on. It should be

noted that the computation of the switching times assumes the converter is synchronized

to the positive sequence line frequency component of the PCC voltage, and negative

sequence PCC voltage distortion is rejected by the converter’s PLL.

3.4 Harmonic Modelling Approach

3.4.1 Introduction

The harmonic modelling approach used to solve the VSC harmonic model is shown below

in Fig. 3.3. In this approach, the control parameters, ma and δ, are iteratively solved

Page 28: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 3. Voltage Source Converter Harmonic Model 22

for such that the Vdc and Qac of the converter matches the input references. The pro-

Initialize ma and δ

Calculate FCM

Have Constraint

Requirements

Been Met?

Evaluate Constraint Equations

Yes

Calculate Switching Times and

Switch States for Period T

(t1, t2,…, t6mf)

Update δ and ma

No

Read in Inputs

(vs, idc, Qac, Vdc, fsw, Zsys)

Write Outputs

(is, vdc)

Calculate Exact

Jacobian

Figure 3.3: Generalized Solution Algorithm for Harmonic VSC Models

cedure outlined in Fig. 3.3 is briefly described here. The control parameters ma and δ

are first initialized using analytically derived equations. The control parameters are then

used to calculate all switching times and the corresponding switch states for an entire

steady-state period. The switching times and switch states are then used to formulate

the FCM. From this FCM, the output vector ~y is calculated which is used to calculate the

Vdc and Qac of the converter. If the calculated Vdc and Qac values are not sufficiently close

the input reference values, i.e. < 0.001 per-unit, another iteration is performed with the

updated control parameters. Otherwise, the loop exits and the output vector ~y is written.

The next few sections describe these steps in greater detail.

Page 29: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 3. Voltage Source Converter Harmonic Model 23

3.4.2 Control Parameter Initialization

In initializing the control variables, ma and δ, it is assumed that the PCC is balanced with

negligible harmonic distortion. The equations used to initialize the control parameters

are shown here in (3.3). The derivation of (3.3) can be found in Appendix A.4.1.

δ =tan−1

VdcIdc

Qac +3

2

ωL|v+1sαβ|2

R2 + (ωL)2

(3.3a)

ma =4

3

R2 + (ωLL)2

ωLL

Idc

|v+1sαβ|

(3.3b)

3.4.3 FCM Derivation

3.4.3.1 Introduction

In this section, the derivation of the FCM for the VSC harmonic model is discussed. First,

the equations used to calculate the switching times of the converter are derived. Then,

the M matrices, that describe the time-variability of the converter states, are derived.

Finally, it is described how the M matrices and the switching times are combined to

formulate the FCM.

3.4.3.2 Switching Times

In this section, the approach used to calculate all 2 fswfL

, or alternatively expressed 2mf ,

switching times involved in the control of the voltage at the phase a terminal is discussed.

The calculation of the switching times for phases b and c is similar and therefore it is

not discussed here. A qualitative description of the control scheme used for the VSC was

described in Section 3.3. The carrier waveform used to calculate the switching times has

a minimum value of −12Vdc and a maximum value of +1

2Vdc and has a period of T = 1

fsw.

For the calculation of the switching times it is assumed that at t = 0 the carrier has a

value of Ftriang = +Vdc

2. The first switching time for phase a, t1a, occurs in the range

t1a ∈[

0, 12fsw

]

. The equation of the carrier waveform, with a negative slope, over the

interval ∆t ∈ [0, 12fsw

] is shown in (3.4). The sampled value of the vrefta waveform at t = 0

can be calculated from (3.5),

Ftriang =Vdc

2(1−∆t · 4fsw) where, ∆t ∈

[

0, 12fsw

]

(3.4)

Page 30: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 3. Voltage Source Converter Harmonic Model 24

vta(0) = maVdc

2cos

(

δ + ∠v+1sαβ(0)

ωL

)

(3.5)

If (3.4) is equated to (3.5) and ∆t is isolated for, the result can be used to solve for t1a

as is shown in (3.6),

t1a =∆t (3.6a)

t1a =1

4fsw(1 + vta(0)) (3.6b)

The second switching time for phase a, t2a, occurs during the next half-cycle of the

triangular waveform, for which the carrier has a positive slope. This second switching

time for phase a, occurs in the range t2a ∈[

1fsw

, 22fsw

]

. To solve for this switching time,

it is convenient to shift vta(0) forward in time by t = 12fsw

and then to solve for the time

∆t at which that the carrier and the time-shifted vta intersects. Once, this time is found,

a time offset of t = 12fsw

, is added to solve for t2a.

Ftriang = −Vdc

2(1−∆t · 4fsw) where, ∆t ∈

[

0, 12fsw

]

(3.7)

vta

(

12fsw

)

= maVdc

2cos

(

δ + ∠v+1sαβ(0)

ωL

+1

2fsw

)

(3.8)

If (3.7) is equated to (3.8) and ∆t is isolated for, the result can be used to solve for t2a

as is shown in (3.9),

t2a =∆t+1

2fsw(3.9a)

t2a =1

4fsw

(

1− vta

(

12fsw

))

+1

2fsw(3.9b)

This analysis can be extended to solve for all 2mf switching times for the control of the

voltage at the phase a terminal, as is shown in (3.10). The generalization is done through

Page 31: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 3. Voltage Source Converter Harmonic Model 25

adding the integer variable i to the above equations, where i ∈ [1, 2, 3, . . . , 2mf ],

Ftriang =(−1)iVdc

2(∆t · 4fsw − 1) where, ∆t ∈

[

0, 12fsw

]

(3.10a)

vta

(

i− 1

2fsw

)

=maVdc

2cos

(

δ + ∠v+1sαβ(0) +

i− 1

2fsw

)

(3.10b)

tia =1

4fsw

(

1 + (−1)i−1vta

(

i− 1

2fsw

))

+i− 1

2fsw(3.10c)

Once the switching times for all three-phases are calculated, they are combined into a

vector and the vector is sorted. From this, the 6mf switching times and switch states for

an entire steady-state period are known. The input vector ~u is rotated in time such that

it lines up with the first calculated switching time of the sorted vector, which is t1. This

is done as follows,

~u(t1) = Rt1~u(0) (3.11)

3.4.3.3 Time Derivatives of Converter States

The topology assumed for the VSC harmonic model has 3 independent switches, Sa, Sb

and Sc. Because each switch has 2 states, on or off, there are 8 unique configurations

of the VSC topology. For the M matrices that describe the VSC harmonic model, the

values of the A and B submatrices are dependent on the states of the converter switches,

whereas the other submatrices C, D and E are dependent on the mathematical properties

of the converter states. Because, the C, D and E submatrices were previously derived

in Section 2.3, only the A and B submatrices are discussed here. To calculate A and

B, the time-derivatives of the isα, isβ and vdc converter states of the VSC topology are

derived. The time derivatives are presented in (3.12), the detailed derivation of the

Page 32: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 3. Voltage Source Converter Harmonic Model 26

time-derivatives can be found in Appendix A.1,

disαdt

=− R

Lisα − 1

L

[

1 0 0]

C

Sa

Sb

Sc

vdc +1

Lvsα (3.12a)

disβdt

=− R

Lisα − 1

L

[

0 1 0]

C

Sa

Sb

Sc

vdc +1

Lvsβ (3.12b)

dvdcdt

=1

Cdc

[

Sa Sb Sc

]

C−1

1 0

0 1

0 0

[

isα

isβ

]

− 1

RdcCdcvdc −

1

Cdcidc (3.12c)

where, Sa, Sb, Sc are binary values. As an example, if switch Sa, is conducting and Sb

and Sc are not conducting: Sa = 1, Sb = 0, Sc = 0. And C refers to the Clarke Transform

as shown in (3.13),

C =

2/3 −1/3 −1/3

0 1/√3 −1/

√3

√2/3

√2/3

√2/3

(3.13)

The time-domain variables vsα, vsβ, idc are provided as inputs to the VSC harmonic

model. As such, (3.12) can be equivalently defined by substituting (3.14) in for vsα, vsβ

and idc of (3.12).

vsα =v−hsα + v−(h−1)

sα + · · ·+ v+hsα (3.14a)

vsβ =v−hsβ + v

−(h−1)sβ + · · ·+ v+h

sβ (3.14b)

idc =Idc + i1dc + i2dc + · · ·+ imdc (3.14c)

where, the variables of (3.14) can be expressed in terms of the input vector ~u by substi-

tuting (2.3) and (2.4) into (3.14), as is shown here for an arbitrary integer k,

vksα =Re(

V ksα + jV k

)

ejkωLt (3.15a)

vksβ =Im(

V ksα + jV k

)

ejkωLt (3.15b)

ikdc =ReIkdcejkωLt (3.15c)

Page 33: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 3. Voltage Source Converter Harmonic Model 27

Submatrix A can be directly extracted from (3.12) as shown in (3.16a). If (3.14) is

substituted in (3.12), submatrix B can be extracted from the resulting expression as is

shown in (3.16b).

A =

−R

L0 −1/3

L(2Sa − Sb − Sc)

0 −R

L−√3/2

L(Sb − Sc)

1

Cdc(Sa −

1

2Sb −

1

2Sc)

√3/2

Cdc(Sb − Sc) − 1

RdcCdc

(3.16a)

B =

1

L0 · · · 1

L0 0 0 0 · · · 0 0

01

L· · · 0

1

L0 0 0 · · · 0 0

0 0 · · · 0 0 − 1

Cdc− 1

Cdc0 · · · − 1

Cdc0

(3.16b)

By substituting the appropriate values of Sa, Sb, and Sc into the A and B submatrices,

all 8 possible configurations of the VSC topology can be modelled through substituting

(3.16) into the M matrices derived in Section 2.3. The Φ matrix for the VSC topology

can be formulated as follows:

Φ =

6mf−1∏

k=1

eMk(tk+1−tk) (3.17)

where, because there are only 8 possible converter configurations with the assumed VSC

model,

∀(M1,M2, . . . ,M6mf) ∈ [M1,M2, . . . ,M8] (3.18)

The procedure of extracting the FCM from the Φ of (3.17) was discussed in Section 2.3.

Assuming that the FCM is known, the output vector ~y, can be calculated as is shown in

(3.19),

~y(0) = R(−t1)[FCM]~u(t1) (3.19)

3.4.3.4 Summary

In this section, the FCM was derived for the VSC harmonic model. It was also shown

how the switching times and switch states are calculated for the assumed sample-and-

hold sinusoidal PWM scheme. Furthermore, it was shown how the time-derivatives of

the state variables are solved for and how they are used to formulate the FCM.

Page 34: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 3. Voltage Source Converter Harmonic Model 28

3.4.4 Evaluation of Constraint Equations

In this section, the constraint equations of the VSC harmonic model are derived. The

two constraint equations imposed on the VSC harmonic model are outlined in (3.20),

∆Vdc = 0 (3.20a)

= Vdc − V refdc (3.20b)

∆Qac = 0 (3.20c)

= Qac −Qrefac (3.20d)

where, ∆Vdc and ∆Qac are equal to the difference between the calculated value and the

input reference value of the average dc-link voltage and reactive power absorbed by the

converter, respectively.

Calculating Vdc

The average value of the dc-link voltage, Vdc, can be extracted from the output vector

~y(t1) as is shown in (3.21),

Vdc =[

0 · · · 0 1 0 · · · 0]

~y(t1) (3.21)

where, the ‘1’ is located at index 4h+ 3, which is the index for Vdc in ~y(t1).

Eqn. (3.21) can be equivalently expressed as is shown in (3.22),

Vdc = PVdc~y(t1) (3.22)

In this thesis, the vectors P[state], can be assumed to have the format:[

0 · · · 0 1 0 · · · 0]

;

with the ‘1’ located at an index such that the state referenced in the subscript of P[state],

is extracted.

Calculating Qac

The reactive power absorbed by the converter, Qac, is the imaginary component of the

three phase complex power of the converter. An equation for calculating the reactive

Page 35: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 3. Voltage Source Converter Harmonic Model 29

power is shown in (3.23),

Qac =1

2Imv1sai

1∗

sa + v1sbi1∗

sb + v1sci1∗

sc (3.23)

The result of converting the states of (3.23) from abc to positive and negative sequence

components at the line frequency is shown in (3.25). The symmetric matrix of (3.24)

was used to perform this change of reference frame.

S =

1 1 1

1 ej4π3 ej

2π3

1 ej2π3 ej

4π3

(3.24)

Q =3

2Imv+1

sαβi+1∗

sαβ + v−1sαβi

−1∗

sαβ (3.25)

Eqn. (3.26) is the result of expanding (3.25) into αβ components, and then isolating the

imaginary values,

Q =3

2(v+1

sβ i+1sα + v−1

sβ i−1sα − v+1

sα i+1sβ − v−1

sα i−1sβ ) (3.26a)

=3

2(Pv+1

sβ~u(t1)Pi+1

sα+ Pv−1

sβ~u(t1)Pi−1

sα− Pv+1

sα~u(t1)Pi+1

sβ− Pv−1

sα~u(t1)Pi−1

sβ)~y(t1) (3.26b)

3.4.5 Control Parameter Update

If the constraint requirements are not met, the control parameters, ma and δ, are updated.

A Newton-Raphson technique is used to update the parameters as is shown in (3.27),

[

ma

δ

]

i+1

=

[

ma

δ

]

i

+ J−1 ~M (3.27)

where, ~M is a vector containing the constraint equations and J is an exact Jacobian with

the following structure,

J =

dVdc

dma

dVdc

dδdQac

dma

dQac

(3.28)

Page 36: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 3. Voltage Source Converter Harmonic Model 30

Where,

dVdc

dma

=PVdc

d(FCM)

dma

~u(t1) (3.29a)

dVdc

dδ=PVdc

d(FCM)

dδ~u(t1) (3.29b)

dQac

dma

=3

2

(

Pv+1

sβ~u(t1)Pi

+1sα

+ Pv−1

sβ~u(t1)Pi

−1sα

− Pv+1sα~u(t1)Pi

+1

sβ− P

v−1sα~u(t1)Pi

−1

) d(FCM)

dma

~u(t1) (3.29c)

dQac

dδ=3

2

(

Pv+1

sβ~u(t1)Pi

+1sα

+ Pv−1

sβ~u(t1)Pi

−1sα

− Pv+1sα~u(t1)Pi

+1

sβ− P

v−1sα~u(t1)Pi

−1

) d(FCM)

dδ~u(t1) (3.29d)

The exact Jacobian entries of (3.28) are found in the VSC source code which is located

in Appendix B.2.1.

3.4.6 Summary of Approach

In summary, the harmonic model of the VSC is derived in this section. The output vector

~y is solved by using an iterative approach to converge on the unique set of switching times

that result in the constraint equations, imposed on the VSC, to be met.

3.5 Summary of Chapter

In this chapter, the harmonic model of the VSC is presented. In this presentation,

the VSC topology, modes of operation, and the control scheme assumed for the VSC

harmonic model were described. This was followed by a detailed description of how the

harmonic model was derived.

Page 37: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4

Line Commutated Converter

Harmonic Models

4.1 Introduction

The purpose of this chapter is to describe the line commutated converter harmonic models

developed in this thesis. In particular, this chapter focuses on describing the assumed

topologies, modes of operation and the derivation of the harmonic models. The following

four line-commutated converters are modelled in this thesis: 6-pulse thyristor converter,

6-pulse diode converter, 12-pulse thyristor converter and the 12-pulse diode converter.

The first section of this chapter discusses the differences between the line commutated

converter harmonic models and the VSC harmonic model and how these differences

effect the derivation of the FCM. The next section, outlines the assumed 6-pulse and

12-pulse topologies and the modes of operation. Then, the control scheme is discussed

for the thyristor switched converter models. Finally, the approach to deriving the four

line commutated harmonic models is discussed; which is followed by a summary of the

chapter.

4.2 Overview of Harmonic Models

As opposed to the VSC model, where the unknown dc-side state is the dc-link voltage, in

the line commutated converter models the unknown dc-side state is the dc-side current.

This is because of the assumed dc-side configuration for all line commutated converters

of this thesis, shown in Fig. 4.1. The FCM for the line commutated converter is derived

31

Page 38: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 32

such that it maps the input vector to the output vector as shown in (4.1).

ac

dc

vs vdcRdc

Ldc

is idc

Figure 4.1: Block Diagram of Line Commutated Converter Harmonic Models

[

~is~idc

]

= [FCM][

~vs

]

(4.1)

Where, ~vs is a vector containing the positive and negative sequence harmonics of the PCC

voltage at time t expressed in the space-vector reference frame. ~is is a vector containing the positive and negative sequence harmonics of the ac-side

phase currents at time t expressed in the space-vector reference frame. ~idc is a vector containing the real and imaginary components of the dc-side current

harmonics at time t.

For the modelled line-commutated converters, the time-derivative of the state-variables

can be represented by (4.2).

d

dt

~x

~u

~y

Mk

~x

~u

~y

(4.2)

where,

Page 39: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 33

~x =

isα

isβ

idc

, ~u =

v−hsα

v−hsβ...

v+hsα

v+hsβ

, and ~y =

i−hsα

i−hsβ...

i+hsα

i+hsβ

Idc

ReI1dcejωLtImI1dcejωLt

...

ReImdcejmωLtImImdcejmωLt

where, isα is specified in the time-domain and is the α-component of the ac-side currents

represented in space-vector format. isβ is specified in the time-domain and is the β-component of the ac-side currents

represented in space-vector format. idc is specified in the time-domain and is the dc-side current.

It is important to re-iterate that the derivation of the submatrices C, D, and E of the

M matrices are dependant only on the mathematical properties of the ~u and ~y vector

elements. The differences between the ~u and ~y in (4.2) and the ~u and ~y used to define C,

D, and E in (2.10), is i) the swapping of the vector ~vdc for~idc in ~y and ii) the elimination

of vector~idc from ~u. In order to determine how the submatrix D and E derived in Section

2.3 for the VSC, can be modified for the line commutated converter, the time derivatives

of the elements of vectors ~vdc and ~idc are compared here. Expanding out time-domain

states idc and vdc into separate frequency components,

idc =Idc + ReI1dcejωLt + · · ·+ Im

dcejmωLt (4.3a)

vdc =Vdc + ReV 1

dcejωLt + · · ·+ V

m

dcejmωLt (4.3b)

Page 40: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 34

Taking the time-derivative of the expressions for idc and vdc in (4.3), yields (4.4),

idcdt

=− ωLImI1dcejωLt − · · · −mωLImImdcejωLt (4.4a)

vdcdt

=− ωLImV 1

dcejωLt − · · · −mωLImV m

dcejωLt (4.4b)

Equation (4.4) shows that the time-derivative of each element in vectors ~vdc and ~idc

vectors is equal to some harmonic multiple multiplied by the quadrature component

of that respective element. From this analysis, it can be concluded that the D and E

submatrices derived in Section 2.3 is also applicable and identical for the line-commutated

converters. The D and E matrices are repeated in (4.5) for convenience purposes.

D =

1/T 0 0

0 1/T 0...

1/T 0 0

0 1/T 0

0 0 1/T...

0 0 1/T

(4.5a)

E =

0 +hω

−hω 0. . .

0 −mω

+mω 0

(4.5b)

The C submatrix for the line commutated converters, shown in (4.5), is similar to the one

derived for the VSC but with the elimination of the states involving vector ~vdc. Therefore,

the C submatrix for the line commutated converter harmonic models is shown here in

(4.6).

C =

0 +hω

−hω 0. . .

0 −hω

+hω 0

(4.6)

Page 41: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 35

The next two sections describe how the A and B submatrices are solved, for the 6-pulse

and 12-pulse line-commutated converters.

4.3 Assumed Topologies and Modes of Operation

4.3.1 6-Pulse Converter

The harmonic models developed for the 6-pulse thyristor and diode converter topologies

assume the 6-pulse topology shown in Fig. 4.2. The inputs to the 6-pulse converter

Rdc

Ldc

Pdc, idc

vdc

R

L

RR

L L

isbisc isa

vsa

vsb

vsc

2

13

4

5

6

Figure 4.2: General 6-Pulse Converter

topologies are the following: vector ~vs; Pdc, the average power absorbed by the dc-side

of the converter; and the impedances R, L and Ldc. In addition to these inputs, for the

thyristor-switched harmonic model, there is an additional input: Vdc, the average voltage

across the dc-side of the converter. The outputs of these harmonic models are the vectors

~is and ~idc.

The operation mode of the 6-pulse line-commutated converter models, derived in this

thesis, is restricted to continuous conduction mode. Furthermore, it is assumed that

Page 42: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 36

Table 4.1: Gating Sequence for 6-Pulse Converter

Gated Conducting Switches Conducting SwitchesSwitch During Commutation During Conduction

1 1, 5, 6 1, 62 6, 2, 1 2, 13 2, 3, 1 2, 34 2, 4, 3 4, 35 4, 3, 5 4, 56 4, 6, 5 6, 5

each gating pulse—or alternatively said, when the next switch in the sequence begins to

conduct current—is followed by an interval of 3-valve commutation of length equal to the

overlap angle µ which is then followed by an interval of 2-valve conduction of length γ−µ.

For the thyristor-switched converter, γ = π/3; however, for the diode-switched converter,

γ = π/3, only under balanced conditions. Since, no simplifying assumptions are made

about the PCC voltages, a unique µ and γ are assigned to each gating pulse. Given these

assumptions, there are 12 configurations of the 6-pulse converter during steady-state: 6

commutation configurations and 6 conduction configurations.

In distribution systems, PCCs are dominated by the positive sequence line-frequency

voltage component. Given this, the sequence of the gating pulses can be mapped out

for an entire steady-state period. The sequence is identical for the diode-switched and

thyristor-switched converter. The diode-switched converters are uncontrolled and the

sequence naturally results for a positive sequence line-frequency dominated PCC. For

the thyristor-switched converter, the sequence results due to the assumed control scheme.

The gating sequence for the 6-pulse converter, using the gating of switch 1 in Fig. 4.2

as a point of reference, is shown in Table 4.1 and graphically illustrated in Fig. 4.3.

The “Conducting Switches During Commutation” column in Table 4.1 references the

switches that conduct during the commutation interval immediately following the gating

of the switch referenced in the “Gated Switch” column of that row. The “Conducting

Switches During Conduction” column in Table 4.1 references the switches that conduct

immediately following the commutation interval that follows the gating of the switch

referenced in the “Gated Switch” column of the row.

Page 43: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 37

t1+Tt1t

S1

S2

S3

S4

S5

S6

γ1µ1

γ2µ2

γ3µ3

γ4µ4

γ5µ5

γ6µ6

Figure 4.3: Switching Scheme for 6-Pulse Converter

4.3.2 12-Pulse Converter

The 12-pulse thyristor and diode converter harmonic models developed in this thesis are

based on the 12-pulse converter topology shown in Fig. 4.4. The inputs to the 12-pulse

converter topology are the same as in the 6-pulse converter topology, but are repeated

here for convenience: vector ~vs, Pdc and the impedances R, L and Ldc. In addition to

these inputs, for the thyristor-switched harmonic model, the Vdc reference is provided as

an input as well. The outputs of these harmonic models are the vectors ~is and ~idc.

For the 12-pulse line-commutated converter models developed in this thesis it is as-

sumed that the operation mode is restricted to continuous conduction mode. Further-

more, it is assumed that each gating pulse—or alternatively when the next switch in the

sequence begins to conduct—is immediately followed by a 5-valve commutation interval

of length equal to the overlap angle µ which is then followed by a 4-valve conduction

Page 44: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 38

Rdc

Ldc

Pdc, idc

D

sai

D

sbi

D

sci

Y

sai

Y

sbi

Y

sci

vdc

vsc vsb vsa

saisbisci

1

11

10

9

8

7

6

5

4

3

2

12

R L

R L

R L

R L

R L

R L

Yp

sai

Yp

sbi

Yp

sci

p

saiD

p

sbiD

p

sciD

1:1

1:1

Figure 4.4: 12-Pulse Converter Topology

interval of length γ − µ. For the thyristor-switched converter, γ = π/6; however, for the

diode-switched converter, γ = π/6, only under balanced conditions. Since, no simplify-

ing assumptions are made about the PCC voltages, a unique µ and γ is assigned to each

gating pulse.

The 12-pulse converter topology is interfaced to the PCC through a Y-Y and a Y-

∆ transformer. It is assumed that the secondary side of the Y-∆ transformer lags the

primary by 30. Like the 6-pulse topology, it is assumed that the PCC is dominated

by the positive sequence line-frequency voltage component. Given this, the sequence of

the gating pulses can be readily calculated and mapped out for the entire steady-state

independent of the converter states. The gating sequence is defined with respect to the

zero-crossings of the positive sequence line-frequency component of the PCC. The firing

Page 45: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 39

Table 4.2: Gating Sequence for 12-Pulse Converters

Gated Conducting Switches Conducting SwitchesSwitch During Commutation During Conduction

1 11, 9, 1, 12, 10 11, 1, 12, 102 11, 1, 12, 10, 2 11, 1, 12, 23 11, 3, 1, 12, 2 3, 1, 12, 24 3, 1, 12, 4, 2 3, 1, 4, 25 3, 5, 1, 4, 2 3, 5, 4, 26 3, 5, 4, 6, 2 3, 5, 4, 67 3, 7, 5, 4, 6 7, 5, 4, 68 7, 5, 4, 8, 6 7, 5, 8, 69 7, 5, 9, 8, 6 7, 9, 8, 610 7, 9, 8, 6, 10 7, 8, 9, 1011 11, 7, 9, 8, 10 11, 9, 8, 1012 11, 9, 12, 8, 10 11, 9, 12, 10

sequence for the 12-pulse topology, using the gating of switch 1 in Fig. 4.4 as a point of

reference, is shown in Table 4.2.

4.4 Control Scheme for Thyristor-Switched Converter

The average dc-side voltage, Vdc, of the thyristor-switched converters is set by the con-

verter firing angle, α; which is the time delay of the gating signals sent to the thyristors

(α is measured in degrees). The control scheme assumes equidistant firing, i.e. the fir-

ing angle is the same for each gating pulse. At α = 0, the average voltage, Vdc is at a

maximum value. As α increases from 0, this average voltage decreases.

For the 6-pulse topology, α is defined with respect to the zero crossings of the line-line

positive sequence line-frequency component of the PCC voltage. There are 6 gating pulses

sent per period as is graphically illustrated in Fig. 4.8. For the 12-pulse thyristor, there

is a Y-Y and Y-∆ transformer interconnecting the PCC to the converter. The voltages

on the secondary of the Y-∆ transformer lag the PCC voltages by 30; therefore, for the

12-pulse topology α is defined with respect to the zero crossings of the line-line and the

line-neutral positive sequence line frequency component of the PCC voltage (the line-

neutral voltages lag the line-line voltages by 30). For illustrative purposes, if the firing

angle of the converter is assigned to α = 10, then exactly 10 after each of the zero

Page 46: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 40

crossings, the gating pulse is sent.

As discussed in Section 4.3, the time interval between successive gating pulses is fully

specified by two control parameters, γ and µ. Where, γ2πfL

is the total time between

successive gating pulses, and µ2πfL

is the length in time of the commutation interval that

immediately follows the gating pulse. For the thyristor-switched converters, γ is fixed

due to the equidistant firing control scheme assumed and therefore γ = π/32πfL

and γ = π/62πfL

for the 6-pulse and 12-pulse topologies, respectively.

4.5 Harmonic Modelling Approach

4.5.1 Introduction

The harmonic modelling approach used to solve for the thyristor and diode line commu-

tated converter models is outlined in Fig. 4.5. For the thyristor converter, the control

parameters, µ and α, are iteratively solved for such that the converter operates as defined

in Section 4.3 with the calculated Pdc and Vdc matching the input references. For the

diode converter, the control parameters, µ, γ, t1, as well as Rdc are iteratively solved

for such that the converter operates as defined in Section 4.3 with the calculated Pdc

matching the input reference. Note, t1 is defined as the time instant that the gating

pulse is sent switch 1; t1 is described in more detail in Section 4.5.5.

In solving for the harmonic models of the line commutated converters there are two

loops employed an outer and an inner loop, as shown in Fig. 4.5. The outer loop is used

to improve the percentage of simulations that converge to a valid solution. The inner

loop is used to find the control parameters of the converter that result in the constraint

equation requirements being met.

Page 47: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 41

Initialize Control ParametersInitialize Control Parameters

Have Constraint Requirements

Been Met?

Calculate FCMCalculate FCM

alculate Switching InstantsCalculate Switching Instants Update Control ParametersUpdate Control Parameters

No

Read in Inputs

Output y(0)

Calculate Exact JacobianCalculate Exact Jacobian

Rotate u(0) Forward by t = t1Rotate u(0) Forward by t = t1

Rotate y(t1) Backward by t = t1Rotate y(t1) Backward by t = t1

k = k + 2k = k + 2

Set k = 1Set k = 1

Is k < h? Yes

Evaluate Constraint EquationsEvaluate Constraint Equations

Yes

Inner Iterative Loop

Figure 4.5: Line Commutated Converter Harmonic Modelling Approach

4.5.2 Control Parameter Initialization

4.5.2.1 Introduction

Before the outer control loop is entered, the control parameters are initialized using an

analytical approach. In initializing the control parameters, the following assumptions are

made: Negligible harmonic distortion on PCC

Page 48: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 42 Balanced PCC voltages Ldc is infinite

Under these assumptions, there is pulse symmetry, i.e. µ and γ for each gating pulse is

equivalent. As such there are only two unknowns to solve for, µ and γ.

4.5.2.2 Thyristor-Switched Converter

The control parameters to initialize for the thyristor-switched converters are the firing

angle α and overlap angle µ. Fig. 4.6 outlines the approach used in initializing these

parameters and a detailed description of the approach can be found in Appendix A.4.2.1.

Initialize α = 0.1

Calculate µ

Calculate Pdc

Update α

Is | |

< 10-5?

Output

µ and α

Calculate Jacobian

addPdcref

dcdc PP -

Figure 4.6: Initializing Control Parameters α and µ

The resulting values for control variables µ and α from the iterative process outlined

in Fig. 4.6 are used as the initialization values.

4.5.2.3 Diode-Switched Converter

The control parameters to initialize for the diode-switched converters are the overlap

angle µ, switching time of switch 1, t1, dc-side resistance, Rdc, and γ. The initial estimates

of the γ and t1 control parameters are directly calculated, whereas an iterative approach

is required to initialize µ and Rdc. Fig. 4.7 outlines the iterative approach used in

Page 49: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 43

Initialize µ = 0.1

Calculate Pdc

Update µ

Is | |

< 10-5?

Output

µ, Rdc

Calculate Jacobian

mddPdc

Calculate Rdc

ref

dcdc PP -

Figure 4.7: Initializing Control Parameters α and µ

initializing µ and Rdc and a detailed description of the approach for initializing all 4

control parameters can be found in Appendix A.4.2.2.

The resulting values for control variables γ and t1 and for Rdc and µ, from the iterative

process outlined in Fig. 4.7, are used as the initialization values.

4.5.3 Outer Iterative Loop

Since a Newton-Raphson based approach is used to update the control parameters, it is

important to have an accurate initial estimate of the switching times to ensure conver-

gance. Harmonic distortion on the PCC can have a significant influence on the switching

times of the line commutated converter models. As such, to improve the accuracy of the

initial estimate of the switching times when harmonic distortion on the PCC exists, an

outer iterative loop is implemented. The input vector ~vs includes the Fourier coefficients

of the PCC phase voltages for harmonic multiples −h,−(h−1), · · · ,+h. Using the outer

control loop, the converter model is first solved for a modified input vector that contains

the harmonic multiples −1, 0,+1 from the original input vector ~vs—using the initialized

values of the control parameters. Once the converter model converges to a solution, the

switching times used to solve for the final iteration of the solution, are then provided

as input to the next iteration of this outer iterative loop. In the following iterations,

Page 50: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 44

the system is solved with an expanded modified input vector with harmonic multiples

−k,−k+1, · · · , k−1, k, again, obtained from the original input vector ~vs. Each iteration

adds two more harmonic multiples to the modified input vector (k = k + 2), until the

solution for all harmonics −h,−(h − 1), · · · ,+h is solved for. Note, the outer iterative

loop is used to improve the rate of convergence in highly distorted systems and therefore

is not needed to analyze every power system.

4.5.4 Inner Iterative Loop

In the inner iterative loop, the converter harmonic model is solved for with the con-

trol parameters solved for in previous iteration of the outer iterative loop. The steps

performed in the inner iterative loop are as follows:

1. First, the switching times of the converter are calculated given the control param-

eter values.

2. Then, the input vector ~u is rotated with respect to time such that it exactly aligns

with when the gating signal is sent to switch 1. Refer back to (2.5) to see how this

rotation is performed.

3. Then, using the calculated switching times in conjunction with the sequence of the

converter states shown in Table 4.1, for the 6-pulse converter, and Table 4.2 for the

12-pulse converter, the FCM is calculated.

4. Then, the constraint equations, specific to the converter model, are evaluated.

5. Finally, if the constraint equations meet the convergence requirements of the con-

verter which is 0.001 pu then the inner control loop is exited and the next iteration

of the outer control loop begins. Otherwise, the next iteration of the inner control

loop is performed with the updated control parameters.

4.5.5 FCM Derivation

4.5.5.1 Introduction

In deriving the FCM for the line commutated converter models, the switching times and

switch states are first calculated. They are entirely specified from the control parameter

values of the converter. Using these switching times and the switch states, the Φ matrix

Page 51: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 45

derived in (2.12), can be calculated; from which, the FCM can be extracted. As such,

in this section, the approach to calculating the switching times and switch states is first

discussed. Then, the derivation of the time-derivatives of the converter states is discussed.

Both the switching information and time-derivatives of the converter state equations are

used to calculate the FCM of the converter.

4.5.5.2 Switching Times

The 6-pulse converter topologies have 13 unique switching times and the 12-pulse topolo-

gies has 25 unique switching times. The switching time calculations involve using t1, as

well as the γ and µ associated with each gating interval. The switching instant asso-

ciated with the gating of switch 1, t1, is calculated differently depending on whether it

is a diode or thyristor switched converter. For the thyristor switched converters, t1 is

calculated relative to the zero-crossings of the line-to-line positive-sequence component

of the PCC voltage; whereas for the diode switched converters, t1 is calculated relative

to the zero-crossings of the line-to-line voltage directly at the terminals of the converter.

The calculation of t1 for the diode and thyristor switched converters is first discussed.

This is followed by a discussion of how the other switching times are calculated.

Calculating t1 for Thyristor-Switched Converter

The firing angle, α, determines when the gating signals are sent to the thyristor switches.

Switch 1 is gated at α degrees after the zero crossing of v+1sbc which coincides with the

intersection of v+1sab and v+1

sac. As shown in Fig. 4.8, this corresponds to α degrees after

∠v+1sαβ = 0 (or alternatively at ∠v+1

sa = α). Since ~u(0) is originally specified at time t = 0,

for the thyristor-switched converters, t1 is calculated as shown in (4.7),

t1 =α− ∠v+1

sαβ(0)

2πfL(4.7)

Calculating t1 for Diode-Switched Converter

For the diode switched converters, the switching times are calculated relative to the zero-

crossings of line-line voltages at the terminal of the converter. The terminal voltages

depend on the converter currents, which are the desired, unknown, states that are being

solved for. As such, the switching time t1 must be analytically solved for like the γ and

Page 52: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 46

µ. This is why a calculation for the initialization of t1 was shown in the previous section.

The switching times for the 6-pulse diode converter are graphically illustrated in Fig. 4.9.

Given that at the beginning of each iteration of the inner iterative loop, t1, µ and γ

are known in addition to the gating sequence of all switches, all the switching times for

a steady-state period can be calculated. For illustrative purposes, the switching times

for the 6-pulse topology are solved here in (4.8). The switching times for the 12-pulse

topology are similarly calculated. These switching times are shown in the graphs of Fig.

4.9 and Fig. 4.8, for the diode and thyristor switched converters, respectively.

t2 =t1 +µ1

2πfL(4.8a)

t3 =t1 +γ1

2πfL(4.8b)

t4 =t3 +µ2

2πfL(4.8c)

t5 =t3 +γ2

2πfL(4.8d)

... (4.8e)

t12 =t11 +µ6

2πfL(4.8f)

t13 =t11 +γ6

2πfL(4.8g)

Page 53: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 47

v+1

sabv+1

sbcv+1

sbav+1sca

v+1

scbv+1

sabv+1sac

t = 0

v+1sac

v+1sa

t7t5t3 t9t11 t13t1

α

Figure 4.8: Switching Times for Thyristor-Switched 6 Pulse Converter

Page 54: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 48

t = 0

vtcavtbcvtac

vtabvtbc

vtbavtcb

t

t1 t2 t3 t5 t6 t7 t8 t9 t10t4 t11 t12 t13

Figure 4.9: Switching Times for Diode-Switched 6 Pulse Converter

Page 55: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 49

4.5.5.3 Time Derivatives of Converter States

For all 4 line-commutated converter harmonic models, a unique M matrix is calculated

for each possible circuit configuration. Therefore, as an example, because the 6-pulse

converters have 12 different configurations, 12 M matrices are calculated. The following

subsections present the A andB submatrices that are used to calculate theM matrices for

a few representative configurations of the 6-pulse converter and for the 12-pulse converter.

4.5.5.3.1 6-Pulse Converter

For the 6-pulse converters there are 12 unique configurations: 6 conduction configurations

and 6 commutation configurations. The approach to solving the A and B submatrices for

each of these configurations is similar; as such, the A and B submatrices are solved here

for two circuit configurations. The A and B submatrices for the other 10 configurations

can be solved similarly.

Differential Equations for Sample Commutation Interval

The commutation converter configuration that immediately follows the gating of switch

1 is shown in Fig. 4.10. In this configuration only switches 5, 6 and 1 of the original

configuration in Fig. 4.2 are conducting. The A and B submatrices that describe this

Rdc

Ldc

idc

R

R L

Lisb

isc

isa

-vsb+

-vsc+

-vsa+R L

vdc

Figure 4.10: 6-Pulse Converter 3-Valve Commutation After Gating of Switch 1

Page 56: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 50

configuration are shown in (4.9). These submatrices are derived in Appendix A.2.1.

A =

−3R + 2Rdc

3L+ 2Ldc0 0

0 −R/L 0

1

L+ Ldc

(

3/2RL+RdcL

3L+ 2Ldc− R

2

)

0 −R +Rdc

L+ Ldc

(4.9a)

B =

3

3L+ 2Ldc0 · · · 3

3L+ 2Ldc0

01

L· · · 0

1

L3/2

L+ Ldc

(

1− 1

3L+ 2Ldc

)

0 · · · 3/2

L+ Ldc

(

1− 1

3L+ 2Ldc

)

0

(4.9b)

Differential Equations for Sample Conduction Interval

The conduction converter configuration that immediately follows the commutation inter-

val that follows the gating of switch 1 is shown in Fig. 4.11. In this configuration only

switches 6 and 1 of the original configuration in Fig. 4.2 are conducting. The A and B

Rdc

Ldc

idc

vdc

R L

R Lisc

isa

vsc

vsa

Figure 4.11: 6-Pulse Converter 2-Valve Conduction After Gating of Switch 1

submatrices that describe this configuration are shown in (4.10). These submatrices are

derived in Appendix A.2.2.

Page 57: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 51

A =− 2R +Rdc

2L+ Ldc

1 0 0

0 1 0

0 0 1

(4.10a)

B =1

2L+ Ldc

3/2√3/2 · · · 3/2

√3/2

−√3/2 −1/2 · · · −

√3/2 −1/2

3/2√3/2 · · · 3/2

√3/2

(4.10b)

In this section, the A and B submatrices of the 6-pulse converter are outlined for the

commutation and conduction configurations that describe the time interval between the

gating of switch 1 and switch 2. The other A and B submatrices for the other 10 circuit

configurations are derived similarly.

4.5.5.3.2 12-Pulse Converter

For the 12-pulse converters there are 24 unique circuit configurations: 12 conduction

configurations and 12 commutation configurations. The approach to solving the A and

B submatrices for each of these configurations is similar; as such, theA and B submatrices

are solved here for 3 of the 24 circuit configurations. The A and B submatrices for the

other 21 configurations can be solved similarly.

Differential Equations for Sample Commutation Interval 1

The commutation configuration that immediately follows the gating of switch 1 of Fig.

4.4 is shown in Fig. 4.12. In this configuration switches 11, 9, 1, 12 and 10 are conducting

current. The A and B submatrices that describe this configuration are shown in (4.11).

Page 58: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 52

R L

R L

Rdc

Ldc

idc

Y

sbi

Y

scivdc

R L

R L

s

saiD

s

sbiD

vsc

vsb

sav3

s

sb

s

sc ii DD ,

R LY

saivsa

scv3

sbv3

s

saiD

Figure 4.12: 12-Pulse Converter 5-Valve Commutation After Gating of Switch 1

These submatrices are derived in Appendix A.3.3.

A =−

0 0(

1− 2/√3) 7/2R +Rdc

7/2L+ Ldc

0 R/L R/L

0 07/2R +Rdc

7/2L+ Ldc

(4.11a)

B =

−1/2

7/2L+ Ldc0 · · · −1/2

7/2L+ Ldc0

0 1/L · · · 0 1/L

3/2 +√3 0 · · · 3/2 +

√3 0

(4.11b)

Differential Equations for Sample Conduction Interval

After switch 1 is gated, there is a commutation interval which is followed by a conduction

interval. The configuration corresponding to this conduction interval is shown in Fig.

4.13. In this configuration switches 1, 11, 12 and 10 of Fig. 4.4 are conducting current.

The A and B submatrices that describe this configuration are shown in 4.12. The

Page 59: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 53

R L

R L

Rdc

Ldc

idcY

sai

Y

sci

vdcR L

R L

D

sai

s

saiD

vsc

vsa

sav3

s

sb

s

sc iiDD ,

scv3

sbv3

Figure 4.13: 12-Pulse Converter 4-Valve Conduction After Gating of Switch 1

derivation of these submatrices is outlined in Appendix A.3.2.

A =− 4R +Rdc

4L+ Ldc

0 0 1 + 2/√3

0 0 1/√3

0 0 1

(4.12a)

B =1

4L+ Ldc

7/2 + 2√3 1 +

√3/2 · · · 7/2 + 2

√3 1 +

√3/2

1 +√3/2 1/2 · · · 1 +

√3/2 1/2

3/2 +√3

√3/2 · · · 3/2 +

√3

√3/2

(4.12b)

Differential Equations for Sample Commutation Interval 2

The commutation configuration immediately following the gating of switch 2 is shown

Fig. 4.14. In this configuration switches 1, 11, 12 and 10, of Fig. 4.4, are conducting

current.

The A and B submatrices that describe this configuration are shown in 4.13. The

Page 60: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 54

R L

R L

Rdc

Ldc

idcY

sai

Y

sci

vdcR L

R L

D

sai

D

sbi

vsc

vsa

sav3

s

sciD

R LD

scisbv3

s

saiD

s

sbiDscv3

Figure 4.14: 12-Pulse Converter 5-Valve Commutation After Gating of Switch 2

derivation of these submatrices is outlined in Appendix A.3.4.

A =

1

2√3

R

L−1

2

R

L

(

1−√3

2

)

7/2R+Rdc

7/2L+ Ldc

+1

2√3

R

L

1

6

R

L

√3

2

R

L

(

1√3− 1

2

)

7/2R+Rdc

7/2L+ Ldc+

5

6

R

L

0 0 −7/2R +Rdc

7/2L+ Ldc

(4.13a)

B =

−1/4

L+

3/8

7/2L+ Ldc

√3/4

L+

√3/2− 3

√3/8

7/2L+ Ldc· · ·

√3/4

L+

1/2− 3√3/4

7/2L+ Ldc−3/4

L+

1/8

7/2L+ Ldc· · ·

3/2 + 3√3/4

7/2L+ Ldc

3/4 +√3/2

7/2L+ Ldc· · ·

(4.13b)

In this section, the approach for solving for the A and B submatrices of (2.10) for the

12-pulse converter is outlined. These submatrices were derived here for the time interval

spanning from when switch 1 is gated until the end of the commutation interval that

immediately follows the gating of switch 2. The other A and B submatrices are similarly

Page 61: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 55

derived.

4.5.5.4 Summary

Once the A and B submatrices have all been calculated, the M matrices describing the

6-pulse and 12-pulse topologies during steady state can be calculated. The M matrices,

the switching times and the gating sequence of the switches, can be combined to solve

for Φ as discussed in Section 2.3, from which the FCM can be extracted. For illustrative

purposes, the Φ matrix that maps the 6-pulse converter states from t = t1 to t = t1 + T

is calculated and shown in (4.14) (the formulation for the 12-pulse converter is similarly

derived),

Φ = exp(

M12γ6−µ6

2πfL

)

exp(

M11µ6

2πfL

)

· · · exp(

M2γ1−µ1

2πfL

)

exp(

M1µ1

2πfL

)

(4.14)

The output vector ~y is calculated from the resulting FCM as shown in (4.15),

~y(0) = R(−t1)[FCM]~u(t1) (4.15)

In this section, the FCM for the harmonic models of the line commutated converter

topologies was outlined. It was shown how the switching times and switch states are

calculated for the assumed control schemes. Additionally, it was shown how the time-

derivatives of the state variables are solved for and how they are used to solve for the

FCM for the line commutated converter harmonic models.

4.5.6 Constraint Equation Evaluation

4.5.6.1 Introduction

In this section, the constraint equations of the line commutated converter harmonic

models are derived. The constraint equations are employed to ensure that 1) the average

power Pdc and voltage Vdc (in the case of the thyristor models) specified as an input

reference to the models are accurately set and 2) the operation of the models is consistent

with the assumptions imposed in Section 4.3. First, the constraint equations for the

thyristor converters are discussed. Then, the constraint equations for the diode converters

are discussed. Finally, a representative set of the constraint equations are derived.

Page 62: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 56

Thyristor-Switched Converters

For the thyristor-switched line commutated converter models to converge to an accurate

solution for a given set of inputs, the following control parameters must be solved for:

firing angle α and the set of overlap angle µ values. Therefore, the 6-pulse converter re-

quires 7 constraint equations, and the 12-pulse converter requires 13 constraint equations

to solve for the α and µ values. The constraint equations used for the thyristor converter

are as follows, where n refers to the number of pulses: 1 constraint equation, to set Pdc n constraint equations, to ensure that at the end of each commutation interval the

amplitude of the specific phase current in the sequence is equal to 0

Note, that while the average dc-side voltage Vdc is specified as an input reference, it is

not iterated for. This is because Rdc is calculated based on the specified inputs Vdc and

Pdc, and therefore if the calculated value of Pdc matches the input reference, the value of

Vdc will necessarily match the input reference as well.

Diode-Switched Converters

For the diode-switched line commutated converter models to converge to an accurate

solution for a given set of inputs, the following control parameters must be solved for:

dc-side resistance, Rdc, switching time, t1, the set of overlap angle µ values, and the set

of γ values. As such, the 6-pulse converter requires 14 constraint equations, and the 12-

pulse converter requires 26 constraint equations to solve for the α, µ, t1 and Rdc values.

The breakdown of the constraint equations for the diode converter are as follows, where

n refers to the number of pulses: 1 constraint equation, to control for Pdc n constraint equations, to ensure that at the end of each commutation interval the

amplitude of the specific phase current in the sequence is equal to 0 n + 1 constraint equations, to ensure diode forward voltage drop is equal to 0 at

the beginning of each commutation interval

From the above descriptions of the constraint equations, it is shown that 3 different types

of constraint equations are used for solving the line commutated converter harmonic

Page 63: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 57

models. As such, in the next few sections these 3 types of constraint equations are

discussed.

Control of Average Power Pdc

The average dc-side power constraint equation, as shown in (4.16), can be expanded as

shown in (4.17),

∆Pdc = 0 (4.16)

∆Pdc = RdcI2dc − P ref

dc (4.17)

where, Idc can be directly calculated, once the FCM has been solved, using the following

equation: Idc = PIdcFCM~u(t1)

Setting Phase Current = 0 at End of Commutation Interval

During the commutation intervals, the amplitude of one of the commutating phase cur-

rents decreases from idc to 0. This property is used here. The approach to calculating

the constraint equations of this type, for the 6-pulse and 12-pulse topologies, is signifi-

cantly different and therefore the next 2 sections solve this constraint equation for one

commutation interval of the 6-pulse topology and for one commutation interval of the

12-pulse topology.

6-Pulse Topology Referring to the first row of Table 4.1, for the 6-pulse converter,

it shows that the gating of switch 1 is immediately followed by a period of commutation

where the current in phase ‘b’ decreases from idc to 0. The end of this commutation

interval corresponds to time t = t2 which was calculated in (4.8). The constraint equation

corresponding to time t = t2 is as follows,

∆isb(t2) =0 (4.18a)

=isb(t2) (4.18b)

To obtain an expression for isb(t2), it is convenient to take the integral of the time

derivative of the converter state vector, as was done in (2.11), but with the limits of

Page 64: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 58

integration being from t = t1 to t = t2 as is shown in (4.19),

~x(t2)

~u(t2)

~y(t2)

= exp

(

M1µ1

2πfL

)

~x(t1)

~u(t1)

~y(t1)

(4.19)

Note, because of the structure of matrix M , exp(

M1µ1

2πfL

)

in (4.19), necessarily has the

following structure,

exp(

M1µ1

2πfL

)

=

Aµ1Bµ1

0

0 Cµ10

Dµ1Eµ1

Fµ1

(4.20)

If (4.20) is substituted into (4.19), the following relation for the converter states of ~x(t2)

at t = t2 can be extracted,

~x(t2) = Aµ1~x(t1) +Bµ1

~u(t1) (4.21)

An expression for ~x(t2) only in terms of the input vector ~u(t1) can be obtained from

(4.21), if (2.14)—re-written for convenience in (4.22)—is substituted into (4.21). The

result of this substitution is (4.23),

~x(t1) = (I − AT )−1BT~u(t1) (4.22)

~x(t2) =(

Aµ1(I −AT )

−1BT +Bµ1

)

~u(t1) (4.23)

And because, ~x(t2) =

isα(t2)

isβ(t2)

idc(t2)

, an expression for isb(t2) can be extracted from (4.23) as

is shown in (4.24),

isb(t2) =[

0 1 0]

C−1

[

1 0 0

0 1 0

]

~x(t2) (4.24)

The other constraint equations of this type, for the 6-pulse converter topology, are solved

similarly.

12-Pulse Topology The procedure for deriving the constraint equations for the

12-pulse topology is more involved than for the 6-pulse topology. For the 12-pulse topol-

Page 65: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 59

ogy the amplitude of a phase current on the secondary-side of the transformer becomes

equal to 0 at the end of each commutation interval. But because only the primary side

currents are being solved for, the secondary currents must be equivalently represented

with primary side currents isa, isb and isc to formulate the constraint equations. A con-

stant matrix that maps the primary side currents to the secondary side currents is derived

in Appendix A.3.1. To illustrate how a constraint equation for the 12-pulse topology is

derived, the derivation of the constraint equation that corresponds to t = t2 is derived in

(4.25),

∆iYsb(t2) =0 (4.25a)

=iYsb(t2) (4.25b)

To solve for iYsb(t2), it is first convenient to expand (4.25), as is shown in (4.26),

iYsb(t2) =[

0 1 0]

iYsa(t2)

iYsb(t2)

iYsc(t2)

(4.26)

If (7.31) from Appendix A.3.1 is re-arranged for ~iYsabc, and relevant states are converted

to the space vector format, and then the resulting expression is substituted into (4.26),

(4.27) results,

iYsb(t2) =[

0 1 0]

C−1

1 0

0 1

0 0

[

isα(t2)

isβ(t2)

]

− 1

3√3

−4 2 −1

−1 −4 2

2 −1 −4

i∆sa(t2)

i∆sb(t2)

i∆sc(t2)

(4.27)

When the secondary of the Y-Y transformer is in commutation mode, the states of the

secondary of the Y-D transformer can be expressed as a function of idc. Similarly, when

the secondary of the Y-D transformer is in commutation mode, the states of the secondary

of the Y-Y transformer can be expressed as a function of idc. As such, the states of the

secondary of the Y-D transformer at t = t2 are shown in (4.28),

i∆sa(t2) =idc(t2) (4.28a)

i∆sb(t2) =− idc(t2) (4.28b)

i∆sc(t2) =0 (4.28c)

Page 66: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 60

If (4.28) is substituted into (4.27) and the resulting expression is expressed as a function

of ~x(t2), (4.29) results,

iYsb(t2) =[

0 1 0]

C−1

1 0

0 1

0 0

[

1 0 0

0 1 0

]

− 1

3√3

−4 2 −1

−1 −4 2

2 −1 −4

1

−1

0

[

0 0 1]

~x(t2)

(4.29)

Where, (4.23) can be substituted into (4.29) for ~x(t2).

For the commutation intervals, where the phase current that decreases from idc to 0 is on

the secondary of the Y-∆ transformer, the process is similar, except (7.31) is re-arranged

for vector ~i∆sabc rather than, ~iYsabc.

Setting Diode Forward Voltage Drop = 0 at Beginning of Commutation In-

terval

The diodes of the diode-switched 6 and 12 pulse topologies are gated when the forward

voltage drop of the diode becomes equal to 0. The derivation of the constraint equation,

for the forward voltage drop of the 6-pulse diode topology is illustrated here for time

t = t1. At time t = t1 the circuit has the configuration of Fig. 4.15. The two equations

idc

R L-vsb+

-vsc+

-vsa+R L

vdcidc

idc

1Dv

Rdc

Ldc

Figure 4.15: 6-Pulse Topology Forward Voltage Drop Configuration at Time t = t1

Page 67: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 61

of (4.30) are derived from Fig. 4.15 by applying Kirchoff’s Voltage Law,

0 =− vsa + (2R +Rdc)idc + (2L+ Ldc)didcdt

+ vsb (4.30a)

0 =vD1 + Ldidcdt

+Ridc + vsb − vsc (4.30b)

By re-arranging (4.30a) for didcdt

, substituting the resulting expression into (4.30b), and

re-arranging for vD1, (4.31) results,

vD1 =RLdc + LRdc

2L+ Ldcidc −

[

L

2L+ Ldc1− 2L

2L+ Ldc−1

]

~vsabc (4.31)

If (4.31) is re-expressed in terms of ~x(t1) and ~u(t1), (4.32) results,

vD1 =RLdc + LRdc

2L+ Ldc

[

0 0 1]

~x(t1) +[

K K · · · K]

~u(t1) (4.32)

where, there are h+1, K-terms in (4.32), andK =[

L

2L+ Ldc

1− 2L

2L+ Ldc

−1

]

C−1

1 0

0 1

0 0

The other forward voltage drop related constraint equations are solved similarly for the

6-pulse and 12-pulse topologies.

4.5.7 Control Parameter Update

In this section, the procedures for updating the control parameters of the thyristor and

diode line commutated converter models are discussed. In both descriptions, only the

6-pulse topology is described as the procedure employed for updating the control param-

eters of the 12-pulse topologies are similar.

4.5.7.1 Thyristor-Switched Converter

In the case that the constraint equation requirements are not met, the control parameters,

α and µ, are updated. A Newton-Raphson technique is used to update the variables as

is shown in (4.33) for the 6-pulse converter,

[

α

]

i+1

=

[

α

]

i

+ J−1 ~M (4.33)

Page 68: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 62

Where ~M is a vector containing the values of the constraint equations and J is an exact

Jacobian with the following structure,

J =

dPdc

dPdc

dµdisb(t2)

disb(t2)

dµ...

...disb(t12)

disb(t12)

(4.34)

Where,

dPdc

dµ=2RdcIdcPIdc

d

dµ~y(0) (4.35a)

dPdc

dγ=2RdcIdcPIdc

d

dγ~y(0) (4.35b)

disb(t2)

dα=[

0 1 0]

C−1

[

1 0 0

0 1 0

]

d

dα~x(t2) (4.35c)

disb(t2)

dµ=[

0 1 0]

C−1

[

1 0 0

0 1 0

]

d

dµ~x(t2) (4.35d)

The entries of the Jacobian can be found in the MATLAB code for the thyristor converter

models in Appendix B.2.2 and Appendix B.2.4.

4.5.7.2 Diode-Switched Converter

In the case that the constraint equation requirements are not met, the control parameters,

γ, µ as well as Rdc and t1 are updated. A Newton-Raphson technique is employed to

update the control parameters as shown in (4.36), for the 6-pulse converter,

t1

Rdc

i+1

=

t1

Rdc

i

+ J−1 ~M (4.36)

Page 69: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 63

Where J is an exact Jacobian of the following form,

J =

dPdc

dt1

dPdc

dRdc

dPdc

dPdc

γdisb(t2)

dt1

disb(t2)

dRdc

disb(t2)

disb(t2)

dγ...

......

...disb(t12)

dt1

disb(t12)

dRdc

disb(t12)

disb(t12)

dγdvD1(t1)

dt1

dvD1(t1)

dRdc

dvD1(t1)

dvD1(t1)

dγ...

......

...dvD1(t13)

dt1

dvD1(t13)

dRdc

dvD1(t13)

dvD1(t13)

(4.37)

Where,

dPdc

dz=2RdcIdcPIdc

d

dv~y(t1) (4.38a)

dPdc

dRdc

=I2dc

+ 2RdcIdcPIdc

d

dRdc

~y(t1) (4.38b)

disb(t2)

dv=[

0 1 0]

C−1

[

1 0 0

0 1 0

]

d

dv~x(t1) (4.38c)

dvD1(t1)

dv=RLdc + LRdc

2L+ Ldc

[

0 0 1] d

dv~x(t1) +

[

K K · · · K

] d

dv~u(t1) (4.38d)

where, z can be either t1, µ, γ and v can be either t1, µ, γ, Rdc and

K =

[

L

2L+ Ldc

1− 2L

2L+ Ldc

−1

]

C−1

1 0

0 1

0 0

.

The Jacobian entries can be found in the MATLAB code for the diode converter models

in Appendix B.2.3 and Appendix B.2.5.1

1In the implementation of the diode switched harmonic models, Rdc is solved for differently than ispresented here. This alternate implementation is found in the MATLAB code. Instead of including theRdc in the Jacobian, an iterative loop is added to the solution such that before the next iteration of theouter control loop, P is calculated, for the current iteration’s value of Rdc and the calculated value of Idcobtained from the results of the current iteration, and that value is compared against the input value.If the convergence criteria is not met, Rdc is updated, as follows:

Rdci+1= Rdci

Pi

P(4.39)

This value of Rdc is then used in another iteration of the inner control loop. The next iteration of theouter control loop begins once the convergence criteria is met. The justification for this approach isthat, in the harmonic models, P is largely proportional to Rdc and by removing Rdc from the Jacobian,the inner control loop is being solved for quicker, which partially offsets the increased time required to

Page 70: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 4. Line Commutated Converter Harmonic Models 64

4.5.8 Summary of Approach

In summary, the approach to deriving the 4 line-commutated harmonic converter models

is outlined in this section. The unknown converter states in ~y are calculated, by iteratively

solving for the unique set of switching times that result in the constraint equations,

imposed on the line commutated converters, to be met.

4.6 Summary of Chapter

In this chapter, the line commutated converter models are presented. More specifically,

the topology, modes of operation, and the control schemes assumed were discussed. This

was followed by a detailed description of how the harmonic models were derived.

increase the number of iterations of the inner control loop.

Page 71: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 5

Harmonic Analysis Tool

For this thesis, a harmonic analysis tool was developed in MATLAB, called OpenHar-

monics, that is designed to perform high accuracy, steady-state, harmonic analysis studies

of power systems when multiple converter interfaced loads and generators exist in the

system. OpenHarmonics has similar features to other frequency-domain based harmonic

analysis tools on the market, but is different in that it 1) incorporates the 5 harmonic

models developed in this thesis and 2) models the interaction between multiple har-

monic sources in the power system. OpenHarmonics is built on top of the open source,

harmonic analysis tool called, OpenDSS, and uses OpenDSS to perform the harmonic

analysis studies.

OpenDSS, like the studied competitive harmonic analysis tools, performs harmonic

analysis studies by sequentially solving for the system harmonics at each harmonic of

interest: first, the system is solved at 60 Hz, then the system harmonics are solved at

120 Hz, then at 180 Hz, etc. With this approach, the solution at one frequency does

not effect the solution at another frequency; however, modelling the interaction between

different harmonic frequencies is a necessary feature for fully implementing the harmonic

models of this thesis. The harmonic converter models in OpenDSS are represented with

fixed current sources, with an associated harmonic spectrum. Therefore, in order to ac-

count for the interaction of multiple harmonic sources on a system, the harmonic spectra

for each of the current sources, representing the harmonic models, must be modifiable

during run time. To do this, while using OpenDSS to perform the harmonic analysis

studies, an iterative harmonic analysis technique is employed which involves OpenHar-

monics initiating multiple executions of OpenDSS to solve for the harmonics of a power

system. However, there is a mismatch between the two solution approaches: OpenDSS

65

Page 72: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 5. Harmonic Analysis Tool 66

solves for the frequency-domain solution of the system and OpenHarmonics solves for the

time-domain solution of the harmonic models. To make the tools compatible, before each

execution of OpenDSS, the results from solving the harmonic models in OpenHarmonics

are converted to the frequency-domain and then these converted results are used to up-

date the harmonic spectrum of the current sources used to represent the harmonic models

in OpenDSS [4, 25]; and after each execution of OpenDSS, the results are converted to

the time-domain to be used as inputs to the harmonic models in OpenHarmonics. An

active communication link, using the COM interface, is established between OpenHar-

monics and OpenDSS such that OpenHarmonics can access the results of the OpenDSS

simulations, update the OpenDSS circuit elements, and initiate additional OpenDSS

simulations. Each simulation, using OpenHarmonics, can be seen as consisting of three

steps: 1) definition of system, 2) iterative harmonic analysis, and 3) generation of results,

as shown in Fig. 5.1. The rest of this chapter describes the procedure OpenHarmonics

takes each time to simulate the harmonics of a power system of interest.

Define Distribution

System and Converter

Models

Perform Iterative

Harmonic Analysis

Switching Between

MATLAB and OpenDSS

Output Harmonic

Spectra to MATLAB

Workspace

Step 1 Step 2 Step 3

Figure 5.1: OpenHarmonics Simulation Procedure

Step 1) Definition of System

Prior to the simulation run time, the power system must be fully defined. The harmonic

converter models are defined in OpenHarmonics. All other components of the power

system are defined in OpenDSS. It is important to note that in OpenHarmonics, for the

VSC harmonic model, the dc-side current source idc is limited to the dc-component only;

therefore, for the VSC harmonic model, ~idc = [Idc], where ~idc is from (4.1).

Step 2) Iterative Harmonic Analysis

When the simulation begins, the COM interface is first initiated between OpenHarmonics

and the OpenDSS circuit files which define the power system to be analyzed. Using this

Page 73: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 5. Harmonic Analysis Tool 67

COM interface, OpenHarmonics simulates a system by iteratively switching back and

forth between MATLAB and OpenDSS, converting between the time-domain and the

frequency-domain in the process, until a solution is obtained. A high-level flow chart,

outlining how OpenHarmonics switches between MATLAB and OpenDSS, to solve for

the converter harmonics, is shown in Fig. 5.2. This is the same flow chart shown in

Chapter 1. The first step, in each iteration, is to solve for the system voltage harmonics

Start

MATLAB

VSC, Thyristor,

Diode Models

OpenDSS

Network

Have PCC voltages

converged?

Stop

Yes

Vharmonics

No

Iharmonics

Figure 5.2: OpenHarmonics—Iterative Harmonic Analysis Functional Block

with OpenDSS. To solve for the system voltage harmonics, OpenDSS performs three

steps:

1. The fundamental power flow solution of the system is first solved for.

2. Using this solution, the harmonic currents or voltages of each element in the network

are solved.

Page 74: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 5. Harmonic Analysis Tool 68

3. Using the calculated harmonics, OpenDSS sequentially solves the system at each of

the harmonic frequencies of interest. For example, if the user requires 15 harmonics

to be solved, the system would solve the system first for 120 Hz, then 180 Hz, ...

900 Hz.

Once the system has been solved at all harmonics of interest, the resulting voltage har-

monic spectra are read into MATLAB, converted to time-domain equivalent quantities,

where these converted quantities are used as inputs to the converter models. The convert-

ers are then solved one-by-one for their respective line current harmonic spectra. These

line current harmonics are converted to frequency-domain equivalent quantities and are

then fed back into OpenDSS to update the harmonic spectrum of the current sources

representing the harmonic converter models. This entire process constitutes one itera-

tion. And this process repeats until the difference in PCC voltage harmonic amplitudes

from consecutive iterations is less than 1%.

Step 3) Generation of Results

Once the system has been solved, the harmonic spectra of the bus voltages and converter

currents are saved to the MATLAB workspace.

Page 75: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6

Results

6.1 Introduction

To promote OpenHarmonics as a steady-state harmonic analysis tool that is a middle

ground between the highly-accurate yet computationally intensive time-domain solvers

such as PSCAD/EMTDC and the frequency-domain harmonic analysis tools such as

ETAP and CYME that feature primitive harmonic models of converters, it is important

to assess the computation time and accuracy of OpenHarmonics as well as the harmonic

models. As such, in this chapter the accuracy and overall computation time of the

harmonic models and the OpenHarmonics tool are evaluated. To evaluate the accuracy

of the harmonic models and OpenHarmonics the systems are solved, for a representative

set of operating conditions, and the results are compared against PSCAD/EMTDC. To

evaluate the computation time the harmonic models and OpenHarmonics are solved for a

representative system for different values of h (the number of analyzed ac-side harmonics)

and the computation times are recorded.

6.2 Evaluating Accuracy of Harmonic Models and

OpenHarmonics

Two verify the accuracy of i) the 5 harmonic models and ii) OpenHarmonics, two studies

were performed. The first study evaluates the accuracy of the 5 harmonic models by

solving for the most significant current harmonics for three test cases and comparing these

results to equivalent tests in PSCAD/EMTDC. The second study evaluates the accuracy

69

Page 76: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 70

of OpenHarmonics by solving for the most significant current and voltage harmonics of

the IEEE 13-Bus Test System when the 5 harmonic models are added to the system and

comparing these results to an equivalent test in PSCAD/EMTDC.

6.2.1 Harmonic Models

To evaluate the accuracy of the 5 harmonic models, each harmonic model was sepa-

rately evaluated. In each of these evaluations, the unknown converter state harmonics

were solved, for a representative operating condition of the converter, and the most sig-

nificant harmonic amplitudes were compared against a similar simulation performed in

PSCAD/EMTDC. In evaluating each converter, three test cases were performed. The

only difference in these test cases are the conditions at the PCC—the circuit parameters

are held constant. In the first test case, the PCC is balanced. In the second test case, the

PCC is unbalanced with -5th and +7th harmonic distortion. In the third test case, the

PCC is unbalanced with +2nd, -5th and +7th harmonic distortion. The test cases were

performed using per-unit quantities and the per-unit values used for the PCC voltages

of the 3 test cases are shown in Table 6.1. For these tests, 31 harmonic multiples were

analyzed (i.e. 60 Hz, 120 Hz, ..., and 1860 Hz). In the following 5 sections, the results

of performing these three test cases on each of 5 harmonic models is shown, along with

the other inputs used to generate the results. Note that in the presented results, not all

solved converter state harmonics are shown. The criteria for including a solved current

state harmonic in the presented results is that its amplitude > 1% of |i+1sαβ|.

Table 6.1: PCC Inputs for Study 1

Inputs Test Case 1 (pu) Test Case 2 (pu) Test Case 3 (pu)v+1sαβ 1∠0° 1∠0° 1∠0°

v−1sαβ N/A 0.02∠30° 0.02∠10°

v+2sαβ N/A N/A 0.02∠60°

v−5sαβ N/A 0.02∠45° 0.02∠0°

v+7sαβ N/A 0.01∠0° 0.01∠0°

6.2.1.1 VSC Harmonic Model

The VSC topology evaluated is shown in Fig. 3.1. The inputs for the 3 test cases are

outlined in Table 6.2. In each of the PSCAD/EMTDC simulations the solution step

Page 77: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 71

size was set to 100µs. The maximum discrepancy between the simulation results from

PSCAD/EMTDC and from the harmonic model in MATLAB, occurred during Scenario

2 and was 0.33% at the −5th harmonic multiple.

Table 6.2: Inputs to VSC Harmonic Model for Study 1

Inputs ValuefL 1 rad/sfsw 15 rad/sRdc 108 puCdc 1 puVdc 2.3 puPdc -0.92 puQac 0.1 puR 0.02 puL 0.2 pu

Page 78: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 72

−29 −17 +1 +13 +19 +310

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Harmonic Multiple

Har

mon

ic C

urre

nt A

mpl

itude

(pu

)

MATLABPSCAD

Figure 6.1: Comparing VSC Harmonic Model to PSCAD/EMTDC in Test Case 1

−29 −17 −5 −1 +1 +3 +7 +13 +19 +31 2(dc−v)0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Harmonic Multiple

Har

mon

ic C

urre

nt a

nd V

olta

ge A

mpl

itude

(pu

)

MATLABPSCAD

Figure 6.2: Comparing VSC Harmonic Model to PSCAD/EMTDC in Test Case 2

Page 79: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 73

−29 −17 −5 −1 +1 +2 +3 +7 +13 +19 +312(dc−v)0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Harmonic Multiple

Har

mon

ic C

urre

nt a

nd V

olta

ge A

mpl

itude

(pu

)

MATLABPSCAD

Figure 6.3: Comparing VSC Harmonic Model to PSCAD/EMTDC in Test Case 3

Page 80: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 74

6.2.1.2 6-Pulse Thyristor Converter Harmonic Model

The 6-pulse thyristor topology evaluated is shown in Fig. 4.2. The inputs for the 3 test

cases are outlined in Table 6.3. In each of the PSCAD/EMTDC simulations the solution

step size was set to 250µs. The maximum discrepancy between the simulation results from

PSCAD/EMTDC and from the harmonic model in MATLAB occurred during Scenario

2 and was 0.17% at the +19th harmonic multiple.

Table 6.3: Inputs to 6-Pulse Thyristor Converter Harmonic Model for Study 1

Inputs ValuefL 1 rad/sPdc 0.92 puVdc 1.385641 puL 0.2 puR 0.02 pu

Ldc 0.5 pu

−17 −11 −5 +1 +7 +13 +190

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

Harmonic Multiple

Har

mon

ic C

urre

nt A

mpl

itude

(pu

)

MATLABPSCAD

Figure 6.4: Comparing 6-Pulse Thyristor Converter Harmonic Model toPSCAD/EMTDC in Test Case 1

Page 81: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 75

−17 −11 −5 −1 +1 +7 +13 +190

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

Harmonic Multiple

Har

mon

ic C

urre

nt A

mpl

itude

(pu

)

MATLABPSCAD

Figure 6.5: Comparing 6-Pulse Thyristor Converter Harmonic Model toPSCAD/EMTDC in Test Case 2

−17 −11 −5 −1 +1 +2 +7 +13 +190

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

Harmonic Multiple

Har

mon

ic C

urre

nt A

mpl

itude

(pu

)

MATLABPSCAD

Figure 6.6: Comparing 6-Pulse Thyristor Converter Harmonic Model toPSCAD/EMTDC in Test Case 3

Page 82: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 76

6.2.1.3 6-Pulse Diode Converter Harmonic Model

The 6-pulse diode topology evaluated is shown in Fig. 4.2. The inputs for the 3 test

cases are outlined in Table 6.4. In each of the PSCAD/EMTDC simulations the solution

step was set to 20µs. The maximum discrepancy between the simulation results from

PSCAD/EMTDC and from the harmonic model in MATLAB occurred during Scenario

2 and was 0.26% at the −17th harmonic multiple.

Table 6.4: Inputs to 6-Pulse Diode Converter Harmonic Model for Study 1

Inputs ValuefL 1 rad/sPdc 0.92 puL 0.2 puR 0.02 pu

Ldc 0.5 pu

−17 −11 −5 +1 +7 +130

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Harmonic Multiple

Har

mon

ic C

urre

nt A

mpl

itude

(pu

)

MATLABPSCAD

Figure 6.7: Comparing 6-Pulse Diode Converter Harmonic Model to PSCAD/EMTDCin Test Case 1

Page 83: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 77

−17 −11 −5 −3 −1 +1 +7 +130

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Harmonic Multiple

Har

mon

ic C

urre

nt A

mpl

itude

(pu

)

MATLABPSCAD

Figure 6.8: Comparing 6-Pulse Diode Converter Harmonic Model to PSCAD/EMTDCin Test Case 2

−17 −11 −5 −3 −1 +1 +2 +7 +130

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Harmonic Multiple

Har

mon

ic C

urre

nt A

mpl

itude

(pu

)

MATLABPSCAD

Figure 6.9: Comparing 6-Pulse Diode Converter Harmonic Model to PSCAD/EMTDCin Test Case 3

Page 84: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 78

6.2.1.4 12-Pulse Thyristor Converter Harmonic Model

The 12-pulse thyristor topology evaluated is shown in Fig. 4.4. The inputs for the 3 test

cases are outlined in Table 6.5. In each of the PSCAD/EMTDC simulations the solution

step was set to 20µs. The maximum discrepancy between the simulation results from

using PSCAD/EMTDC and from the harmonic model in MATLAB, occurred during

Scenario 2 and was 0.34% at the −5th harmonic multiple.

Table 6.5: Inputs to 12-Pulse Thyristor Converter Harmonic Model for Study 1

Inputs ValuefL 1 rad/sPdc 0.92 puVdc 3.0 puL 0.2 puR 0.02 pu

Ldc 0.5 pu

−23 −11 +1 +13 +250

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Harmonic Multiple

Har

mon

ic C

urre

nt A

mpl

itude

(pu

)

MATLABPSCAD

Figure 6.10: Comparing 12-Pulse Thyristor Converter Model to PSCAD/EMTDC inTest Case 1

Page 85: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 79

−23 −11 −5 −1 +1 +13 +250

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Harmonic Multiple

Har

mon

ic C

urre

nt A

mpl

itude

(pu

)

MATLABPSCAD

Figure 6.11: Comparing 12-Pulse Thyristor Converter Model to PSCAD/EMTDC inTest Case 2

−23 −11 −5 −1 +1 +2 +13 +250

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Harmonic Multiple

Har

mon

ic C

urre

nt A

mpl

itude

(pu

)

MATLABPSCAD

Figure 6.12: Comparing 12-Pulse Thyristor Converter Model to PSCAD/EMTDC inTest Case 3

Page 86: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 80

6.2.1.5 12-Pulse Diode Converter Harmonic Model

The 12-pulse diode topology evaluated is shown in Fig. 4.4. The inputs for the 3 test

cases are outlined in Table 6.6. In each of the PSCAD/EMTDC simulations the solution

step was set to 20µs. The maximum discrepancy between the simulation results from

PSCAD/EMTDC and from the harmonic model in MATLAB occurred during Scenario

2 and was 0.24% at the −5th harmonic multiple.

Table 6.6: Inputs to 12-Pulse Diode Converter Harmonic Model for Study 1

Inputs ValuefL 1 rad/sPdc 0.92 puL 0.2 puR 0.02 pu

Ldc 0.5 pu

−23 −11 +1 +130

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Harmonic Multiple

Har

mon

ic C

urre

nt A

mpl

itude

(pu

)

MATLABPSCAD

Figure 6.13: Comparing 12-Pulse Diode Converter Harmonic Model to PSCAD/EMTDCin Test Case 1

Page 87: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 81

−23 −11 −5 −1 +1 +7 +130

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Harmonic Multiple

Har

mon

ic C

urre

nt A

mpl

itude

(pu

)

MATLABPSCAD

Figure 6.14: Comparing 12-Pulse Diode Converter Harmonic Model to PSCAD/EMTDCin Test Case 2

−11 −5 −1 +1 +2 +130

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Harmonic Multiple

Har

mon

ic C

urre

nt A

mpl

itude

(pu

)

MATLABPSCAD

Figure 6.15: Comparing 12-Pulse Diode Converter Harmonic Model to PSCAD/EMTDCin Test Case 3

Page 88: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 82

6.2.1.6 Summary

In summary, it was shown in this first study that there is a high degree of correspon-

dence between the simulation results from the harmonic models and PSCAD/EMTDC.

The maximum discrepancy between the two simulation methods was shown to be 0.34%,

even when testing unbalanced conditions with significant even and odd harmonic dis-

tortion. The discrepancy can be attributed to rounding errors in setting the circuit

parameters in PSCAD/EMTDC, size of simulation time step in PSCAD/EMTDC, and

small undetected errors in the implemented harmonic models in MATLAB.

6.2.2 OpenHarmonics

To evaluate the accuracy of the OpenHarmonics harmonic analysis tool, a steady-state

harmonic analysis study was performed on a modified version of the IEEE 13-Bus Test

System. The only modifications to the test system, were the shorting out of the regulator

and the addition of the 5 harmonic models at Bus 634 and Bus 675. The modified IEEE

13-Bus Test System is graphically illustrated in Fig. 6.16. In this study, the unknown

converter state harmonics are solved, for each of the converter models, and the most

significant harmonics are compared against the simulation results from PSCAD/EMTDC.

The inputs used in this study for the 5 converter models are shown in Table 6.7. In this

study, 31 harmonic multiples were analyzed (i.e. 60 Hz, 120 Hz, ..., and 1860 Hz).

The results of the simulation are shown here. The solved line current harmonic am-

plitudes, for the 5 harmonic models, are graphed in Fig. 6.17–6.21. The bus 634 and 675

voltage harmonics are graphed in Fig. 6.22 and Fig. 6.23, respectively. Note that in the

presented results, not all solved converter harmonics are shown. The criteria for includ-

ing a solved current (voltage) harmonic amplitude, in the presented results, is that its

amplitude is > 1% of |i+1sαβ | (|v+1

sαβ|). The solution step size used in the PSCAD/EMTDC

simulation was 1µs.

Page 89: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 83

650

646 645 632 633 634

611 684

652

671

680

692 675

12-Pulse Diode

Rectifier

6-Pulse Diode

Rectifier

12-Pulse Thyristor

Rectifier

6-Pulse Thyristor

Rectifier

VSC

Figure 6.16: Modified IEEE 13-Bus Test System

Table 6.7: Inputs for the 5 Harmonic Models in Study 2

Input VSC Thyristor Diode Thyristor Diode6-Pulse 6-Pulse 12-Pulse 12-Pulse

fL(Hz) 60 60 60 60 60fsw(Hz) 900 N/A N/A N/A N/ARdc(Ω) 108 N/A N/A N/A N/A

Ldc(mH) N/A 2.04 2.55 139.1 153.0Cdc(mF) 60.0 N/A N/A N/A N/AR(mΩ) 30.7 30.7 33.4 2097.6 2307.4L(mH) 0.8149 0.8149 1.019 55.6 61.2Vdc(kV) 1.0 0.5095 N/A 10.0 N/APdc(kW) −90 +90 +70 +100 +75Qac(kvar) +10 N/A N/A N/A N/A

Page 90: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 84

−29 −17 −5 −1 +1 +13 +310

20

40

60

80

100

120

140

160

180

Harmonic Multiple

Cur

rent

Har

mon

ic A

mpl

itude

(A

)

MATLABPSCAD

Figure 6.17: Comparing Harmonic Current Amplitudes of VSC Harmonic Model Solvedin OpenHarmonics with PSCAD/EMTDC

−17 −11 −5 −1 +1 +7 +130

20

40

60

80

100

120

140

Harmonic Multiple

Cur

rent

Har

mon

ic A

mpl

itude

(A

)

MATLABPSCAD

Figure 6.18: Comparing Harmonic Current Amplitudes of 6-Pulse Diode Converter Har-monic Model Solved in OpenHarmonics with PSCAD/EMTDC

Page 91: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 85

−11 −5 +1 +7 +130

20

40

60

80

100

120

140

160

180

200

Harmonic Multiple

Cur

rent

Har

mon

ic A

mpl

itude

(A

)

MATLABPSCAD

Figure 6.19: Comparing Harmonic Current Amplitudes of 6-Pulse Thyristor ConverterHarmonic Model Solved in OpenHarmonics with PSCAD/EMTDC

−11 −9 −1 +1 +130

2

4

6

8

10

12

14

16

18

Harmonic Multiple

Cur

rent

Har

mon

ic A

mpl

itude

(A

)

MATLABPSCAD

Figure 6.20: Comparing the Current Harmonics of the 12-Pulse Diode Converter fromOpenHarmonics and PSCAD/EMTDC

Page 92: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 86

−11 −1 +1 +130

5

10

15

20

25

Harmonic Multiple

Cur

rent

Har

mon

ic A

mpl

itude

(A

)

MATLABPSCAD

Figure 6.21: Comparing the Current Harmonics of the 12-Pulse Thyristor Converter fromOpenHarmonics and PSCAD/EMTDC

−29 −17 −5 −1 +1 +310

50

100

150

200

250

300

350

400

Harmonic Multiple

Vol

tage

Har

mon

ic A

mpl

itude

(V

)

MATLABPSCAD

Figure 6.22: Comparing the Voltage Harmonics at Bus 634 from OpenHarmonics andPSCAD/EMTDC

Page 93: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 87

−1 +10

500

1000

1500

2000

2500

3000

3500

Harmonic Multiple

Vol

tage

Har

mon

ic A

mpl

itude

(V

)

MATLABPSCAD

Figure 6.23: Comparing the Voltage Harmonics at Bus 675 from OpenHarmonics andPSCAD/EMTDC

Page 94: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 88

6.2.2.1 Analysis of Results

OpenHarmonics is better than existing harmonic analysis software tools for performing

steady-state harmonic analysis with converters in the system because i) non-characteristic

harmonics are included in the solution and ii) OpenHarmonics models characteristic vari-

ations associated with load dependent changes in overlap angle for the LCC harmonic

models. These claims are supported in these results. As an example, for the VSC har-

monic model the non-characterstic harmonics obtained from the results occur at harmonic

multiples −1 and −5. These harmonic multiples would be absent from the results from

other harmonic analysis tools.

By inspection of Fig. 6.17–6.23, it can be observed that there is a high degree of

correspondence between the PSCAD/EMTDC and OpenHarmonics results. However, at

certain harmonic multiples, the discrepancy between the PSCAD/EMTDC and Open-

Harmonics results is significant enough to warrant attention here. At bus 634, the max-

imum discrepancy between PSCAD/EMTDC and OpenHarmonics when comparing the

bus voltage harmonics, is 66% which was measured at h=-5 and for bus 675 it is 0.19%

which was measured at h=+1. Because the discrepancy between the PSCAD/EMTDC

and OpenHarmonics results is negligible when the converter models are removed from

the simulation, it can be concluded that the presence of the converter models is the main

contributor of this error. The greater error measured at bus 634 compared to bus 675,

can be attributed to the fact that the amplitude of the converter line current harmonics

are on average an order of magnitude greater than those from the converters at bus 675.

The converter line current harmonics can be compared as well. For the VSC, the max-

imum discrepancies were measured at h=-5, and h=-1 and the discrepancy values were

67% and 9.91%, respectively. For the 6-pulse thyristor converter a maximum discrepancy

of 7.6% was measured at h=-11. For the 6-pulse diode converter a maximum discrepancy

of 18.2% was measured at h=-11. For the 12-pulse thyristor converter a maximum dis-

crepancy of 3.5% was measured at h=-11. For the 12-pulse diode converter a maximum

discrepancy of 3.6% was measured at h=-11. Therefore, there is much greater error in

the converters interfaced to bus 634, as was expected as that bus voltage has higher error

than bus 675. The main sources of this error are likely due to i) the potential for multiple

zero-crossings in PSCAD/EMTDC that are not modelled in the LCC harmonic models

in OpenHarmonics and ii) the convergence tolerances in OpenHarmonics, one for solving

for the harmonic models and the other for solving for the system voltages.

Page 95: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 89

6.3 Evaluating Computation Time of Harmonic Mod-

els and OpenHarmonics

A problem with performing steady-state harmonic analysis of a power system with a time-

domain based tool such as PSCAD/EMTDC is that setting up the system for simulation

studies can be a time-demanding process, i.e. it is demanding on engineering time. One

of the main contributors to this is the design of the converter controllers, which is a

time-demanding activity that is prone to errors. Therefore to make a significant impact

in reducing this engineering time the utility engineers cannot be expected to design

controllers for all converters in the system—the controllers have to be abstracted away

from the analysis. This leaves two approaches for solving for the steady-state harmonics

in the power system: i) OpenHarmonics and ii) PSCAD/EMTDC with the Simplex

block (or another time-domain tool equivalent); where, the Simplex block employs the

simplex algorithm to find the control parameters without converter controllers. Through

the Simplex block the control parameters are iteratively solved for through multiple

simulation runs of the PSCAD/EMTDC where the control parameters are updated after

each simulation run. To evaluate the computation time of the harmonic models and

OpenHarmonics when the goal of reducing engineering time is factored in, two studies

were performed. In the first study, the computation time for each of the harmonic models

is compared against PSCAD/EMTDC for different values of h. In the second study, the

computation time for OpenHarmonics is computed for different values of h.

6.3.1 Harmonic Models

In this section the computation times for the 5 harmonic models are evaluated for four

different values of h and the times are compared to PSCAD/EMTDC when the controllers

are replaced with Simplex blocks. The input parameters for the 5 harmonic models are

the same as used for test case 2 outlined in Section 6.2.1, and detailed in Table 6.1–6.6

for the 5 harmonic models.

6.3.1.1 VSC Harmonic Model

The computation times for solving for the VSC harmonics using i) the derived harmonic

model, and ii) PSCAD/EMTDC, for the 4 different values of h, are presented in Table

6.8. In calculating these results, the Simplex block for the PSCAD/EMTDC simulation

Page 96: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 90

is defined to solve for the ma and δ control parameters using the constraint equation√

(Qac −Qrefac )2 + (Vdc − V ref

dc )2 < 0.001. Note, PSCAD/EMTDC required 61 simula-

tions of the system to converge to the solution.

Table 6.8: Comparing Computation Time of VSC Harmonic Model withPSCAD/EMTDC for Test Case 2

h PSCAD Derived Harmonic Model3 53.8min 0.55s11 53.8min 2.29s17 53.8min 5.40s31 53.8min 24.98s

6.3.1.2 6-Pulse Thyristor Converter Harmonic Model

The computation times for solving for the 6-pulse thyristor converter harmonics using

i) the derived harmonic model, and ii) PSCAD/EMTDC, for the 4 different values of

h, are presented in Table 6.9. In calculating these results, the Simplex block for the

PSCAD/EMTDC simulation is defined to solve for the α control parameter using the

constraint equation ∆Pdc = |Pdc − P refdc | < 0.001. Note, PSCAD/EMTDC required 10

simulations of the system to converge to the solution.

Table 6.9: Comparing Computation Time of 6-Pulse Thyristor Harmonic Model withPSCAD/EMTDC for Test Case 2

h PSCAD Derived Harmonic Model3 32.1s 0.11s11 32.1s 0.80s17 32.1s 2.01s31 32.1s 11.55s

6.3.1.3 6-Pulse Diode Converter Harmonic Model

The computation times for solving for the 6-pulse diode converter harmonics using i)

the derived harmonic model, and ii) PSCAD/EMTDC, for the 4 different values of h,

are presented in Table 6.10. In calculating these results, the Simplex block for the

Page 97: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 91

PSCAD/EMTDC simulation is defined to solve for the Rdc control parameter using the

constraint equation ∆Pdc = |Pdc − P refdc | < 0.001. Note, PSCAD/EMTDC required 21

simulations of the system to converge to the solution.

Table 6.10: Comparing Computation Time of 6-Pulse Diode Harmonic Model withPSCAD/EMTDC for Test Case 2

h PSCAD Derived Harmonic Model3 86.1s 0.43s11 86.1s 2.11s17 86.1s 5.92s31 86.1s 35.85s

6.3.1.4 12-Pulse Thyristor Converter Harmonic Model

The computation times for solving for the 12-pulse thyristor converter harmonics using

i) the derived harmonic model, and ii) PSCAD/EMTDC, for the 4 different values of

h, are presented in Table 6.11. In calculating these results, the Simplex block for the

PSCAD/EMTDC simulation is defined to solve for the α control parameter using the

constraint equation ∆Vdc = |Vdc − V refdc | < 0.001. Note, PSCAD/EMTDC required 13

simulations of the system to converge to the solution.

Table 6.11: Comparing Computation Time of 12-Pulse Thyristor Harmonic Model withPSCAD/EMTDC for Test Case 2

h PSCAD Derived Harmonic Model3 59.3s 0.64s11 59.3s 3.31s17 59.3s 8.00s31 59.3s 45.67s

6.3.1.5 12-Pulse Diode Converter Harmonic Model

The computation times for solving for the 12-pulse diode converter harmonics using

i) the derived harmonic model, and ii) PSCAD/EMTDC, for the 4 different values of

h, are presented in Table 6.11. In calculating these results, the Simplex block for the

Page 98: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 92

PSCAD/EMTDC simulation is defined to solve for the α control parameter using the

constraint equation ∆Pdc = |Pdc − P refdc | < 0.001. Note, PSCAD/EMTDC required 3

simulations of the system to converge to the solution.

Table 6.12: Comparing Computation Time of 12-Pulse Diode Harmonic Model withPSCAD/EMTDC for Test Case 2

h PSCAD Derived Harmonic Model3 14.1s 0.93s11 14.1s 4.81s17 14.1s 10.94s31 14.1s 61.85s

In generating the results of Table 6.8–6.12, the the control parameters in both PSCAD/EMTDC

and OpenHarmonics were initialized to the same value. The convergence requirement

(0.001 pu) for PSCAD/EMTDC was chosen such that it is consistent with the con-

vergence requirement of the derived harmonic models. Finally, the PSCAD/EMTDC

simulations were performed with a simulation step size of 200µs.

6.3.1.6 Analysis of Results

The computation time for the derived harmonic models as shown in Table 6.8–6.12 in-

creases quadratically with h. At lower values of h such as h = 3, h = 11 and h = 17

the 5 derived harmonic models outperform PSACD/EMTDC; however, because the com-

putation time of PSCAD/EMTDC is effectively constant with h while the computation

time for the harmonic models increase quadratically with h, there is a point at which

PSCAD/EMTDC begins to outperform the harmonic models. For the test case 2 input

parameters used to generate the tables, this point occurs between h = 17 and h = 31 for

the 12-pulse diode harmonic model and at some value of h > 31 for the other 4 harmonic

models. However, since the harmonic models allow the user to specify specific harmonics

to analyze there is generally not a need to analyze more than a few harmonics. For

example, in cases where the utility is concerned with a specific harmonic frequency such

as the 5th harmonic in their system, the harmonics that typically make the most effect

on this harmonic are the 1st, 5th, and 7th and as such the system can be solved just

for these three harmonics; and as the results show, for h = 3 the harmonic models are

generally 1 to 2 orders of magnitude faster than PSCAD/EMTDC.

Page 99: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 93

All this being said, the harmonic models were derived for the purposes of being used

to analyze systems with multiple converter interfaced loads and generators. As such, it

is more important to look at the computation time when multiple converters are being

solved for as is done in OpenHarmonics. When solving for the system harmonics the

slowest harmonic model will dictate how long the simulation takes in PSCAD/EMTDC.

As an example, in a system containing a 12-pulse diode converter and a VSC, if the

12-pulse diode converter model converges to a solution in 3 simulation runs and the

VSC harmonic model converges in 60 simulation runs, the system would be expected to

require closer to 60 simulation runs to converge to a solution in PSCAD/EMTDC. The

slowest converter to solve in PSCAD/EMTDC is the VSC topology. At h = 31 the VSC

harmonic model, for the test case 2 inputs, was computed to be 129 times faster in solving

for the harmonics than PSCAD/EMTDC. Therefore when analyzing any system with a

VSC in PSCAD/EMTDC, OpenHarmonics can be expected to signficantly outperform

it. There are four main reasons why the PSCAD/EMTDC version of the VSC is much

slower than the LCC topologies: i) there are two control parameters rather then one; ii)

in order to reach steady-state solution the converter must run to 120 seconds whereas

the LCC models required running only to 12 seconds; iii) the control scheme is more

computationally intensive and iv) the initialization values for the control parameters of

the LCC models are much closer to the final values of the control parameters when a

solution is found than the initialization values for the control parameters of the VSC

model are.

6.3.2 OpenHarmonics

The computation times for performing the study of the modified IEEE 13-Bus Test

System, outlined in Section 6.2.2, in OpenHarmonics for four different values of h are

presented in Table 6.13.

Page 100: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 94

Table 6.13: Computation Times of OpenHarmonics for Modified IEEE 13-Bus Test Sys-tem for Different Values of h

h OpenHarmonics3 17.1s11 69.6s17 178.0s31 795.3s

6.3.2.1 Analysis of Results

The computation times required to solve the modified IEEE 13-Bus Test System, shown

in Table 6.13, increase quadratically with h. This is because, though the computation

time of OpenDSS increases linearly with h, solving the harmonic models constitute the

majority of the computation time of a OpenHarmonics simulation. It is important to

note that while for h = 31 the computation time required to solve for a solution was 13.3

min, this is computationally efficient in comparison to PSCAD/EMTDC. It was shown in

Table 6.8 that solving just the VSC in PSCAD/EMTDC required a computation time of

53.8 minutes for the test case 2 inputs. Furthermore, considering that the solution of the

modified IEEE 13-Bus Test System in PSCAD/EMTDC would involve simultaneously

solving for 4 additional converters it is likely that OpenHarmonics would offer at least a

4 times improvement in computation time over PSCAD/EMTDC for the modified IEEE

13-Bus Test System.

6.4 Summary

In this chapter, it was shown that the harmonic models offer similar accuracy to PSCAD/EMTDC

while at the same time decreasing the overall engineering time required to analyze the

steady-state harmonics on a network. In the first evaluation study of this chapter,

the harmonic models and OpenHarmonics were shown to have comparable accuracy to

PSCAD/EMTDC; when comparing the harmonic models the maximum discrepancy be-

tween the derived harmonic models and PSCAD/EMTDC was calculated as less then

0.4%. In the second evaluation study of this chapter, the harmonic models were com-

pared to PSCAD/EMTDC in terms of computation time and it was shown that from

h = 1 to h = 17 the harmonic models had consistently lower computation times to

Page 101: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 6. Results 95

PSCAD/EMTDC. Furthermore, it was shown that OpenHarmonics should offer at least

a factor of 4 increase in speed over PSCAD/EMTDC for the analysis of the modififed

IEEE 13-Bus Test System.

It is important to note that the harmonic models and the OpenHarmonics tool have

not been optimized in terms of computation time whereas PSCAD/EMTDC has. There-

fore there is significant scope to reduce these computation times. The harmonic models

and OpenHarmonics currently exist as MATLAB M-files. By compiling these M-files,

the computation time could be immediately reduced by a factor of 2 or 3.

Page 102: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 7

Conclusions and Future Work

7.1 Conclusions

In this thesis, a harmonic analysis tool, called OpenHarmonics, is presented that is de-

signed to perform high accuracy, computationally efficient, steady-state harmonic analy-

sis studies of distribution systems with multiple converter interfaced generators and loads.

OpenHarmonics is proposed as a middle ground solution between the computationally

intensive time-domain based harmonic analysis tools and the frequency-domain based

harmonic analysis tools that employ primitive harmonic models of converter topologies.

The key differentiating feature of OpenHarmonics is the built-in harmonic models of

common converter topologies. These models and their solution are the core contribution

of this thesis. The software tool OpenHarmonics provides one possible application of

these models. These harmonic models improve upon state-of-the-art in the following 3

areas:

1. High accuracy. By minimizing assumptions, the harmonic models are highly

accurate even in systems where the PCC is both unbalanced and has significant

levels of harmonic distortion (both even and odd harmonics).

2. Computatonally efficient design. The modelling is done using space-vector

component analysis which reduces the number of states to solve, and allows a real

valued FCM formulation. Furthermore, the control parameters of the closed loop

formulations are solved for using an exact Jacobian—which significantly reduces

the number of iterations to converge to a solution.

96

Page 103: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 7. Conclusions and Future Work 97

3. Convenient inputs. The harmonic models were designed to be incorporated into

an existing harmonic analysis tool with minimal modification.

In this thesis, it was shown that OpenHarmonics is more accurate than many of the

existing frequency-domain based harmonic analysis tools when analyzing systems with

converter interfaced loads and generators. This is because, unlike these tools, Open-

Harmonics i) solves for non-characteristic harmonics and ii) models harmonic variations

associated with load dependent changes in overlap angle. The accuracy of OpenHar-

monics and the 5 harmonic models was verified against detailed time-domain simulation

results. When verifying the accuracy of the harmonic models, the results were shown

to have a maximum error of less than 0.4% when compared to PSCAD/EMTDC. When

comparing the accuracy of OpenHarmonics to PSCAD/EMTDC, the results were shown

to have a high degree of correspondence as well. Furthermore, it was shown that Open-

Harmonics has the ability to reduce the overall engineering time involved in analyzing the

steady-state harmonics on a network. This is done by i) abstracting converter controller

design from the analysis and ii) having faster computation times than PSCAD/EMTDC

when controller design is abstracted from the analysis.

Though, the harmonic models developed in this thesis were functionally shown to

work with OpenDSS through the OpenHarmonics harmonic analysis tool, it is possible

to extend the models to additional software tools that feature a built-in COM interface,

with minimal modifications. These harmonic models are envisioned to be a first step

in improving the accuracy of the frequency-domain based harmonic analysis simulation

tools by accounting for the interaction between different harmonic sources on the system.

As the number of converter interfaced loads and generators increase on the grid, and

regulation standards for these converters become more stringent, the need for a tool such

as OpenHarmonics to provide accurate, computationally efficient, steady-state harmonic

analysis of systems with multiple converter interfaced loads and generators will become

that much more important.

7.2 Future Work

There are many avenues in which this thesis can be extended in the future. The next

two sections describe how the functionality of OpenHarmonics and the harmonic models

could be extended.

Page 104: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Chapter 7. Conclusions and Future Work 98

OpenHarmonics

The rate of convergence for OpenHarmonics could be improved if the FCM solved for, for

each of harmonic converter models, was incorporated into the overall system admittance

matrix. To do this, the OpenDSS engine used in OpenHarmonics would have to be

replaced with a custom engine. The features of OpenHarmonics could also be extended

in the future to incorporate post-processing capabilities. As an example, given the solved

line current harmonics, it would be possible to use this information to automatically

locate and size filters in the analyzed system.

Harmonic Models

The assumptions about the converter operation could be relaxed for the line commutated

converter harmonic models to include additional modes of operation such as discontinuous

conduction model. Additional control schemes could be added for the VSC and thyristor-

switched models. Finally, harmonic models could be derived for additional converter

topologies. As an example, adding a back emf for the thyristor bridge converters would

be useful in modelling HVDC. Additional topologies of interest are a 3-level VSC, 18

pulse rectifier, 24 pulse rectifier and various multimodular converter topologies.

Page 105: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Bibliography

[1] J. Arrillaga and N. R. Watson, Power system harmonics. Wiley, 2003.

[2] T. F. on Harmonics Modeling and Simulation, “Modeling and simulation of the prop-

agation of harmonics in electric power networks. i. concepts, models, and simulation

techniques,” IEEE Trans. Power Del., vol. 11, no. 1, pp. 452–465, Jan. 1996.

[3] P. S. Harmonics, “Power system harmonics: An overview,” IEEE Trans. Power App.

Syst., vol. PAS-102, no. 8, pp. 2455–2460, 1983.

[4] T. F. on Harmonics Modeling and Simulation, “Characteristics and modeling of

harmonic sources-power electronic devices,” IEEE Trans. Power Del., vol. 16, no. 4,

pp. 791–800, Oct. 2001.

[5] C. M. Osauskas, D. J. Hume, and A. R. Wood, “Small signal frequency domain model

of an hvdc converter,” in IEE Proc. Generation, Transmission & Distribution, vol.

148, no. 6, Nov. 2001, pp. 573–578.

[6] A. R. Wood and C. M. Osauskas, “A linear frequency-domain model of a statcom,”

IEEE Trans. Power Del., vol. 19, no. 3, pp. 1410–1418, July 2004.

[7] W. Xu, J. E. Drakos, Y. Mansour, and A. Chang, “A three-phase converter model

for harmonic analysis of hvdc systems,” IEEE Trans. Power Del., vol. 9, no. 3, pp.

1724–1731, 1994.

[8] M. Mohaddes, A. M. Gole, and S. Elez, “Steady state frequency response of stat-

com,” IEEE Trans. Power Del., vol. 16, no. 1, pp. 18–23, 2001.

[9] M. Madrigal and E. Acha, “Modelling of custom power equipment using harmonic

domain techniques,” in Int. Conf. Harmonics and Quality of Power, vol. 1, 2000,

pp. 264–269 vol.1.

99

Page 106: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Bibliography 100

[10] P. W. Lehn and K. L. Lian, “Frequency coupling matrix of a voltage-source con-

verter derived from piecewise linear differential equations,” IEEE Trans. Power Del.,

vol. 22, no. 3, pp. 1603–1612, July 2007.

[11] K. L. Lian and P. W. Lehn, “A time-domain method for calculating harmonics

produced by a power converter,” in Int. Conf. Power Electron. and Drive Systems,

Nov. 2009, pp. 528–532.

[12] E. V. Larsen, D. H. Baker, and J. C. McIver, “Low-order harmonic interactions on

ac/dc systems,” IEEE Trans. Power Del., vol. 4, no. 1, pp. 493–501, Jan. 1989.

[13] M. Fauri, “Harmonic modelling of non-linear load by means of crossed frequency

admittance matrix,” IEEE Trans. Power Syst., vol. 12, no. 4, pp. 1632–1638, Nov.

1997.

[14] Y. Sun, G. Zhang, W. Xu, and J. G. Mayordomo, “A harmonically coupled admit-

tance matrix model for ac/dc converters,” IEEE Trans. Power Syst., vol. 22, no. 4,

pp. 1574–1582, Nov. 2007.

[15] B. C. Smith, N. R. Watson, A. R. Wood, and J. Arrillaga, “Harmonic tensor lineari-

sation of hvdc converters,” IEEE Trans. Power Del., vol. 13, no. 4, pp. 1244–1250,

Oct. 1998.

[16] N. Rajagopal and J. E. Quaicoe, “Harmonic analysis of three-phase ac/dc converters

using the harmonic admittance method,” in Canadian Conf. Elect. and Comput.

Eng., vol. 1, Sep. 1993, pp. 313–316.

[17] R. Carbone, A. L. Schiavo, P. Marino, and A. Testa, “A new method based on

periodic convolution for sensitivity analysis of multi-stage conversion systems,” in

Proc. 9th Int. Conf. Harmonics and Quality of Power, vol. 1, 2000, pp. 69–74.

[18] P. W. Lehn, “Direct harmonic analysis of the voltage source converter,” IEEE Trans.

Power Del., vol. 18, no. 3, pp. 1034–1042, July 2003.

[19] ——, “Exact modeling of the voltage source converter,” IEEE Trans. Power Del.,

vol. 17, no. 1, pp. 217–222, Jan. 2002.

Page 107: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Bibliography 101

[20] K. L. Lian and P. W. Lehn, “Steady-state solution of a voltage-source converter

with full closed-loop control,” IEEE Trans. Power Del., vol. 21, no. 4, pp. 2071–

2081, 2006.

[21] P. W. Lehn and G. Ebner, “Harmonic modelling of thyristor bridges using a sim-

plified time domain method,” in IEEE Int. Conf. Harmonics and Quality of Power,

Oct. 2006.

[22] K. L. Lian, B. K. Perkins, and P. W. Lehn, “Harmonic analysis of a three-phase diode

bridge rectifier based on sampled-data model,” IEEE Trans. Power Del., vol. 23,

no. 2, pp. 1088–1096, April 2008.

[23] K. L. Lian and P. W. Lehn, “Harmonic analysis of single-phase full bridge rectifiers

based on fast time domain method,” in IEEE Int. Symp. Ind. Electron., vol. 4, 2006,

pp. 2608–2613.

[24] G. Carpinelli, F. Iacovone, A. Russo, P. Varilone, and P. Verde, “Analytical modeling

for harmonic analysis of line current of vsi-fed drives,” IEEE Trans. Power Del.,

vol. 19, no. 3, pp. 1212–1224, 2004.

[25] B. C. Smith, J. Arrillaga, A. R. Wood, and N. R. Watson, “A review of iterative

harmonic analysis for ac-dc power systems,” IEEE Trans. Power Del., vol. 13, no. 1,

pp. 180–185, Jan. 1998.

Page 108: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A

Harmonic Model Derivations

A.1 VSC Harmonic Model Differential Equations

In this section, the differential equations of the unknown converter states are derived for

the assumed VSC model in Fig. 7.1. The differential equations of interest are: disαdt

,disβdt

and dvdcdt

.

Solving for disαdt

anddisβdt

First, Kirchoff’s Voltage Law is applied to each of the three phases of Fig. 7.1. This

results in the following 3 equations,

−vsa +Risa + Ldisadt

+ Savdc + voff =0 (7.1a)

−vsb +Risb + Ldisbdt

+ Sbvdc + voff =0 (7.1b)

−vsc +Risc + Ldiscdt

+ Scvdc + voff =0 (7.1c)

It is convenient, for the subsequent analysis, to combine the equations in (7.1) into a

vector as is done in (7.2),

−~vsabc +R~isabc + Ld~isabcdt

+

Sa

Sb

Sc

vdc +

1

1

1

voff = 0 (7.2)

102

Page 109: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 103

R

L

RR

L L

isbisc isa

vdc

Q

Sa Sb Sc

Sa’ Sb’ Sc’

idcCdc

P

vtab

vtbc

Rdc

vsa

vsb

vsc

voff

Figure 7.1: Assumed VSC Topology

(7.2) can be re-arranged for d~isabcdt

as is done in (7.3),

d~isabcdt

= −R

L~isabc −

1

L

Sa

Sb

Sc

vdc +1

L~vsabc −

1

L

1

1

1

voff (7.3)

The states in (7.3) can be translated into the space-vector by pre-multiplying by the

inverse of Clarke Transform, C, as is done in (7.4),

C−1d~isαβ0dt

= −R

LC−1~isαβ0 −

1

L

Sa

Sb

Sc

vdc +1

LC−1~vsαβ0 −

1

L

1

1

1

voff (7.4)

where,

Page 110: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 104

C =2

3

1 −1/2 −1/2

0√3/2 −

√3/2

1/√2 1/

√2 1/

√2

Left-multiplying (7.4) by C, yields (7.5),

d~isαβ0dt

= −R

L~isαβ0 −

1

LC

Sa

Sb

Sc

vdc +1

L~vsαβ0 −

1

L

0

0√2

voff (7.5)

Because of the converter topology, there is no zero-sequence current component and as

such only the αβ states of the currents are of interest. Therefore, eliminating zero-

sequence current from (7.5), yields (7.6),

d~isαβdt

= −R

L~isαβ −

1

L

[

2/3 −1/3 −1/3

0√3/2 −

√3/2

]

Sa

Sb

Sc

vdc +1

L~vsαβ (7.6)

Solving for didcdt

First, Kirchoff’s Current Law is applied to the dc-side of the converter yielding (7.7),

Cdcdvdcdt

− Saisa − Sbisb − Scisc +1

Rdc

vdc + idc = 0 (7.7)

(7.7) can be re-arranging for dvdcdt

as is done in (7.8)

dvdcdt

=1

Cdc

[

Sa Sb Sc

]

~isabc −1

CdcRdcvdc −

1

Cdcidc (7.8)

(7.9) is the resulting equation for didcdt

when relevant states in (7.8) are translated into

the space vector reference frame and the zero-sequence component is neglected,

dvdcdt

=1

Cdc

[

Sa Sb Sc

]

1 0

−1/2√3/2

−1/2 −√3/2

~isαβ −1

CdcRdcvdc −

1

Cdcidc (7.9)

The submatrices A and B of the M matrix of (2.10), can be obtained from the above

derivations. The submatrix A can be extracted from (7.6) and (7.8). If (3.14) is sub-

Page 111: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 105

stituted in (7.6) and (7.8), submatrix B can be extracted from the resulting expression.

These submatrices are shown in (7.10),

A =

−R

L0 −1/3

L(2Sa − Sb − Sc)

0 −R

L−√3/2

L(Sb − Sc)

1

Cdc(Sa − 1/2Sb − 1/2Sc)

√3/2

Cdc(Sb − Sc) − 1

RdcCdc

(7.10a)

B =

1

L0 · · · 1

L0 0 0 0 · · · 0 0

01

L· · · 0

1

L0 0 0 · · · 0 0

0 0 · · · 0 0 − 1

Cdc− 1

Cdc0 · · · − 1

Cdc0

(7.10b)

A.2 6-Pulse Topology Differential Equations

A.2.1 Commutation Interval

In this section, the differential equations of states isα, isβ and idc are derived for the

Fig. 7.2 configuration of the 6-pulse converter topology. This configuration is for the

commutation interval immediately following the gating of switch 1 which occurs at t = t1.

Rdc

Ldc

idc

R

R L

Lisb

isc

isa

-vsb+

-vsc+

-vsa+R L

vdc

Figure 7.2: 6-Valve Configuration from t = t1 to t = t2

Page 112: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 106

Solving for disαdt

anddisβdt

If Kirchoff’s Voltage Law is applied to Fig. 7.2, the following 2 equations in can be

derived,

0 =− vsa + (R +Rdc)isa + (L+ Ldc)disadt

− L

2

disbdt

− L

2

discdt

− R

2isb −

R

2isc +

1

2vsb +

1

2vsc

(7.11a)

0 =vsb − vsc −Risb +Risc − Ldisbdt

+ Ldiscdt

(7.11b)

(7.12) is the result of performing the following on (7.11): i) translating the relevant

states into the space-vector reference frame, ii) combining related states into vectors, iii)

eliminating zero-sequence components,

[

3/2L+ Ldc 0

0√3L

]

d~isαβdt

=

[

−3/2R− Rdc 0

0 −√3R

]

~isαβ +

[

3/2 0

0√3

]

~vsαβ (7.12)

Solving (7.12) ford~isαβ

dtresults in (7.13),

d~isαβdt

=

−3R + 2Rdc

3L+ 2Ldc0

0 −R

L

~isαβ +

3

3L+ 2Ldc0

01

L

~vsαβ (7.13)

Solving for didcdt

If Kirchoff’s Voltage Law is applied to Fig. 7.2, the following expression in (7.14) can be

derived,

0 = −vsa + (3/2R+Rdc)idc + (3/2L+ Ldc)idcdt

+1

2vsb +

1

2vsc (7.14)

(7.15) is the result of re-arranging (7.14) for didcdt

and translating relevant state variables

into space-vector format,

didcdt

= −3/2R +Rdc

3/2L+ Ldcidc +

[

3/2 0]

~vsαβ (7.15)

Page 113: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 107

Submatrices A and B can be extracted from (7.15) and (7.13) as is shown in (7.16),

A =

−3R + 2Rdc

3L+ 2Ldc0 0

0 −R/L 0

0 0 −3/2R +Rdc

3/2L+ Ldc

(7.16a)

B =

3

3L+ 2Ldc

0 · · · 3

3L+ 2Ldc

0

01

L· · · 0

1

L3/2 0 · · · 3/2 0

(7.16b)

A.2.2 Conduction Interval

In this section, the differential equations of states isα, isβ and idc are derived for the

Fig. 7.3 configuration of the 6-pulse converter topology. This configuration is for the

conduction interval that follows the commutation interval immediately after the gating

of switch 1 which occurs at t = t2.

Rdc

Ldc

idc

vdc

R L

R Lisc

isa

vsc

vsa

Figure 7.3: 6-Pulse Configuration from t = t2 to t = t3

Solving for disαdt

anddisβdt

Applying Kirchoff’s Voltage Law to Fig. 7.3, the following two equations can be derived,

0 =− vsa + (2R +Rdc)isa + (2L+ Ldc)disadt

+ vsc (7.17a)

0 =− vsc + (2R +Rdc)isb + (2L+ Ldc)disbdt

+ vsa (7.17b)

Page 114: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 108

Translating the expressions in (7.17) into space-vector format through Clarke Transform

C, eliminating the zero-sequence components from the analysis, and combining related

states into vectors, yields (7.18),

0 =[

2L+ Ldc 0] d~isαβ

dt+[

2R +Rdc 0]

~isαβ −[

3/2√3/2]

~vsαβ (7.18a)

0 =(2L+ Ldc)[

−1/2√3/2] d~isαβ

dt+ (2R+Rdc)

[

−1/2√3/2]

~isαβ +[

3/2√3/2]

~vsαβ

(7.18b)

The 2 expressions in (7.18) can be combined and from the resulting expressiond~isαβ

dtcan

be calculated as shown in (7.19),

d~isαβdt

= −2R +Rdc

2L+ Ldc

[

1 0

0 1

]

~isαβ +1

2L+ Ldc

[

3/2√3/2

−√3/2 −1/2

]

~vsαβ (7.19)

Solving for idcdt

Applying Kirchoff’s Voltage Law to Fig. 7.3, (7.20) can be derived,

0 = −vsa + (2R +Rdc)idc + (2L+ Ldc)didcdt

+ vsc (7.20)

Re-arranging (7.20) for didcdt

and translating relevant states to space-vector format, results

in (7.21),didcdt

= −2R +Rdc

2L+ Ldc

idc +1

2L+ Ldc

[

3/2√3/2]

~vsαβ (7.21)

Submatrices A and B, that describe this configuration of the 6-pulse topology, can be

extrapolated from (7.21) and (7.19). They are shown here in (7.22),

A =− 2R +Rdc

2L+ Ldc

1 0 0

0 1 0

0 0 1

(7.22a)

B =1

2L+ Ldc

3/2√3/2 · · · 3/2

√3/2

−√3/2 −1/2 · · · −

√3/2 −1/2

3/2√3/2 · · · 3/2

√3/2

(7.22b)

Page 115: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 109

A.3 12-Pulse Topology Differential Equations

A.3.1 Relating Primary and Secondary Sides of 12-Pulse Topol-

ogy

In this section, equations are derived that relate the 3-phase currents drawn by the 12-

pulse topology, shown in Fig. 4.4, to the transformer secondary side currents. The

3-phase currents drawn by the converter are isa, isb and isc and these states are related

to the primary-side currents of the Y-Y and Y-∆ transformer through the 3 equations in

(7.23),

isa =iY psa + i∆p

sa (7.23a)

isa =iY psb + i∆p

sb (7.23b)

isc =iY psc + i∆p

sc (7.23c)

In the next 2 sections, equations are derived that relate the primary side transformer

currents ~iY psabc and

~i∆psabc to the secondary side currents ~iYsabc and ~i

∆sabc.

Relating ~iY psabc to ~iYsabc

The two modelled transformers are assumed to have a 1:1 turns ratio. As such, vectors

~iY psabc and

~iYsabc are equivalent, which is expressed in matrix format in (7.24),

iY psa

iY psb

iY psc

=

1 0 0

0 1 0

0 0 1

iYsa

iYsb

iYsc

(7.24)

Relating ~i∆psabc to ~i∆sabc

In deriving an equation that relates the vector ~i∆psabc to ~i∆sabc, it is convenient to zoom in

on the modelled Y-∆ transformer as is done in Fig. 7.4. From Fig. 7.4, the equations of

Page 116: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 110

D

sai

D

sbi

D

sci

p

saiD

p

sbiD

p

sciD

1:1

a

b

c

+

-+ -

+

- +

-

sbv3

sav3scv3

sav

sbv

scv

+-

-

+

s

saiD

s

sbiD

s

sciD

Figure 7.4: Primary and Secondary Side of Y-∆ Transformer

(7.25), can be derived by inspection,

i∆sa =i∆ssc − i∆s

sa (7.25a)

i∆sb =i∆ssa − i∆s

sb (7.25b)

i∆sc =i∆ssb − i∆s

sc (7.25c)

Because, it is assumed that the secondary of the transformer lags the primary by 30 deg,

the secondary and primary side currents of the transformer are related as shown in (7.26),

i∆ssa =

1√3i∆psa (7.26a)

i∆ssb =

1√3i∆psb (7.26b)

i∆ssc =

1√3i∆psc (7.26c)

If (7.26) is substituted into (7.25), the following 3 equations result,

i∆sa =1√3

(

i∆psc − i∆p

sa

)

(7.27a)

i∆sb =1√3

(

i∆psa − i∆p

sb

)

(7.27b)

i∆sc =1√3

(

i∆psb − i∆p

sc

)

(7.27c)

Page 117: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 111

Because no zero sequence current circulates in the 12-pulse topology, the following rela-

tion is true,

i∆psa + i∆p

sb + i∆psc = 0 (7.28)

(7.28) can be re-arranged for i∆psa , i

∆psa and i∆p

sa (i.e. i∆psa = −i∆p

sb − i∆psc , ...). If these 3

equations are substituted into (7.27a), (7.27b) and (7.27c), and the resulting equations

are then combined into matrix format, (7.29) is the result,

i∆sa

i∆sb

i∆sc

=1√3

−2 −1 0

0 −2 −1

−1 0 −2

i∆psa

i∆psb

i∆psc

(7.29)

Inverting (7.29), results in (7.30),

i∆psa

i∆psb

i∆psc

=1

3√3

−4 2 −1

−1 −4 2

2 −1 −4

i∆sa

i∆sb

i∆sc

(7.30)

If (7.30) and (7.24) are substituted into (7.23), (7.31) results,

isa

isb

isc

=

1 0 0

0 1 0

0 0 1

iYsa

iYsb

iYsc

+1

3√3

−4 2 −1

−1 −4 2

2 −1 −4

i∆sa

i∆sb

i∆sc

(7.31)

(7.31) can be translated over to the space-vector reference frame by utilizing the Clarke

Transform and eliminating the zero-sequence current component as is shown in (7.32),

[

isα

isβ

]

=1√3

[

2/√3 −1/

√3 −1/

√3

0 1 −1

]

iYsa

iYsb

iYsc

+1√3

[

−1 1 0

−1/√3 −1/

√3 2/

√3

]

i∆sa

i∆sb

i∆sc

(7.32)

This equation relates the primary and secondary side currents of the 12-pulse topology.

A.3.2 Conduction Interval

In this section, the differential equations of states isα, isβ and idc are derived for the Fig.

7.5 configuration of the 12-pulse converter topology. This configuration describes the

Page 118: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 112

conduction interval that follows the gating of switch 1 (switch 1 is gated at t = t1). The

12-pulse converter topology assumes this configuration from t = t2 to t = t3.

R L

R L

Rdc

Ldc

idcY

sai

Y

sci

vdcR L

R L

D

sai

s

saiD

vsc

vsa

sav3

s

sb

s

sc iiDD ,

scv3

sbv3

Figure 7.5: 12-Pulse Converter Configuration from t = t2 to t = t3

Deriving didcdt

Applying Kirchoff’s Voltage Law to 7.5, (7.33) can be derived,

0 = −(1 +√3)vsa + vsc + (4R +Rdc)idc + (4L+ Ldc)

didcdt

(7.33)

Translating relevant states in (7.33) to space vector format, and re-arranging for didcdt

results in (7.34)

didcdt

= −4R +Rdc

4L+ Ldcidc +

1

4L+ Ldc

[

3/2 +√3

√3/2]

~vsαβ (7.34)

Deriving disαdt

anddisβdt

The following relations can be derived from Fig. 7.5 by inspection,

idc =iYsa = −iYsc = i∆sa = −i∆sb (7.35a)

0 =iYsb = i∆sc (7.35b)

Page 119: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 113

It is convenient to express the converter states of (7.35) in terms of idc. If this is done

and the resulting expressions are substituted into (7.32), an expression ford~isαβ

dtin terms

of idc results. The result of simplifying and taking the time-derivative of this expression,

is shown here in (7.36),

d

dt

[

isα

isβ

]

=

[

1 + 2/√3

1/√3

]

didcdt

(7.36)

The equation for didcdt

, (7.34), can be substituted into (7.36), resulting in (7.37) ford~isαβ

dt,

d~isαβdt

= −4R +Rdc

4L+ Ldc

[

1 + 2/√3

1/√3

]

idc +1

4L+ Ldc

[

7/2 + 2√3 1 +

√3/2

1 +√3/2 1/2

]

~vsαβ (7.37)

Submatrices A and B, describing this converter configuration, can be extrapolated from

(7.37) and (7.34). They are shown here in (7.38),

A =− 4R +Rdc

4L+ Ldc

0 0 1 + 2/√3

0 0 1/√3

0 0 1

(7.38a)

B =1

4L+ Ldc

7/2 + 2√3 1 +

√3/2 · · · 7/2 + 2

√3 1 +

√3/2

1 +√3/2 1/2 · · · 1 +

√3/2 1/2

3/2 +√3

√3/2 · · · 3/2 +

√3

√3/2

(7.38b)

A.3.3 Commutation Interval 1

In this section, the differential equations of states isα, isβ and idc are derived for the Fig.

7.6 configuration of the 12-pulse converter topology. This configuration describes the

commutation interval that follows the gating of switch 1 (switch 1 is gated at t = t1).

The 12-pulse converter topology assumes this configuration from t = t1 to t = t2.

Deriving didcdt

Applying Kirchoff’s Voltage Law to Fig. 7.6, (7.39) can be derived,

0 = −vsa + (7/2R+Rdc)idc + (7/2L+ Ldc)didcdt

−√3vsa + 1/2(vsb + vsc) (7.39)

Page 120: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 114

R L

R L

Rdc

Ldc

idc

Y

sbi

Y

scivdc

R L

R L

s

saiD

s

sbiD

vsc

vsb

sav3

s

sb

s

sc ii DD ,

R LY

saivsa

scv3

sbv3

s

saiD

vloop

Figure 7.6: 12-Pulse Converter Configuration from t = t1 to t = t2

(7.40) is the result of re-arranging (7.39) for didcdt

and then converting relevant states into

space-vector format,

didcdt

= −7/2R +Rdc

7/2L+ Ldcidc +

1

7/2L+ Ldc

[

3/2 +√3 0

]

~vsαβ (7.40)

Deriving disαdt

anddisβdt

It is useful in the analysis to solve for the commutation loop voltage in terms of the idc

converter state. Therefore, Kirchoff’s Voltage Law is applied to the commutation loop,

from which the following 2 equations can be derived,

vloop =− vsb +RiYsb + LdiYsbdt

(7.41a)

vloop =− vsc +RiYsc + LdiYscdt

(7.41b)

where, vloop is the voltage difference across the commutation loop. If the equations of

(7.41) are summed, idc = −iYsb − iYsc is substituted, and the resulting expression is re-

Page 121: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 115

arranged for vloop, (7.42) results,

vloop = −R

2idc −

L

2

didcdt

− 1

2(vsb + vsc) (7.42)

If (7.42) is substituted into the 2 equations of (7.41), and the resulting equations are

re-arranged fordiY

sb

dtand diYsc

dt, respectively, (7.43) results,

diYsbdt

=− 1

2

didcdt

− R

2Lidc −

R

LiYsb +

1

L

[

0√3/2]

~vsαβ (7.43a)

diYscdt

=− 1

2

didcdt

− R

2Lidc −

R

LiYsc +

1

L

[

0 −√3/2]

~vsαβ (7.43b)

It is important to express iYsb and iYsc of (7.43) in terms of the converter states that are

being analyzed: isa, isb, isc and idc. As such, the following 2 equations are employed,

iYsb =isb − i∆psb (7.44a)

iYsc =isc − i∆psc (7.44b)

i∆psb and i∆p

sc can be solved by substituting the states of (7.45), expressed in terms of idc,

into (7.30). The results of simplifying the equation is shown here in (7.46),

idc =iYsa = −i∆sb = i∆sa (7.45a)

0 =i∆sc (7.45b)

i∆psa

i∆psb

i∆psc

=1√3

−1

2

−1

idc (7.46)

If (7.46) is substituted into (7.44) and the result of this is then substituted back into

(7.43), the following 2 equations result,

diYsbdt

=− 1

2

didcdt

− R

L

(

1/2 + 2/√3)

idc −R

L

[

−1/2√3/2]

~isαβ +1

L

[

0√3/2]

~vsαβ

(7.47a)

diYscdt

=− 1

2

didcdt

− R

L

(

1/2− 1/√3)

idc −R

L

[

−1/2 −√3/2]

~isαβ +1

L

[

0 −√3/2]

~vsαβ

(7.47b)

Page 122: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 116

If (7.47) and the time-derivatives of (7.45) are substituted into (7.32), and the resulting

expression is simplified, (7.47) results,

d

dt

[

isα

isβ

]

=

[

1− 2/√3

0

]

didcdt

+

[

0

−R/L

]

idc +

[

0 0

0 −R/L

]

~isαβ +

[

0 0

0 1/L

]

~vsαβ (7.48a)

If the equation for didcdt

, (7.40), is substituted into (7.48), the following expression for~isαβ

dt,

results,

d~isαβdt

= −

(

1− 2/√3) 7/2R +Rdc

7/2L+ Ldc

R/L

idc −R

L

[

0 0

0 1

]

~isαβ +

−1/2

7/2L+ Ldc0

0 1/L

~vsαβ

(7.49)

Submatrices A and B, for this configuration of the 12-pulse converter, can be derived

from (7.49) and (7.40). They are shown here in (7.50),

A =−

0 0(

1− 2/√3) 7/2R +Rdc

7/2L+ Ldc

0 R/L R/L

0 07/2R +Rdc

7/2L+ Ldc

(7.50a)

B =

−1/2

7/2L+ Ldc0 · · · −1/2

7/2L+ Ldc0

0 1/L · · · 0 1/L

3/2 +√3 0 · · · 3/2 +

√3 0

(7.50b)

A.3.4 Commutation Interval 2

In this section, the differential equations of states isα, isβ and idc are derived for the Fig.

7.7 configuration of the 12-pulse converter topology. This configuration describes the

commutation interval that follows the gating of switch 2 (switch 2 is gated at t = t3).

The 12-pulse converter topology assumes this configuration from t = t3 to t = t4.

Deriving didcdt

It is useful in the analysis to solve for the commutation loop voltage in terms of the idc

converter state. Therefore, Kirchoff’s Voltage Law is applied to the commutation loop,

Page 123: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 117

R L

R L

Rdc

Ldc

idcY

sai

Y

sci

vdcR L

R L

D

sai

D

sbi

vsc

vsa

sav3

s

sciD

R LD

scisbv3

s

saiD

s

sbiD

scv3

vloop

Figure 7.7: 12-Pulse Converter Configuration from t = t3 to t = t4

from which the following 2 equations can be derived,

vloop =− Ri∆sb − Ldi∆sbdt

(7.51a)

vloop =− Ri∆sc − Ldi∆scdt

−√3vsb (7.51b)

where vloop is the voltage difference across the commutation loop. If the equations of

(7.51) are summed and the resulting expression is re-arranged for vloop, (7.52) results,

vloop = −L

2

(

di∆sbdt

+di∆scdt

)

− R

2(i∆sb + i∆sc)−

√3

2vsb (7.52)

By inspection of Fig. 7.7, the following can be derived,

idc = i∆sb + i∆sc (7.53)

(7.53) can be substituted into (7.52) which results in the following equation for the

commutation loop voltage,

vloop =L

2

didcdt

+R

2idc −

√3

2vsb (7.54)

Page 124: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 118

Applying Kirchoff’s Voltage Law to Fig. 7.7, utilizing (7.14), (7.55) can be derived,

0 = −vsa + (7/2R +Rdc)idc + (7/2 + Ldc)didcdt

+

√3

2vsb + vsc (7.55)

(7.56) is the result of re-arranging (7.55) for idcdt, translating relevant states into space-

vector format and eliminating the zero-sequence components,

didcdt

= −7/2R +Rdc

7/2L+ Ldcidc −

√3/2

7/2L+ Ldc

[

−√3 + 1/2 −

√3/2 + 1

]

~vsαβ (7.56)

Deriving disαdt

anddisβdt

To solve ford~isαβ

dtit is necessary to solve for the time derivatives of the currents on the

secondary side of the converter. From inspection of Fig. 7.7, the time-derivatives of the

following secondary currents can be immediately derived,

didcdt

=diYsadt

= −diYscdt

=di∆sadt

(7.57a)

0 =diYsbdt

(7.57b)

To derivedi∆

sb

dtand di∆sc

dt, (7.54) is substituted into (7.51), the result is (7.58),

0 =Ri∆sb + Ldi∆sbdt

+L

2

didcdt

+R

2idc −

√3

2vsb (7.58a)

0 =Ri∆sc + Ldi∆scdt

+L

2

didcdt

+R

2idc +

√3

2vsb (7.58b)

Where,

i∆sb =isb − iYsb (7.59a)

i∆sc =isc − iYsc (7.59b)

By inspection of Fig 7.7, it is known that iYsb = 0 and iYsc = −idc. These 2 equations can

be substituted into (7.59), resulting in (7.60),

i∆sb =isb (7.60a)

i∆sc =isc + idc (7.60b)

Page 125: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 119

(7.61) results from substituting (7.60) into (7.58), and then re-arranging the resulting

equations fordi∆

sb

dtand di∆sc

dtand translating relevant states into space vector format,

di∆sbdt

=− 1

2

didcdt

+

√3/2

L

[

−1/2√3/2]

~vsαβ −R

L

[

−1/2√3/2]

~isαβ −1

2

R

Lidc (7.61a)

di∆scdt

=− 1

2

didcdt

−√3/2

L

[

−1/2√3/2]

~vsαβ −R

L

[

−1/2 −√3/2]

~isαβ −3

2

R

Lidc

(7.61b)

If (7.61) and (7.57) are substituted into (7.32) and the resulting equation is simplified,

the following equation for~isαβ

dt, results,

d

dt

[

isα

isβ

]

=

[

3−√3/2

1/√3− 1/2

]

didcdt

+1

4

1

L

[

−1√3

√3 −3

]

~vsαβ+1

2

R

L

[

1/√3 −1

1/3√3

]

~isαβ−1

2

R

L

[

1/√3

5/3

]

idc

(7.62)

(7.56) can be substituted into (7.62), yielding the expression fordisαβ

dtin (7.63),

disαβdt

=1

2

R

L

[

1/√3 −1

1/3√3

]

~isαβ −

(

1−√3

2

)

7/2R +Rdc

7/2L+ Ldc+

1

2√3

R

L(

1√3− 1

2

)

7/2R+Rdc

7/2L+ Ldc+

5

6

R

L

idc

+

−1/4

L+

3/8

7/2L+ Ldc

√3/4

L+

√3/2− 3

√3/8

7/2L+ Ldc√3/4

L+

1/2− 3√3/4

7/2L+ Ldc

−3/4

L+

1/8

7/2L+ Ldc

~vsαβ (7.63)

Submatrices A and B, for this configuration of the 12-pulse converter, can be extrap-

Page 126: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 120

olated from (7.62) and (7.57). They are shown here in (7.64),

A =

1

2√3

R

L−1

2

R

L

(

1−√3

2

)

7/2R+Rdc

7/2L+ Ldc+

1

2√3

R

L

1

6

R

L

√3

2

R

L

(

1√3− 1

2

)

7/2R+Rdc

7/2L+ Ldc+

5

6

R

L

0 0 −7/2R +Rdc

7/2L+ Ldc

(7.64a)

B =

−1/4

L+

3/8

7/2L+ Ldc

√3/4

L+

√3/2− 3

√3/8

7/2L+ Ldc· · ·

√3/4

L+

1/2− 3√3/4

7/2L+ Ldc−3/4

L+

1/8

7/2L+ Ldc· · ·

3/2 + 3√3/4

7/2L+ Ldc

3/4 +√3/2

7/2L+ Ldc· · ·

(7.64b)

A.4 Initializing Control Parameters

A.4.1 VSC Model

In initializing the control variables, ma and δ, it is assumed that the PCC is balanced

with negligible harmonic distortion. Given these assumptions, the three-phase complex

power of the converter can be calculated, by analyzing phase-a, as shown in (7.65),

S ≈3

2V

+1

sa I+1∗

sa (7.65a)

≈Pdc + jQac (7.65b)

Expanding out the I+1∗

sa in (7.65), yields (7.66), which is an expression for the three-phase

real and reactive power of the system in terms of the system voltages and impedances,

Pdc + jQac =3

2V

+1

sa

(

V+1

sa − V+1

ta

R + jωLL

)

(7.66)

If the expression (3.2), for the terminal voltage of the converter for phase a, is converted

to phaser format, (7.67) results,

V+1

ta =Vdc

2ma∠(δ + ∠V

+1

sa ) (7.67)

Page 127: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 121

Convenient expressions for Pdc and Qac can be derived from (7.66) if (7.67) is substituted

into (7.66) and the reference phase is set to 0, ∠V+1

sa = 0. Note, from this point on v+1sαβ

is used in place of V+1

sa as the these states are equivalent if both specified at a time t.

The resulting expressions for Pdc and Qac are shown here in (7.68),

Pdc =− 3

4

ωLL|v+1sαβ|

R2 + (ωLL)2Vdcma sin δ (7.68a)

Qac =3

2

ωLL|v+1sαβ |

R2 + (ωLL)2

(

|v+1sαβ| −

Vdcma

2cos δ

)

(7.68b)

Substituting, Pdc = IdcVdc, into (7.68) and re-arranging for δ and ma, yields,

δ = tan−1

VdcIdc

Qac −3

2

ωLL|v+1sαβ|2

R2 + (ωLL)2

(7.69a)

ma =− 4

2

R2 + (ωLL)2

ωLL

Idc

|v+1sαβ| sin δ

(7.69b)

These expressions are used for the initialization of the control parameters, ma and δ of

the VSC harmonic models.

A.4.2 Line Commutated Converter Models

In initializing the control parameters, the following assumptions are made: Negligible harmonic distortion on PCC Ldc is infinite

Using these assumptions, for both the diode and thyristor converter models, µ for each

gating pulse is equivalent and γ for each gating pulse is equivalent.

A.4.2.1 Thyristor-Switched Models

The approach to iterating for an initial guess of α and µ for the thyristor-switched

converters is outlined in Fig. 7.8. The steps outlined in the Figure are described here in

greater detail using the 6-pulse thyristor-switched converter as a reference. The analysis

for estimating µ and α for the 12-pulse thyristor-switched converter follows similarly and

therefore is not discussed here.

Page 128: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 122

Initialize α = 0.1

Calculate µ

Calculate Pdc

Update α

Is | |

< 10-5?

Output

µ and α

Calculate Jacobian

addPdcref

dcdc PP -

Figure 7.8: Initializing Control Parameters α and µ

Calculating µ

The commutation interval length µ is set by the value of α and α is initialized to 0.1 rad.

To calculate µ for the 6-pulse converter, the average voltage at the output of the converter

is solved for. Given that the average voltage is specified as an input reference setting to

the model, the resulting expression can be re-arranged to give an expression for the value

of µ. The average voltage can be calculated by analyzing the average voltage across the

dc-side of the converter for the interval between when the gating switch 1 and switch 2

as shown in (7.70). The analysis assumes that the voltage drop across the ac-side line

impedance is negligible.

Vdc =

∫ µ+α

α

(

V sb − V sc

)

dθ +

∫ α+π/3

µ+α

(

V sa − V sc

)

dθ (7.70)

Where, V sa = |v+1sαβ| cos θ; V sb = |v+1

sαβ| cos (θ − 2π/3); and V sc = |v+1sαβ| cos (θ + 2π/3).

Solving (7.70) and re-arranging for µ, results in (7.71),

µ = cos−1

(

3√3

Vdc

|v+1sαβ|

− cosα

)

− α (7.71)

Page 129: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 123

Calculating Pdc

An analytical expression for the average real power Pdc is shown in (7.72),

Pdc = VdcIdc (7.72)

Since Vdc is specified as an input, to solve for Pdc, Idc, the average dc-side current, must

be calculated. By analyzing the change in phase b current, during the commutation

interval following the gating of switch 1, as it decreases from −idc to 0, an expression for

Idc can be obtained. This is shown in (7.73),

Idc =1

2L

∫ µ+α

α

(

V sb − V sc

)

dθ (7.73)

Where, V sb = |v+1sαβ| cos (θ − 2π/3) and V sc = |v+1

sαβ| cos (θ + 2π/3). If (7.73) is solved

and substituted into (7.72), the following expression results for P ,

Pdc = Vdc

|v+1sαβ|2L

[

sin

(

θ − 2π

3

)

− sin

(

θ +2π

3

)]µ+α

α

(7.74)

Simplifying (7.74) results in (7.75) which can be used to evaluate the constraint equation

∆Pdc = 0,

Pdc = Vdc

√3

2L|v+1

sαβ| (cosα− cosµ+ α) (7.75)

Updating α

If the constraint requirement of tolerance ǫ = 10−4 is not met, α is updated for the next

iteration of the loop using a Newton-Raphson based approach,

αi+1 = αi +dPdc

−1

∆Pdc (7.76)

The µ and α resulting from this iteration process are used in the first iteration of the

thyristor-switched 6-pulse converter.

A.4.2.2 Diode-Switched Models

In the diode-switched converter models there are four control parameters to initialize:

γ, µ, t1 and Rdc. The γ and t1 parameters are directly calculated whereas an iterative

Page 130: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 124

approach is required to solve for Rdc and µ.

Initializing t1

As discussed in Section 4.5.5, ~u is rotated in time by t = t1, so that the converter states

contained in the input vector are specified at the instant that switch 1 is gated. Due

to the presence of harmonics, the time instant that switch 1 becomes forward biased is

unknown and therefore must be solved for. Given the initialization assumptions, t1 can

be directly calculated using (7.77),

t1 =2π − ∠v+1

sαβ(0)

ω(7.77)

Where, ∠v+1sαβ(0) = tan−1

(

V +1sβ

V +1sα

)

; and V +1sα and V +1

sβ are elements of input vector ~u(0).

Initializing γ

Given the periodicity of steady-state signals,

p∑

i=1

γi = 2π (7.78)

Where, p is the number of pulses. The initialization assumptions imply pulse symmetry,

i.e.

∀i, k γi = γk, where 1 <= i, k <= p (7.79)

As such, (7.79) can be re-written in terms of γ. The resulting expression is re-arranged

for γ as shown here in (7.80),

γ =2π

p(7.80)

By setting appropriate values for p, the initialization value for the 6-pulse and 12-pulse

converter can be solved (γ = π/3 for the 6-pulse topology and γ = π/6 for the 12-pulse

topology).

Page 131: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 125

Initializing µ and Rdc

The analysis for estimating µ and Rdc for the 6-pulse diode converter is discussed here;

the 12-pulse diode-switched converter follows similarly and therefore is not discussed

here.

Initialize µ = 0.1

Calculate Pdc

Update µ

Is | |

< 10-5?

Output

µ, Rdc

Calculate Jacobian

mddPdc

Calculate Rdc

ref

dcdc PP -

Figure 7.9: Initializing Control Parameters α and µ

Calculating Rdc

Rdc can be calculated via (7.81),

Rdc =V 2dc

Pdc(7.81)

To solve for Rdc using (7.81), Vdc must be calculated. Vdc can be calculated by calculating

the average dc-side voltage between the gating of switch 1 and switch 2, as shown in

(7.82),

Vdc =

∫ µ

0

(

V sb − V sc

)

dθ +

∫ π/3

µ

(

V sa − V sc

)

dθ (7.82)

Where, V sa = |v+1sαβ| cos θ; V sb = |v+1

sαβ| cos (θ − 2π/3); and V sc = |v+1sαβ| cos (θ + 2π/3).

Solving (7.82) results in (7.83),

Vdc =3√3

2π|v+1

sαβ| (cosµ+ 1) (7.83)

Page 132: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix A. Harmonic Model Derivations 126

Calculating Pdc

Pdc can be calculated through via (7.84),

Pdc = VdcIdc (7.84)

Given that Vdc was calculated in (7.83), Idc must be calculated in order to solve (7.84). By

analyzing the change in phase b current, during the commutation interval following the

gating of switch 1, as it decreases from −idc to 0, an expression for Idc can be obtained.

This expression is shown here in (7.85),

Idc =1

2L

∫ µ

0

(

V sb − V sc

)

dθ (7.85)

Where, V sb = |v+1sαβ| cos (θ − 2π/3) and V sc = |v+1

sαβ| cos (θ + 2π/3). Solving (7.85) results

in (7.86),

Idc =1

2L

(

−√3 cosµ+

√3)

(7.86)

This expression for Idc can be combined with Vdc in (7.84) to solve for Pdc.

Updating µ

If the constraint requirement of tolerance ǫ = 10−4 is not met, µ is updated for the next

iteration using a Newton-Raphson based approach,

µi+1 = µi +dPdc

−1

∆Pdc (7.87)

The µ and Rdc resulting from this iteration process are used in the first iteration of the

diode-switched 6-pulse converter.

Page 133: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B

Matlab Source Code

B.1 Source Code for OpenHarmonics

OpenHarmonics.m

1 %Author: Philippe A. Gray

2 %Date: May 5, 2013

3

4 %INPUTS OpenHarmonics User Interface.

5 %This file is where the user interfaces with OpenHarmonics. The

6 %simulation parameters, converter and monitor objects are specified in

7 %this file. Once, all inputs have been added, the user must hi t Run (F5)

8 %and OpenHarmonics will simulate the network. The outputs o f the ...

simulation

9 %will appear in the Workspace block on the top right side of th e ...

MATLAB GUI.

10 global numHarmonics DSSText OpenDSSFile DSSCircuit

11

12 %numHarmonics − changes the number of harmonic orders that you would ...

like to analyze.

13 %For example: numHarmonics = 27, would generate the harmoni c ...

spectrum up to and

14 %including, the 27th harmonic.

15 numHarmonics = 31;

16

17 %This line references the full path of the OpenDSS circuit fi le

18 %containing the network to be simulated. Make sure that the O penDSS ...

file is

19 %located in the \OpenDSSFiles subfolder.

127

Page 134: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 128

20 OpenDSSFile = 'IEEE13Nodeckt' ;

21 OpenDSSFileLoc = ...

22 'C: \Users \Phil \Dropbox \Masters \Matlab \OpenHarmonics \OpenDSSFiles \' ;

23 OpenDSSFile = [OpenDSSFileLoc,OpenDSSFile];

24

25 %Initializes the communication interface (COM) between MA TLAB and ...

OpenDSS

26 [DSSObj DSSText DSSCircuit DSSSolution DSSMonitors busBa sekVs] = ...

startOpenDSS(OpenDSSFile); %don`t change

27

28 %Creates the pwrconverters object for the simulated networ k

29 sys = pwrconverters();

30

31 %USER INPUT− Add Converter ...

ObDjects...Here *********************************32 %format = ...

add(sys,'type','name','bus','Srated','Vdc','P','Q', 'Lpu','mf','Cbank')

33 %Refer to the user manual further explanation of the input fo rmat

34 %vsc,diode6,diode12,thyristor6,thyristor12

35

36 %for the thesis test case

37 sys = add(sys, 'vsc' , 'vsc 634' , '634' ,100,1000, −90,10,0.2,15 * 60, '' );

38 sys = add(sys, 'diode6' , 'diode 634' , '634' ,80, '' ,70, '' ,0.2, '' , '' );

39 sys = add(sys, 'thyristor6' , 'thyristor6 634' , '634' ,100,480/sqrt(3) * ...

40 sqrt(2) * 1.3,90, '' ,0.2, '' , '' );

41 sys = ...

add(sys, 'thyristor12' , 'thyristor12 675' , '675' ,110,10000,100, '' ,0.2, '' , '' );

42 sys = add(sys, 'diode12' , 'diode12 675' , '675' ,100, '' ,75, '' ,0.2, '' , '' ); %

43

44 %USER INPUT− List the bus names that you would like the voltage ...

harmonic

45 %spectrums for into VSolve.

46 DSSText.Command = 'CalcVoltageBases' ;

47 VSolve = ;

48

49 %Calls and excecutes the OpenHarmonics solution engine.

50 ActualHarmonics(DSSText,DSSCircuit,DSSSolution,DSSM onitors,sys, ...

51 ISolve,VSolve);

52

53 %This loads the results of the simulation into the MATLAB Wor kspace

54 load([OpenDSSFileLoc, 'outputs.mat' ]);

55 type([OpenDSSFileLoc, 'errorFile.txt' ]);

Page 135: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 129

startOpenDSS.m

1 %INPUTS startOpenDSS Sets up interface between OpenHarmon ics and ...

OpenDSS.

2 %This function initiates the communication between OpenHa rmonics and

3 %OpenDSS. Calling this function returns a number of objects that ...

directly

4 %reference certain properties of the OpenDSS circuit file. By calling

5 %functions on these objects we can simulate the circuit, cha nge circuit

6 %properties, add components to the circuit, change simulat ion ...

parameters.

7

8 function [DSSObj DSSText DSSCircuit DSSSolution DSSMonitors ...

busBasekVs OpenDSSFile] = startOpenDSS(OpenDSSFile)

9

10 DSSObj = actxserver( 'OpenDSSEngine.DSS' );

11

12 %Start = DSSObj.Start(0);

13 %DSSText is a pointer to the DSSObj.Text object. DSSObj.Tex t is used ...

when

14 %you want to write new lines to the OpenDSS file.

15 DSSText = DSSObj.Text;

16

17 %DSSCircuit points to the DSSObj.ActiveCircuit object. Th rough this ...

object

18 %you can access certain data from circuit objects of interes t.

19 DSSCircuit=DSSObj.ActiveCircuit;

20

21 %By invoking the .solve function on DSSSolution you can simu late the

22 %circuit for the current set of simulation parameters.

23 DSSSolution=DSSCircuit.Solution;

24

25 %DSSMonitors points to an array of MonitorObjects. We stric kly use

26 %DSSMonitors to grab all the names of the Monitor Objects in t he ...

network so

27 %that we can locate the associated .csv files that contain th e relevant

28 %harmonic data.

29 DSSMonitors = DSSCircuit.Monitors;

30

31 %This command is necessary first step before any simulation s of the ...

system

32 %are performed

Page 136: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 130

33 DSSText.Command = [ 'compile ' , OpenDSSFile, '.dss' ];

34 DSSText.Command = 'edit spectrum.default numharm = 1' ;

35 DSSText.Command = 'edit spectrum.defaultload numharm = 1' ;

36 busBasekVs = zeros(DSSCircuit.NumBuses,1);

37

38 %BusNames contains the names of all buses in the system. A bus is ...

not on a

39 %per phase basis. The bus definition from OpenDSS is the defi nition ...

used in

40 %OpenHarmonics in defining a bus. That is a bus is defined as a ...

collection

41 %of nodes connected − and this connection line or point is the bus.

42 BusNames = DSSCircuit.AllBusNames;

43

44 %This loop goes through each bus in the circuit and stores the base ...

voltage

45 %in units of kV (l −l, rms) into the array busBasekVs. This base ...

voltage is

46 %used later to per −unit −ize the bus voltages.

47 for i = 1:DSSCircuit.NumBuses

48 DSSCircuit.SetActiveBus(char(BusNames(i)));

49 DSSBus = DSSCircuit.ActiveBus;

50 busBasekVs(i) = DSSBus.kVBase;

51 end

converter.m

1 %converter converter model class

2 classdef converter < handle

3 properties

4 name, type, bus, h

5 Cdc, Idc, Q, Ldc, P, L, R %units: F, A, kvar, H, kW, H, Ohm

6

7 %Vbase is in l −l,rms; Sbase is in 3 Phase.

8 Vbase ac, Sbase, Zbase ac, Rdc, Vdc, Ibase ac %V, kVA, kVA, ...

Ohm, Ohm, V, A

9 mf, ma, sigma, mu, alpha, phaseAng, gamma, Cbank

10 L pu, R pu, Rdc pu, Vdc pu, Cdc pu, Idc pu, Q pu, Ldc pu, ...

P pu, err

11 Cbank pu,Zbase dc, Vbase dc, Ibase dc

12 end

Page 137: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 131

13 methods

14 %Constructor − Whenever a new converter object is added to the

15 %system this function block is called.

16 %This block takes in the inputs and corresondingly changes . ..

all the

17 %properties that are relevant to that particular converter type.

18 function c obj = ...

converter(type,name,bus,Srated,Vdc,P,Q,Lpu,mf,Cbank pu)

19 global numHarmonics DSSText DSSCircuit

20 c obj.err = 0;

21 c obj.Sbase = Srated;

22 c obj.type = type;

23 c obj.name = name;

24 c obj.bus = bus;

25 c obj.h = numHarmonics;

26 c obj.P = P;

27 if ¬isempty(Cbank pu)

28 c obj.Cbank pu = Cbank pu;

29 end

30 DSSCircuit.SetActiveBus(c obj.bus);

31 DSSBus = DSSCircuit.ActiveBus;

32 c obj.Vbase ac = DSSBus.KVBase * 1000 * sqrt(2);

33 c obj.Ibase ac = 2/3 * (c obj.Sbase * 1000)/c obj.Vbase ac;

34 c obj.Vbase dc = c obj.Vbase ac;

35 c obj.Ibase dc = c obj.Sbase * 1000/c obj.Vbase dc;

36 c obj.Zbase ac = c obj.Vbase ac/c obj.Ibase ac;

37 c obj.Zbase dc = c obj.Vbase dc/c obj.Ibase dc;

38 wp = 1;

39 Cbase ac = wp/(2 * pi * 60)/c obj.Zbase dc;

40 Lbase ac = wp/(2 * pi * 60) * c obj.Zbase dc;

41 Cbase dc = wp/(2 * pi * 60)/c obj.Zbase dc;

42 Lbase dc = wp/(2 * pi * 60) * c obj.Zbase dc;

43

44 if strcmp(type, 'vsc' ) %if one will explore this branch

45 c obj.Vdc = Vdc;

46 c obj.Rdc = 10ˆ8 * c obj.Zbase dc; %Rdc set so that ...

the p.u. is 10ˆ8

47 c obj.Q = Q;

48 c obj.Cdc = 10 * abs(6 * Srated/Vdcˆ2); %Set so that the ...

dc−link cap will have at least 2 J of energy ...

storage per kW rated. This is a general rule of ...

thumb that limits the ripple on the dc −link to ...

within a few percent.

Page 138: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 132

49 c obj.mf = round(mf/60); %the switching frequency of ...

the converter

50 c obj.Idc = P * 1000/Vdc; %calculated based on the ...

specified power and average dc −link voltage

51 else

52 c obj.Ldc pu = 0.5;

53 c obj.Ldc = c obj.Ldc pu* Lbase dc;

54 c obj.mu = −1;

55 c obj.Vdc = Vdc;

56 if strcmp(type, 'thyristor6' ) | | ...

strcmp(type, 'thyristor12' )

57 c obj.Rdc = Vdcˆ2/(P * 1000);

58 else

59 c obj.Vdc = 0;

60 if strcmp(type, 'diode6' )

61 c obj.Rdc = ...

1.654ˆ2/(P/c obj.Sbase) * c obj.Zbase dc;

62 else

63 c obj.Rdc = ...

3.3080ˆ2/(P/c obj.Sbase) * c obj.Zbase dc;

64 end

65 end

66 end

67

68 c obj.R pu = 0.02;

69 c obj.L pu = Lpu;

70 c obj.R = c obj.R pu* c obj.Zbase dc;

71 c obj.L = c obj.L pu* Lbase dc;

72 if ¬isempty(Cbank pu)

73 c obj.Cbank = c obj.Cbank pu* Cbase dc;

74 end

75

76 c obj.Rdc pu = c obj.Rdc/c obj.Zbase dc;

77 c obj.P pu = c obj.P/c obj.Sbase;

78 c obj.Vdc pu = c obj.Vdc/c obj.Vbase dc;

79

80 if strcmp(type, 'vsc' )

81 c obj.Cdc pu = c obj.Cdc/Cbase dc;

82 c obj.Idc pu = c obj.Idc/c obj.Ibase dc;

83 c obj.Q pu = c obj.Q/c obj.Sbase;

84 c obj.Vdc pu = c obj.Vdc/c obj.Vbase dc;

85 end

86

Page 139: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 133

87 %Add Delta −Connected Three −Phase Capacitor Bank to Bus

88 if ¬isempty(Cbank pu)

89 DSSText.Command = [ 'new Capacitor.' ,c obj.name, 'ab ...

Bus1=' ,c obj.bus, '.1 Bus2=' ,c obj.bus, '.2 ...

Phases=1 cuf=' ,num2str(c obj.Cbank * 10ˆ6)];

90 DSSText.Command = [ 'new Capacitor.' ,c obj.name, 'bc ...

Bus1=' ,c obj.bus, '.2 Bus2=' ,c obj.bus, '.3 ...

Phases=1 cuf=' ,num2str(c obj.Cbank * 10ˆ6)];

91 DSSText.Command = [ 'new Capacitor.' ,c obj.name, 'ca ...

Bus1=' ,c obj.bus, '.3 Bus2=' ,c obj.bus, '.1 ...

Phases=1 cuf=' ,num2str(c obj.Cbank * 10ˆ6)];

92 end

93

94 %Defining new spectrum objects

95 initSpectrum = zeros(numHarmonics,3);

96 for i = 1:numHarmonics

97 initSpectrum(i,1) = i;

98 end

99

100 csvwrite([c obj.name, 'a spectrum.csv' ],initSpectrum);

101 csvwrite([c obj.name, 'b spectrum.csv' ],initSpectrum);

102 csvwrite([c obj.name, 'c spectrum.csv' ],initSpectrum);

103 DSSText.Command = [ 'new Spectrum.' ,c obj.name, 'a ...

numharm=' , ...

104 num2str(numHarmonics), ' ...

csvfile=' ,c obj.name, 'a spectrum.csv' ];

105 DSSText.Command = [ 'new Spectrum.' ,c obj.name, 'b ...

numharm=' , ...

106 num2str(numHarmonics), ' ...

csvfile=' ,c obj.name, 'b spectrum.csv' ];

107 DSSText.Command = [ 'new Spectrum.' ,c obj.name, 'c ...

numharm=' , ...

108 num2str(numHarmonics), ' ...

csvfile=' ,c obj.name, 'c spectrum.csv' ];

109 DSSText.Command = [ 'new Isource.' ,c obj.name, 'a ...

Bus1=' ,c obj.bus, '.1 basefreq = 60 Phases=1 amps=0 ...

spectrum=' ,c obj.name, 'a' ];

110 DSSText.Command = [ 'new Isource.' ,c obj.name, 'b ...

Bus1=' ,c obj.bus, '.2 basefreq = 60 Phases=1 amps=0 ...

spectrum=' ,c obj.name, 'b' ];

111 DSSText.Command = [ 'new Isource.' ,c obj.name, 'c ...

Bus1=' ,c obj.bus, '.3 basefreq = 60 Phases=1 amps=0 ...

spectrum=' ,c obj.name, 'c' ];

Page 140: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 134

112 DSSText.Command = [ 'new monitor.' ,c obj.name, ...

113 'a Isource.' ,c obj.name, 'a' ];

114 DSSText.Command = [ 'new monitor.' ,c obj.name, ...

115 'b Isource.' ,c obj.name, 'b' ];

116 DSSText.Command = [ 'new monitor.' ,c obj.name, ...

117 'c Isource.' ,c obj.name, 'c' ];

118 end

119 %this function reads in the csv files containing the PCC volt age

120 %harmonic spectra of the converter as input. It then solves t he

121 %converter model for the injection current harmonic spectr a. ...

This

122 %harmonic spectra is used to update the spectrum and isource

123 %objects of the openDSS file.

124 function c obj = updateValue(c obj,varName,value)

125 c obj.(varName) = value;

126 end

127 function solveConverter(c obj) %the only output we need is ...

the current spectrum

128 global OpenDSSFile invSymMtx DSSText numHarmonics

129

130 if c obj.err == 0

131 lenHarm = 2 * c obj.h+1;

132

133 %this reads in the abc phase voltages at the PCC ...

from the csv

134 %files from the most recent simulation.

135 Va = ...

csvread([OpenDSSFile, ' Mon ' ,c obj.name, 'a.csv' ],1,2, ...

136 [1,2,c obj.h,3]);

137 Vb = ...

csvread([OpenDSSFile, ' Mon ' ,c obj.name, 'b.csv' ],1,2, ...

138 [1,2,c obj.h,3]);

139 Vc = ...

csvread([OpenDSSFile, ' Mon ' ,c obj.name, 'c.csv' ],1,2, ...

140 [1,2,c obj.h,3]);

141 %this loop transforms the abc voltages into the ...

positive and

142 %negative sequence refererence frame. Then the real and

143 %imaginary components of the positive and negative ...

sequence

144 %frame values are extracted and added to the voltage ...

vector

145 %V.

Page 141: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 135

146 V = zeros(lenHarm * 2,1);

147 count = 0;

148 for i = 1:c obj.h

149 Vav = Va(i,1) * exp(1i * Va(i,2) * pi/180);

150 Vbv = Vb(i,1) * exp(1i * Vb(i,2) * pi/180);

151 Vcv = Vc(i,1) * exp(1i * Vc(i,2) * pi/180);

152 pnArr = invSymMtx * [Vav;Vbv;Vcv];

153 V(2 * c obj.h+3+count:2 * c obj.h+4+count) = ...

[real(pnArr(2));imag(pnArr(2))];

154 V(2 * c obj.h −1−count:2 * c obj.h −count) = ...

[real(pnArr(3));imag(pnArr(3))];

155 count = count + 2;

156 end

157 %the converter solver takes p.u. values as the input ...

so this

158 %operation pu −tizes the PCC voltages.

159 V = V/(c obj.Vbase ac/sqrt(2));

160

161 outputFile = [c obj.name, 'V.mat' ];

162 save(outputFile, 'V' );

163

164 %In this "if" block, the object type is used to ...

determine which

165 %converter solver function to run. Each converter ...

type operates

166 %uniquely and thus a separate solving function is ...

called for

167 %each of the 5 different converter types. The output ...

of each of

168 %the solver functions is the injection current ...

harmonic spectra

169 %for the converter given the inputs and the PCC ...

voltages.

170 if strcmp(c obj.type, 'vsc' )

171 [Ia Ib Ic fundCurrents c obj.ma c obj.sigma ...

Rdc new c obj.err] = solveVSC(V, ...

172 c obj.L pu,c obj.R pu,c obj.mf,c obj.Rdc pu,c obj.Cdc pu, ...

173 c obj.Idc pu,c obj.h,c obj.Vdc pu,c obj.Q pu);

174 elseif strcmp(c obj.type, 'thyristor6' )

175 [Ia Ib Ic fundCurrents c obj.alpha c obj.mu] = ...

solveThyristor6(V,c obj.L pu, ...

176 c obj.R pu,c obj.Rdc pu,c obj.Ldc pu, ...

177 c obj.h,c obj.Vdc pu,c obj.P pu);

Page 142: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 136

178 elseif strcmp(c obj.type, 'diode6' )

179 [Ia Ib Ic fundCurrents c obj.phaseAng ...

c obj.gamma c obj.mu c obj.P pu Rdc new ...

c obj.L pu c obj.Vdc pu] = solveDiode6(V, ...

180 c obj.L pu,c obj.R pu,c obj.Rdc pu,c obj.Ldc pu, ...

181 c obj.h,c obj.Vdc pu,c obj.P pu,c obj.mu,c obj.gamma,c obj.ph

182 elseif strcmp(c obj.type, 'thyristor12' )

183 [Ia Ib Ic fundCurrents c obj.alpha c obj.mu] = ...

solveThyristor12(V,c obj.L pu, ...

184 c obj.R pu,c obj.Rdc pu,c obj.Ldc pu, ...

185 c obj.h,c obj.Vdc pu,c obj.P pu);

186 elseif strcmp(c obj.type, 'diode12' )

187 [Ia Ib Ic fundCurrents c obj.phaseAng ...

c obj.gamma c obj.mu c obj.P pu Rdc new ...

c obj.L pu c obj.Vdc pu] = solveDiode12(V, ...

188 c obj.L pu,c obj.R pu,c obj.Rdc pu,c obj.Ldc pu, ...

189 c obj.h,c obj.Vdc pu,c obj.P pu,c obj.mu,c obj.gamma,c obj.ph

190 end

191

192 if ¬strcmp(c obj.type, 'thyristor12' ) && ¬...

strcmp(c obj.type, 'thyristor6' )

193 c obj.Rdc pu = Rdc new;

194 c obj.Rdc = Rdc new* c obj.Zbase dc;

195 end

196 if strcmp(c obj.type, 'diode12' ) | | ...

strcmp(c obj.type, 'diode6' )

197 c obj.Vdc = c obj.Vbase dc * c obj.Vdc pu;

198 end

199

200 csvwrite([c obj.name, 'a spectrum.csv' ],Ia);

201 csvwrite([c obj.name, 'b spectrum.csv' ],Ib);

202 csvwrite([c obj.name, 'c spectrum.csv' ],Ic);

203

204 %Spectrums are being asked to read in the values of ...

the updated

205 %csv files

206 DSSText.Command = [ 'edit Spectrum.' ,c obj.name, 'a ...

numharm=' , ...

207 num2str(numHarmonics), ' ...

csvfile=' ,c obj.name, 'a spectrum.csv' ];

208 DSSText.Command = [ 'edit Spectrum.' ,c obj.name, 'b ...

numharm=' , ...

Page 143: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 137

209 num2str(numHarmonics), ' ...

csvfile=' ,c obj.name, 'b spectrum.csv' ];

210 DSSText.Command = [ 'edit Spectrum.' ,c obj.name, 'c ...

numharm=' , ...

211 num2str(numHarmonics), ' ...

csvfile=' ,c obj.name, 'c spectrum.csv' ];

212

213 fundCurrents(1:end,1) = ...

fundCurrents(1:end,1) * (c obj.Ibase dc);

214

215 ampVal = num2str(fundCurrents(1,1));

216 angleVal = num2str(fundCurrents(1,2));

217 DSSText.Command = [ 'Edit Isource.' ,c obj.name, 'a ...

enabled=true amps = ' ,ampVal, ' angle = ...

' ,angleVal, ' spectrum=' ,c obj.name, 'a' ];

218 ampVal = num2str(fundCurrents(2,1));

219 angleVal = num2str(fundCurrents(2,2));

220 DSSText.Command = [ 'Edit Isource.' ,c obj.name, 'b ...

enabled=true amps = ' ,ampVal, ' angle = ...

' ,angleVal, ' spectrum=' ,c obj.name, 'b' ];

221 ampVal = num2str(fundCurrents(3,1));

222 angleVal = num2str(fundCurrents(3,2));

223 DSSText.Command = [ 'Edit Isource.' ,c obj.name, 'c ...

enabled=true amps = ' ,ampVal, ' angle = ...

' ,angleVal, ' spectrum=' ,c obj.name, 'c' ];

224 end

225 end

226 end

227 end

pwrconverters.m

1 %PWRCONVERTERS class type

2 %Only one object of "pwrconverters" type is created per simu lation ...

study.

3 %This "pwrconverters" object contains each

4 %converter object modelled for the tested distribution net work.

5 %"pwrconverters" has two properties: converterArr and num Converters

6 %converterArr: is an array of "converter" type objects. Eac h element in

7 %this array contains a converter object that the user has cho sen to be

Page 144: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 138

8 %included in the simulated network. The converter object mu st be ...

specified

9 %in the inputs.m file − not in the OpenDSS circuit file.

10 %numConverters: is an integer variable containing the numb er of ...

converter

11 %objects modelled in the system.

12 classdef pwrconverters

13 properties

14 converterArr %−−− array of type "converter"

15 numConverters %−−− integer variable%

16 end

17 methods

18 function conv objs = pwrconverters()

19 conv objs.numConverters = 0;

20 conv objs.converterArr = converter.empty(100,0);

21 end

22 function conv objs = ...

add(conv objs,type,name,bus,Srated,Vdc,P,Q,Lpu,mf,Cbank)

23 global OpenDSSFile numHarmonics

24 conv objs.numConverters = conv objs.numConverters + 1;

25 conv objs.converterArr(conv objs.numConverters) = ...

26 converter(type,name,bus,Srated,Vdc,P,Q,Lpu,mf,Cbank ); ...

end

27 %function − cycles through each of the converters in the

28 %converterArr array. The harmonic current spectra for each

29 %of the converters is solved given the solution of the PCC ...

voltage

30 %fund + harmonics in the preceding iteration. The solved ...

injection

31 %currents are then used to update spectrum and isource objec ts

32 %corresponding to each of the solved converters.

33 function solveConverters(conv objs)

34 for i = 1:conv objs.numConverters

35 solveConverter(conv objs.converterArr(i));

36 end

37 end

38 function conv objs = changeValue(conv objs,name,varName,value)

39 for i = 1:conv objs.numConverters

40 if (strcmp(conv objs.converterArr(i).name,name))

41 conv objs.converterArr(i) = ...

updateValue(conv objs.converterArr(i),varName,value);

42 break ;

43 end

Page 145: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 139

44 end

45 end

46 end

47 end

ActualHarmonics.m

1 %PWRCONVERTERS class type

2 %Only one object of "pwrconverters" type is created per simu lation ...

study.

3 %This "pwrconverters" object contains each

4 %converter object modelled for the tested distribution net work.

5 %"pwrconverters" has two properties: converterArr and num Converters

6 %converterArr: is an array of "converter" type objects. Eac h element in

7 %this array contains a converter object that the user has cho sen to be

8 %included in the simulated network. The converter object mu st be ...

specified

9 %in the inputs.m file − not in the OpenDSS circuit file.

10 %numConverters: is an integer variable containing the numb er of ...

converter

11 %objects modelled in the system.

12 classdef pwrconverters

13 properties

14 converterArr %−−− array of type "converter"

15 numConverters %−−− integer variable%

16 end

17 methods

18 function conv objs = pwrconverters()

19 conv objs.numConverters = 0;

20 conv objs.converterArr = converter.empty(100,0);

21 end

22 function conv objs = ...

add(conv objs,type,name,bus,Srated,Vdc,P,Q,Lpu,mf,Cbank)

23 global OpenDSSFile numHarmonics

24 conv objs.numConverters = conv objs.numConverters + 1;

25 conv objs.converterArr(conv objs.numConverters) = ...

Page 146: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 140

26 converter(type,name,bus,Srated,Vdc,P,Q,Lpu,mf,Cbank ); ...

end

27 %function − cycles through each of the converters in the

28 %converterArr array. The harmonic current spectra for each

29 %of the converters is solved given the solution of the PCC ...

voltage

30 %fund + harmonics in the preceding iteration. The solved ...

injection

31 %currents are then used to update spectrum and isource objec ts

32 %corresponding to each of the solved converters.

33 function solveConverters(conv objs)

34 for i = 1:conv objs.numConverters

35 solveConverter(conv objs.converterArr(i));

36 end

37 end

38 function conv objs = changeValue(conv objs,name,varName,value)

39 for i = 1:conv objs.numConverters

40 if (strcmp(conv objs.converterArr(i).name,name))

41 conv objs.converterArr(i) = ...

updateValue(conv objs.converterArr(i),varName,value);

42 break ;

43 end

44 end

45 end

46 end

47 end

exportMonitors.m

1 function exportMonitors(MonitorList)

2 global DSSText;

3

4 for i = 1:length(MonitorList)

5 DSSText.Command = [ 'export mon ' ,char(MonitorList(i))];

6 end

Page 147: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 141

checkIfCriteriaMet.m

1 function [pass Vcurr] = checkIfCriteriaMet(MonitorList,Vprev,to l)

2 global numHarmonics OpenDSSFile

3

4 lenHarm = 2 * numHarmonics+1;

5 exportMonitors(MonitorList);

6 Vcurr = zeros(lenHarm,length(MonitorList)/3);

7 pass = 1;

8

9 for i = 1:3:length(MonitorList)

10

11 Va = ...

csvread([OpenDSSFile, ' Mon ' ,char(MonitorList(i)), '.csv' ],1,2, ...

12 [1,2,numHarmonics,3]);

13 Vb = ...

csvread([OpenDSSFile, ' Mon ' ,char(MonitorList(i+1)), '.csv' ],1,2, ...

14 [1,2,numHarmonics,3]);

15 Vc = ...

csvread([OpenDSSFile, ' Mon ' ,char(MonitorList(i+2)), '.csv' ],1,2, ...

16 [1,2,numHarmonics,3]);

17

18 %Function combines the phase abc harmonic specta vectors in to ...

the space

19 %vector format from −ve to +ve sequence harmonic h

20 Vcurr(1:end,(i −1)/3+1) = getSVMag(Va,Vb,Vc,numHarmonics);

21 end

22

23 compareMtx = Vcurr −Vprev;

24 for i = 1:2 * numHarmonics+1

25 for j = 1:length(MonitorList)/3

26 if Vcurr(i,j) ≥ 1

27 if abs(compareMtx(i,j)/Vprev(i,j)) * 100 > tol

28 pass = 0;

29 break ;

30 end

31 end

32 end

Page 148: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 142

33 if pass == 0

34 break ;

35 end

36 end

getIabcFundCurrents.m

1 function [Ia Ib Ic fundCurrents] = getI abc fundCurrents(I,h)

2 global SymMtx

3

4 Ia = zeros(h,3);

5 Ib = zeros(h,3);

6 Ic = zeros(h,3);

7 fundCurrents = zeros(3,2);

8

9 count = 1;

10

11 for i = 1:h

12

13 outputCurrent = SymMtx * [0;I(2 * h+2+count)+1i * I(2 * h+2+count+1); ...

14 I(2 * h−count)+1i * I(2 * h−count+1)];

15

16 if i == 1

17 outa ref = abs(outputCurrent(1));

18 outb ref = abs(outputCurrent(2));

19 outc ref = abs(outputCurrent(3));

20 Ia(1,1:end) = [1,100.0,angle(outputCurrent(1)) * 180/pi+180];

21 Ib(1,1:end) = [1,100.0,angle(outputCurrent(2)) * 180/pi+180];

22 Ic(1,1:end) = [1,100.0,angle(outputCurrent(3)) * 180/pi+180];

23 for j = 1:3

24 fundCurrents(j,1) = abs(outputCurrent(j));

25 fundCurrents(j,2) = angle(outputCurrent(j)) * 180/pi+180;

26 end

27 else

28 Ia(i,1:end) = [i,abs(outputCurrent(1))/outa ref * 100, ...

angle(outputCurrent(1)) * 180/pi+180 * i];

Page 149: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 143

29 Ib(i,1:end) = [i,abs(outputCurrent(2))/outb ref * 100, ...

angle(outputCurrent(2)) * 180/pi+180 * i];

30 Ic(i,1:end) = [i,abs(outputCurrent(3))/outc ref * 100, ...

angle(outputCurrent(3)) * 180/pi+180 * i];

31 end

32

33 count = count + 2;

34 end

B.2 Source Code for Harmonic Models

B.2.1 VSC

solveVSC.m

1 function [Ia Ib Ic fundCurrents ma sigma Rdc error] = ...

solveVSC(Valphabeta, ...

2 L,R,mf,Rdc in,Cdc,Idc in,h,Vdc in,Q)

3

4 global OpenDSSFileLoc

5

6 error = 0;

7 Vdc = Vdc in;

8 Rdc = Rdc in;

9 Idc = Idc in;

10

11 errorFile = fopen([OpenDSSFileLoc, 'errorFile.txt' ], 'w' );

12 if Idc > 3 %restricting to 2 pu

13 c = clock;

14 Idc = 3;

15 fprintf(errorFile, '%2.0fh:%2.0fm:%2.0fs P > Pmax = 3.0 pu. ...

Setting P = 3.0 pu. \n' ,c(4),c(5),c(6));

16 elseif Idc < −3 %restricting to 2 pu

17 c = clock;

18 Idc = −3;

19 fprintf(errorFile, '%2.0fh:%2.0fm:%2.0fs P < Pmin = −3.0 pu. ...

Setting P = −3.0 pu. \n' ,c(4),c(5),c(6));

Page 150: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 144

20 end

21 if Vdc ≤ 0 %restricting to 2 pu

22 c = clock;

23 Iphase = zeros(h,3);

24 for i = 1:h

25 Iphase(i,1) = i;

26 end

27 Iphase(1,2) = 100;

28 Ia = Iphase;

29 Ib = Iphase;

30 Ic = Iphase;

31 fundCurrents = [0,0;0, −120;0,+120];

32 sigma = 0;

33 ma = 0;

34 error = 0;

35 fprintf(errorFile, '%2.0fh:%2.0fm:%2.0fs The Vdc for VSC must be ...

> 0\n' ,c(4),c(5),c(6));

36 return ;

37 end

38 if Vdc ≥ 3 %restricting to 2 pu

39 c = clock;

40 Vdc = 3;

41 fprintf(errorFile, '%2.0fh:%2.0fm:%2.0fs The Vdc for VSC must be ...

< 3 pu. Setting Vdc to 3.0 pu. \n' ,c(4),c(5),c(6));

42 end

43 if Idc == 0 %restricting to 2 pu

44 Idc = 0.001;

45 end

46

47 [Ia Ib Ic fundCurrents ma sigma Rdc error] = ...

VSCmodel(Valphabeta,L,R,mf,Rdc,Cdc,Idc,h,Vdc,Q);

48

49 if error == 1

50 c = clock;

51 Iphase = zeros(h,3);

52 for i = 1:h

53 Iphase(i,1) = i;

54 end

55 Iphase(1,2) = 100;

56 Ia = Iphase;

57 Ib = Iphase;

Page 151: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 145

58 Ic = Iphase;

59 fundCurrents = [0,0;0, −120;0,+120];

60 sigma = 0;

61 ma = 0;

62 return ;

63 end

64 fclose(errorFile);

VSCmodel.m

1 %VSCmodel Returns the injection current harmonics for the c onverter ...

of type

2 %"vsc".

3 function [Ia Ib Ic fundCurrents ma sigma Rdc new error] = ...

VSCmodel(Valphabeta,L,R,mf,Rdc,C, ...

4 Idc,h,Vdcref,Qload)

5 global OpenDSSFileLoc

6 Rdc new = Rdc;

7

8 w = 1;

9 fac = w/2/pi;

10 m = 3;

11 Pload = Vdcref * Idc;

12 wac = w;

13 tolerance = 0.001; %tolerance percent set to 1%

14 loopCount = 1;

15 Tac = 1/fac;

16 error = 0;

17 errorFile = fopen([OpenDSSFileLoc, 'errorFile.txt' ], 'w' );

18 overModCount = 0;

19

20 %Setting interface reactance of each phase to the input valu es.

21 Ra = R;

22 Rb = R;

23 Rc = R;

24 La = L;

25 Lb = L;

Page 152: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 146

26 Lc = L;

27 lenHarm = 2 * h+1;

28 CTf = 2/3 * [1 −1/2 −1/2;0 sqrt(3)/2 −sqrt(3)/2;1/sqrt(2) 1/sqrt(2) ...

1/sqrt(2)];

29 invCTf = inv(CTf);

30 Lmatrix = [La 0 0;0 Lb 0;0 0 Lc];

31 Rmatrix = [Ra 0 0;0 Rb 0;0 0 Rc];

32 SymMatrix = [1 1 1;1 exp(1i * 240* pi/180) exp(1i * 120* pi/180); ...

33 1 exp(1i * 120* pi/180) exp(1i * 240* pi/180)];

34 invSymMatrix = inv(SymMatrix);

35

36 Mtx = transpose(SymMatrix) * conj(SymMatrix);

37 V = zeros(2 * lenHarm+2 * m+2,1);

38 V(2 * lenHarm+1) = −Idc; %This is Idc, −Idc = > that power is being ...

drawn from grid.

39

40 V(1:2 * lenHarm) = Valphabeta;

41 %The PWM scheme phase angle is with respect to the positive −sequence ...

fundamental

42 %frequency component of the PCC voltages. So, phaseOff stor es the phase

43 %angle of this fundamental frequecy component.

44 abs fund = abs(V(lenHarm+2)+1i * V(lenHarm+3));

45 phaseOff = angle(V(lenHarm+2)+1i * V(lenHarm+3));

46

47 K = 3/2 * abs fund/(Rˆ2+Lˆ2) * L;

48 if Pload 6= 0

49 sigma = atan(Pload/K/(Qload/K+abs fund));

50 ma = abs(2 * Pload/(K * Vdcref * sin(sigma)));

51 else

52 sigma = 0;

53 ma = 0.8;

54 end

55

56 %Ts stores each time instant that each of the phases abc inter sect ...

with the

57 %control PWM sawtooth waveform. From these switching times we can

58 %reconstruct the state of the switches of the VSC at every ins tant ...

through

59 %a whole period. From this we know the operation of the conver ter ...

through a

60 %whole steady state period and can then fully model it.

Page 153: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 147

61 % Ts(1,:) is phase a, Ts(2,:) is phase b, Ts(3,:) is phase c

62 Ts = zeros(2 * mf+1,3);

63 phaseArr = zeros(2 * mf,3);

64 RotationMatrix = zeros(2 * lenHarm+2 * m+2,2 * lenHarm+2 * m+2);

65

66 while (true)

67 mi = [ma;ma;ma];

68 Za = 0+sigma+phaseOff; %

69 Zb = 4* pi/3+sigma+phaseOff;

70 Zc = 2 * pi/3+sigma+phaseOff;

71 Zoff = [Za;Zb;Zc];

72 ang = sigma+phaseOff;

73 for k = 1:3 %this loop has three iterations −one iteration for ...

each of the abc phases

74 modphase = mi(k);

75 for i = 1:2 * mf+1 %there will be 2 * mf+1 switching times from ...

ti −> ti + 2 * \pi

76 phase = Tac * (i −1)/(2 * mf)+Zoff(k);

77 if mod(i,2) == 1

78 swtime = Tac/4/mf * (1 −ma* cos(phase));

79 else

80 swtime = Tac/4/mf * (1+ma* cos(phase));

81 end

82 Ts(i,k) = Tac/(2 * mf) * (i −1)+swtime;

83 phaseArr(i,k) = phase;

84 end

85 end

86

87 data = [Ts(:,1),phaseArr(:,1),ones(2 * mf+1,1); ...

88 Ts(:,2),phaseArr(:,2),2 * ones(2 * mf+1,1); ...

89 Ts(:,3),phaseArr(:,3),3 * ones(2 * mf+1,1)];

90 data = sortrows(data);

91

92 ti = data(1,1);

93 numSWTimes = 6* mf;

94 switchTimes = zeros(6 * mf,1);

95 for i = 1:6 * mf

96 switchTimes(i) = data(i+1,1) −data(i,1);

97 end

98

99 sw data = zeros(6 * mf,5);

Page 154: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 148

100 Sabc = zeros(3,1);

101 for j = 1:mf

102 Sabc = [0;0;0];

103 for i = 0:1

104 for k = 1:3

105 posit = 6 * (j −1)+3 * i+k;

106 Sabc(data(posit,3)) = mod(i+1,2);

107 sw data(posit,1:3) = transpose(Sabc);

108 end

109 Sabc = [1;1;1];

110 end

111 end

112 for i = 1:6 * mf

113 sw data(i,4:5) = [data(i,2),data(i+1,2)];

114 end

115

116 count = 1;

117 for i = −h:1:h

118 RotationMatrix(count:count+1,count:count+1) = ...

119 [cos(i * ti), −sin(i * ti); ...

120 sin(i * ti),cos(i * ti)];

121 count = count + 2;

122 end

123 for i = 0:m

124 RotationMatrix(count:count+1,count:count+1) = ...

125 [cos(i * ti), −sin(i * ti); ...

126 sin(i * ti),cos(i * ti)];

127 count = count + 2;

128 end

129 Zi = RotationMatrix * V;

130

131 A11 = −CTf * inv(Lmatrix) * (Rmatrix * invCTf);

132 A22 = −1/Rdc/C;

133

134 A11 = A11(1:2,1:2);

135

136 A = zeros(3,3,8);

137 for Sc = 0:1

138 for Sb = 0:1

139 for Sa = 0:1

140 index = Sc * 2ˆ2+Sb * 2ˆ1+Sa * 2ˆ0+1;

Page 155: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 149

141 A12 = −1/L * CTf(1:2,1:3) * [Sa;Sb;Sc];

142 A21 = 1/C * [Sa Sb Sc] * invCTf(:,1:2);

143 A(:,:,index) = [A11 A12;A21 A22];

144 end

145 end

146 end

147

148 Omega = zeros(2 * lenHarm+2 * m+2,2 * lenHarm+2 * m+2);

149 M = zeros(2 * lenHarm+2 * m+2,2 * lenHarm+2 * m+2);

150 %Calculation of N

151

152 Nbase = CTf * inv(Lmatrix) * invCTf;

153 Nbase = Nbase(1:2,1:2);

154 N11 = zeros(2,lenHarm);

155 N = zeros(3,2 * lenHarm+2 * m+2);

156

157 for i = 0:lenHarm −1

158 N11(1:2,2 * i+1:2 * i+2) = Nbase;

159 end

160 N(1:2,1:2 * lenHarm) = N11;

161

162 for i = 1:2:2 * m+2

163 N(3,2 * lenHarm+i) = 1/C;

164 end

165

166 %Calculation of Omega

167 count = 1;

168 %Calculation of Omega = M

169 for i = h: −1:0

170 Omega(count:count+1,count:count+1) = [0 i * wac; −i * wac 0];

171 count = count + 2;

172 end

173 for i = 1:h

174 Omega(count:count+1,count:count+1) = [0 −i * wac;i * wac 0];

175 count = count + 2;

176 end

177 for i = 0:m

178 Omega(count:count+1,count:count+1) = [0 −i * wac;i * wac 0];

179 count = count + 2;

180 end

181

Page 156: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 150

182 M = Omega;

183 H = zeros(2 * lenHarm+2 * m+2,3);

184

185 count = 1;

186 for i = h: −1: −h

187 H(count:count+1,1:2) = 1/2/pi * [cos(i * 2* pi) ...

sin(i * 2* pi); −sin(i * 2* pi) cos(i * 2* pi)];

188 count = count + 2;

189 end

190

191 for i = 2 * lenHarm+1:2:2 * lenHarm+2 * m+2

192 H(i,3) = 1/Tac;

193 end

194

195 Ahat = ...

zeros(3+2 * lenHarm+2 * m+2+2* lenHarm+2 * m+2,3+2 * lenHarm+2 * m+2+2* lenHarm+2 * m+2);

196 Ahat(1:3,3+1:2 * lenHarm+2 * m+2+3) = N;

197 Ahat(2 * lenHarm+2 * m+2+3+1:end,1:3) = H;

198 Ahat(3+1:2 * lenHarm+2 * m+2+3,3+1:2 * lenHarm+2 * m+2+3) = Omega;

199 Ahat(3+1+2 * lenHarm+2 * m+2:end,3+1+2 * lenHarm+2 * m+2:end) = M;

200

201 %initializing phi *****

202 phi = eye(length(Ahat),length(Ahat));

203 leftFCMterms = zeros(length(phi),length(phi),numSWTim es−1);

204 rightFCMterms = zeros(length(phi),length(phi),numSWTi mes−1);

205

206 index = ...

sw data(numSWTimes,3) * 2ˆ2+sw data(numSWTimes,2) * 2ˆ1+sw data(numSWTimes,1) * 2ˆ0+1;

207 Ahat(1:3,1:3) = A(:,:,index);

208 leftFCMterms(1:end,1:end,1) = expm(Ahat * switchTimes(end));

209

210 index = sw data(1,3) * 2ˆ2+sw data(1,2) * 2ˆ1+sw data(1,1) * 2ˆ0+1;

211 Ahat(1:3,1:3) = A(:,:,index);

212 rightFCMterms(1:end,1:end,end) = expm(Ahat * switchTimes(1));

213

214 j = 2;

215 for i = numSWTimes−1: −1:2

216 index = sw data(i,3) * 2ˆ2+sw data(i,2) * 2ˆ1+sw data(i,1) * 2ˆ0+1;

217 Ahat(1:3,1:3) = A(:,:,index);

218 leftFCMterms(:,:,j) = ...

leftFCMterms(:,:,j −1) * expm(Ahat * switchTimes(i));

Page 157: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 151

219 j = j + 1;

220 end

221

222 j = numSWTimes−2;

223 for i = 2:numSWTimes −1

224 index = sw data(i,3) * 2ˆ2+sw data(i,2) * 2ˆ1+sw data(i,1) * 2ˆ0+1;

225 Ahat(1:3,1:3) = A(:,:,index);

226 rightFCMterms(:,:,j) = ...

expm(Ahat * switchTimes(i)) * rightFCMterms(:,:,j+1);

227 j = j − 1;

228 end

229

230 phi = leftFCMterms(:,:,5) * rightFCMterms(:,:,5);

231

232 Hp = phi(2 * lenHarm+2 * m+2+3+1:end,1:3);

233 Ap = phi(1:3,1:3);

234 Np = phi(1:3,3+1:2 * lenHarm+2 * m+2+3);

235 Qp = phi(2 * lenHarm+2 * m+2+3+1:end,3+1:3+2 * lenHarm+2 * m+2);

236

237 FCM = Hp* (inv(eye(3,3) −Ap)) * Np+Qp;

238 Ialphabeta = FCM * Zi;

239 Vdc = Ialphabeta(2 * lenHarm+1);

240

241 dPhi dma = 0;

242 dPhi dsigma = 0;

243 sub = 0;

244

245 for i = 1:mf

246 if i == mf

247 sub = 1;

248 end

249 for j = 1:6 −sub

250 pos = (i −1) * 6+j;

251 Ang1 = sw data(pos,4);

252 Ang2 = sw data(pos,5);

253 if j ≤ 2

254 dmaTerm = Tac/4/mf * (cos(Ang1) −cos(Ang2));

255 dsigmaTerm = Tac/4/mf * ma* ( −sin(Ang1)+sin(Ang2));

256 elseif j == 3

257 dmaTerm = Tac/4/mf * (cos(Ang2)+cos(Ang1));

258 dsigmaTerm = −Tac/4/mf * ma* (sin(Ang2)+sin(Ang1));

Page 158: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 152

259 elseif j ≤ 5

260 dmaTerm = −Tac/4/mf * (cos(Ang1) −cos(Ang2));

261 dsigmaTerm = −Tac/4/mf * ma* ( −sin(Ang1)+sin(Ang2));

262 else

263 dmaTerm = −Tac/4/mf * (cos(Ang2)+cos(Ang1));

264 dsigmaTerm = Tac/4/mf * ma* (sin(Ang2)+sin(Ang1));

265 end

266 index = ...

sw data(pos,3) * 2ˆ2+sw data(pos,2) * 2ˆ1+sw data(pos,1) * 2ˆ0+1;

267 Ahat(1:3,1:3) = A(:,:,index);

268

269 dPhi dma = dPhi dma + leftFCMterms(:,:,numSWTimes −pos) * ...

270 dmaTerm* Ahat * rightFCMterms(:,:,numSWTimes −pos);

271

272 dPhi dsigma = dPhi dsigma + ...

leftFCMterms(:,:,numSWTimes −pos) * ...

273 dsigmaTerm * Ahat * rightFCMterms(:,:,numSWTimes −pos);

274 end

275 end

276

277 dHp dma = dPhi dma(2 * lenHarm+2 * m+2+3+1:end,1:3);

278 dAp dma = dPhi dma(1:3,1:3);

279 dNp dma = dPhi dma(1:3,3+1:2 * lenHarm+2 * m+2+3);

280 dQp dma = dPhi dma(2 * lenHarm+2 * m+2+3+1:end,3+1:3+2 * lenHarm+2 * m+2);

281

282 dHp dsigma = dPhi dsigma(2 * lenHarm+2 * m+2+3+1:end,1:3);

283 dAp dsigma = dPhi dsigma(1:3,1:3);

284 dNp dsigma = dPhi dsigma(1:3,3+1:2 * lenHarm+2 * m+2+3);

285 dQp dsigma = ...

dPhi dsigma(2 * lenHarm+2 * m+2+3+1:end,3+1:3+2 * lenHarm+2 * m+2);

286

287 dFCMdma = derivFCM(dHp dma,dNp dma,dQp dma,dAp dma,Hp,Np,Ap);

288 dFCMdsigma = ...

derivFCM(dHp dsigma,dNp dsigma,dQp dsigma,dAp dsigma,Hp,Np,Ap);

289

290 %*************************************************** *******************

291

292 dQ dma = 0;

293 dQ dsigma = 0;

294

295 i = 2 * h+3;

Page 159: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 153

296 dIsa dma = dFCMdma(i,1:end) * Zi;

297 dIsb dma = dFCMdma(i+1,1:end) * Zi;

298 dIsa dsigma = dFCM dsigma(i,1:end) * Zi;

299 dIsb dsigma = dFCM dsigma(i+1,1:end) * Zi;

300 dQ dma = dQ dma−3/2 * Zi(i) * dIsb dma+3/2 * Zi(i+1) * dIsa dma;

301 dQ dsigma = dQ dsigma −3/2 * Zi(i) * dIsb dsigma+3/2 * Zi(i+1) * dIsa dsigma;

302 i = 2 * h;

303 dIsa dma = dFCMdma(i,1:end) * Zi;

304 dIsb dma = dFCMdma(i+1,1:end) * Zi;

305 dIsa dsigma = dFCM dsigma(i,1:end) * Zi;

306 dIsb dsigma = dFCM dsigma(i+1,1:end) * Zi;

307 dQ dma = dQ dma−3/2 * Zi(i) * dIsb dma+3/2 * Zi(i+1) * dIsa dma;

308 dQ dsigma = dQ dsigma −3/2 * Zi(i) * dIsb dsigma+3/2 * Zi(i+1) * dIsa dsigma;

309

310

311 dP dma = Idc * dFCMdma(2 * lenHarm+1,1:end) * Zi;

312 dP dsigma = Idc * dFCMdsigma(2 * lenHarm+1,1:end) * Zi;

313 Qnegseq = ...

3/2 * imag((Zi(2 * h+3)+1i * Zi(2 * h+4)) * conj(Ialphabeta(2 * h+3)+1i * Ialphabeta(2 * h+4)))

314 Qposseq = ...

−3/2 * imag((Zi(2 * h−1)+1i * Zi(2 * h)) * conj(Ialphabeta(2 * h−1)+1i * Ialphabeta(2 * h)));

315 Qcalc = Qposseq+Qnegseq;

316

317 Pcalc = Idc * Vdc;

318 Jload = [dP dsigma,dP dma;dQ dsigma,dQ dma];

319

320 delP = Pload − Pcalc;

321 delQ = Qload − Qcalc;

322

323 temp = [sigma;ma] + Jload \[delP;delQ];

324 sigma = temp(1);

325 ma = temp(2);

326

327 if (ma > 1)

328 overModCount = overModCount + 1;

329 if overModCount > 4

330 error = 1;

331 break ;

332 end

333 elseif overModCount > 0

334 overModCount = 0;

Page 160: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 154

335 end

336

337 if ma < 0

338 ma = 0.01;

339 end

340 if abs(delP) < tolerance && abs(delQ) < tolerance

341 break

342 end

343 loopCount = loopCount+1;

344

345 if loopCount == 50

346 c = clock;

347 fprintf(errorFile, '%2.0fh:%2.0fm:%2.0fs Solution does not ...

exist for VSC \n' ,c(4),c(5),c(6));

348 error = 1;

349 break ;

350 end

351 end

352

353 if ma > 1 && overModCount ≤ 4

354 c = clock;

355 fprintf(errorFile, '%2.0fh:%2.0fm:%2.0fs Solution does not exist. ...

Increase Vdc. \n' ,c(4),c(5),c(6));

356 error = 1;

357 end

358

359 count = 1;

360 for i = −h:1:h

361 RotationMatrix(count:count+1,count:count+1) = ...

362 [cos( −i * ti), −sin( −i * ti);sin( −i * ti) cos( −i * ti)];

363 count = count + 2;

364 end

365 for i = 0:1:m

366 RotationMatrix(count:count+1,count:count+1) = ...

367 [cos( −i * ti), −sin( −i * ti);sin( −i * ti) cos( −i * ti)];

368 count = count + 2;

369 end

370

371 tempM = eye(2 * lenHarm+2 * m+2);

372 tempM(2 * lenHarm+3:end,2 * lenHarm+1:end) = ...

2* tempM(2 * lenHarm+3:end,2 * lenHarm+1:end);

Page 161: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 155

373 Ialphabeta = tempM * RotationMatrix * Ialphabeta;

374 sigma = mod(sigma,2 * pi);

375 [Ia Ib Ic fundCurrents] = getI abc fundCurrents(Ialphabeta,h);

376

377 fclose(errorFile);

derivFCM.m

1 function dFCM = derivFCM(dHp,dNp,dQp,dAp,Hp,Np,Ap)

2

3 dInvImMtx = get dInvImMtx(Ap,dAp);

4 InvImMtx = inv(eye(3) −Ap);

5

6 dFCM = dHp* InvImMtx * Np+Hp* dInvImMtx * Np+Hp* InvImMtx * dNp+dQp;

B.2.2 Thyristor 6-Pulse Rectifier

solveThyristor6.m

1 function [Ia,Ib,Ic,fundCurrents,alpha,mu] = ...

solveThyristor6(Valphabeta,L,R, ...

2 Rdc,Ldc,h,Vdc,P in)

3

4 global OpenDSSFileLoc

5

6 P = P in;

7 errorFile = fopen([OpenDSSFileLoc, 'errorFile.txt' ], 'w' );

8

9 if Vdc ≥ 1.7321 | | Vdc < 0

10 c = clock;

11 if Vdc ≥ 1.7321

12 fprintf(errorFile, '%2.0fh:%2.0fm:%2.0fs Thyristor 6 pulse ...

model will not conduct any current because Vdc pu > ...

1.73 \n' ,c(4),c(5),c(6));

Page 162: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 156

13 else

14 fprintf(errorFile, '%2.0fh:%2.0fm:%2.0fs Thyristor 6 pulse ...

model will not conduct any current Vdc pu must be > ...

0\n' ,c(4),c(5),c(6));

15 end

16 Iphase = zeros(h,3);

17

18 for i = 1:h

19 Iphase(i,1) = i;

20 end

21 Iphase(1,2) = 100;

22 Ia = Iphase;

23 Ib = Iphase;

24 Ic = Iphase;

25 fundCurrents = [0,0;0, −120;0,+120];

26 alpha = 0;

27 mu = zeros(6,1);

28 return ;

29 end

30

31 if P > 3 %restricting to 2 pu

32 c = clock;

33 fprintf(errorFile, '%2.0fh:%2.0fm:%2.0fs P > Pmax = 3.0 pu. ...

Setting P = 3.0 pu. \n' ,c(4),c(5),c(6));

34 Iphase = zeros(h,3);

35

36 for i = 1:h

37 Iphase(i,1) = i;

38 end

39 Iphase(1,2) = 100;

40 Ia = Iphase;

41 Ib = Iphase;

42 Ic = Iphase;

43 fundCurrents = [0,0;0, −120;0,+120];

44 alpha = 0;

45 mu = zeros(6,1);

46 return ;

47 end

48 if P ≤ 0 %restricting to 2 pu

49 c = clock;

50 Iphase = zeros(h,3);

Page 163: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 157

51 for i = 1:h

52 Iphase(i,1) = i;

53 end

54 Iphase(1,2) = 100;

55 Ia = Iphase;

56 Ib = Iphase;

57 Ic = Iphase;

58 fundCurrents = [0,0;0, −120;0,+120];

59 alpha = 0;

60 mu = zeros(6,1);

61 fprintf(errorFile, '%2.0fh:%2.0fm:%2.0fs P < Pmin = 0.0 ...

pu. \n' ,c(4),c(5),c(6));

62 return ;

63 end

64

65 %Initializations

66 alpha i = 0;

67 alpha = alpha i;

68 mu = −100;

69 Vs mag = abs(Valphabeta(2 * h+3)+1i * Valphabeta(2 * h+4));

70

71 while (alpha > pi * 3/2 | | alpha < 0 | | mu < 0 | | mu > pi/3)

72 convergance = 0;

73 alpha i = alpha i+pi/3/100;

74 alpha = alpha i;

75 if alpha > pi * 3/2

76 c = clock;

77 fprintf(errorFile, '%2.0fh:%2.0fm:%2.0fs 12 pulse thyristor ...

model cannot find solution. Try another Vdc ...

value. \n' ,c(4),c(5),c(6));

78 Iphase = zeros(h,3);

79

80 for i = 1:h

81 Iphase(i,1) = i;

82 end

83 Iphase(1,2) = 100;

84 Ia = Iphase;

85 Ib = Iphase;

86 Ic = Iphase;

87 fundCurrents = [0,0;0, −120;0,+120];

88 alpha = 0;

Page 164: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 158

89 mu = zeros(12,1);

90 return ;

91 end

92 while (convergance == 0)

93 checkVal = 2 * pi/3/sqrt(3) * Vdc/Vs mag − cos(alpha);

94 while (checkVal < −1 | | checkVal > 1)

95 alpha i = alpha i+pi/3/100;

96 alpha = alpha i;

97 checkVal = 2 * pi/3/sqrt(3) * Vdc/Vs mag − cos(alpha);

98 if alpha > pi * 3/2

99 c = clock;

100 fprintf(errorFile, '%2.0fh:%2.0fm:%2.0fs 12 pulse ...

thyristor model cannot find solution. Try another ...

Vdc value. \n' ,c(4),c(5),c(6));

101 Iphase = zeros(h,3);

102

103 for i = 1:h

104 Iphase(i,1) = i;

105 end

106 Iphase(1,2) = 100;

107 Ia = Iphase;

108 Ib = Iphase;

109 Ic = Iphase;

110 fundCurrents = [0,0;0, −120;0,+120];

111 alpha = 0;

112 mu = zeros(12,1);

113 return ;

114 end

115 end

116 mu = acos(checkVal) −alpha;

117 Idc calc = ...

1/2/L * ( −sqrt(3) * cos(alpha+mu)+sqrt(3) * cos(alpha)) * Vs mag;

118

119 J = ...

sqrt(3)/2/L * ( −sqrt(3) * sin(alpha) −sin(alpha)/sqrt(1 −(pi/3/sqrt(3) * Vdc/Vs ma

120

121 M = P−Vdc* Idc calc;

122

123

124 if abs(M) < 0.00001

125 convergance = 1;

Page 165: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 159

126 break ;

127 end

128

129 alpha = alpha+1/J * M;

130 end

131 end

132

133 mu prev = mu * ones(6,1);

134 alpha prev = alpha;

135

136 center = 2 * h+1;

137 convergance = 0;

138 %****************

139

140 for i = 1:2:h

141 V = Valphabeta(center −i * 2:center+i * 2+1);

142 while (convergance == 0)

143 [Ia Ib Ic fundCurrents alpha mu error] = ...

144 solveThyristor6Model(V,L,R,Rdc,Ldc,i,0,P,mu prev,alpha prev);

145

146 convergance = 1;

147

148 mu prev = mu;

149 alpha prev = alpha;

150

151 end

152 convergance = 0;

153 end

solveThyristor6Model.m

1 function [Ia,Ib,Ic,fundCurrents,alpha,mu out,error] = ...

solveThyristor6Model(Valphabeta,L,R, ...

2 Rdc,Ldc,h,Vdc,P,mu in,alpha in)

3

4 global SymMtx invSymMtx

5

Page 166: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 160

6

7 countIter = 0;

8 Pload = P;

9 Rout = Rdc;

10 Lout = Ldc;

11 w = 1; %line frequency in rad/s

12 alpha = alpha in;

13 tolerance = 0.001;

14 f = w/2/pi;

15 Tac = 1/f;

16 Ra = R;

17 Rb = R;

18 Rc = R;

19 La = L;

20 Lb = L;

21 Lc = L;

22 lenHarm = 2 * h+1;

23 V abc = SymMtx * [0;Valphabeta(lenHarm+2)+1i * Valphabeta(lenHarm+3); ...

24 Valphabeta(2 * h−1)+1i * Valphabeta(2 * h)];

25 Mag abc = [abs(V abc(1));abs(V abc(2));abs(V abc(3))];

26 Phase abc = [angle(V abc(1));angle(V abc(2));angle(V abc(3))];

27 error = 0;

28 CTF = 2/3 * [1 −1/2 −1/2;0 sqrt(3)/2 −sqrt(3)/2;1/sqrt(2) 1/sqrt(2) ...

1/sqrt(2)];

29 invCTF = inv(CTF);

30

31 Mi = zeros(6,2);

32 Mi(2,1:end) = [1 0];

33 Mi(3,1:end) = −1* [ −1/2 −sqrt(3)/2];

34 Mi(1,1:end) = −1* [ −1/2 sqrt(3)/2];

35 Mi(5,1:end) = −1* [1 0];

36 Mi(6,1:end) = [ −1/2 −sqrt(3)/2];

37 Mi(4,1:end) = [ −1/2 sqrt(3)/2];

38 %end initializations ************************

39

40 Vsabc phasor = zeros(3,1);

41 for i = 1:3

42 [x y] = pol2cart(Phase abc(i),Mag abc(i));

43 Vsabc phasor(i) = x + 1i * y;

44 end

45

Page 167: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 161

46 temp = [1 −1 0;0 1 −1; −1 0 ...

1] * [Vsabc phasor(1);Vsabc phasor(2);Vsabc phasor(3)];

47

48 Mag sv = abs(temp);

49 Phase sv = angle(temp);

50 flag error = 0;

51

52 maxPos = 3+3* lenHarm+1;

53

54 symMatrix = invSymMtx * Vsabc phasor;

55

56 posSeq = symMatrix(2);

57 negSeq = symMatrix(3);

58

59 phase = angle(posSeq) −0;

60 Ts = zeros(18,1);

61 Ts(1:end) = [1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6];

62

63 Zi = zeros(3 * lenHarm+1,1);

64 Zi(1:2 * lenHarm,1) = Valphabeta;

65 Zi(2 * lenHarm+1) = Vdc;

66 %*************************************************** ***********************

67

68 %Now that the Ts(1,1) and alpha are known and the input vector has been

69 %provided...we can use a rotation matrix to move the input ve ctor to ...

a time

70 %equal to Ts(1,1) + alpha

71 %Ts(* , * ) contains the swithing times and the 2 phase voltage ...

conduction for

72 %each conduction interval from 0 −> 2* pi

73 %An example: Ts(i,1) contains the next switching time, and T s(i,2) ...

contains

74 %the 2 phase voltage conduction for Ts(i −1,1) −−> Ts(i,1)

75

76 Acomm = zeros(3,3,6);

77 Acond = zeros(3,3,6);

78 Ncond = zeros(3,3 * lenHarm+1,6);

79 %Transition from Vab −> Vac

80 Acomm(1:2,1:end,1) = [ −(3/2 * R+Rout)/(3/2 * L+Lout),0,0; ...

81 0, −R/L,0];

82 Acomm(3,1:end,1) = [0,0, −(3/2 * R+Rout)/(3/2 * L+Lout)];

Page 168: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 162

83 %Transition from Vca −> Vcb

84 Acomm(1:2,1:end,5) = ...

[1/(2 * L* L+4* (L+Lout) * L) * ( −2* L* R−3* (L+Lout) * R−L* (R+Rout)), ...

85 1/(2 * L* L+4* (L+Lout) * L) * (sqrt(3) * (L+Lout) * R−sqrt(3) * L* (R+Rout)),0; ...

86 1/(2 * sqrt(3) * L* L+4* sqrt(3) * L* (L+Lout)) * (3 * (L+Lout) * R−3* L* (R+Rout)), ...

87 1/(2 * sqrt(3) * L* L+4* sqrt(3) * L* (L+Lout)) * ( −2* sqrt(3) * L* R−sqrt(3) * (L+Lout) * R−3* sqrt(3)

88 Acomm(3,1:end,5) = [0,0, −(3/2 * R+Rout)/(3/2 * L+Lout)];

89 %Transition from Vbc −> Vba

90 Acomm(1:2,1:end,3) = ...

[ −(2 * L* R+3* (L+Lout) * R+L* (R+Rout))/(2 * L* L+4* (L+Lout) * L), ...

91 −(sqrt(3) * (L+Lout) * R−sqrt(3) * L* (R+Rout))/(2 * L* L+4* (L+Lout) * L),0; ...

92 −(3 * (L+Lout) * R−3* L* (R+Rout))/(2 * sqrt(3) * L* L+4* sqrt(3) * (L+Lout) * L), ...

93 ( −2* sqrt(3) * L* R−sqrt(3) * (L+Lout) * R−sqrt(3) * 3* L* (R+Rout))/(2 * sqrt(3) * L* L+4* sqrt(3)

94 Acomm(3,1:end,3) = [0,0, −(3/2 * R+Rout)/(3/2 * L+Lout)];

95 %Transition from Vba −> Vca

96 Acomm(1:end,1:end,4) = Acomm(1:end,1:end,1);

97 %Transition from Vac −> Vbc

98 Acomm(1:end,1:end,2) = Acomm(1:end,1:end,5);

99 %Transition from Vcb −> Vab

100 Acomm(1:end,1:end,6) = Acomm(1:end,1:end,3);

101

102 %Now initializing the conduction A arrays

103

104 Acond(1:2,1:end,6) = [ −(Ra+Rb+Rout)/(La+Lb+Lout),0,0; ...

105 0, −(Ra+Rb+Rout)/(La+Lb+Lout),0];

106 Acond(3,1:end,6) = [0,0, −(Ra+Rb+Rout)/(La+Lb+Lout)];

107 Acond(1:2,1:end,2) = [ −(Ra+Rb+Rout)/(La+Lb+Lout),0,0; ...

108 0, −(Ra+Rb+Rout)/(La+Lb+Lout),0];

109 Acond(3,1:end,2) = [0,0, −(Rc+Rb+Rout)/(Lc+Lb+Lout)];

110 Acond(1:2,1:end,4) = [ −(Ra+Rb+Rout)/(La+Lb+Lout),0,0; ...

111 0, −(Ra+Rb+Rout)/(La+Lb+Lout),0];

112 Acond(3,1:end,4) = [0,0, −(Ra+Rc+Rout)/(La+Lc+Lout)];

113 Acond(1:end,1:end,1) = Acond(1:end,1:end,4);

114 Acond(1:end,1:end,3) = Acond(1:end,1:end,6);

115 Acond(1:end,1:end,5) = Acond(1:end,1:end,2);

116 %****************************************

117 %first row is for the disalpha/dt, column 1 vsalpha, column 2 vsbeta,

118 %column 3 v dc 119 %second row is for the disbeta/dt

120 %third dimension is for differentiating between the differ ent ...

intervals. −

Page 169: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 163

121 coeffArr = zeros(3,3,6);

122 coeffArr(1,1,6) = 3/2/(La+Lb+Lout);

123 coeffArr(1,2,6) = −sqrt(3)/2/(La+Lb+Lout);

124 coeffArr(1,3,6) = −1/(La+Lb+Lout);

125 coeffArr(2,1,6) = −sqrt(3)/2/(La+Lb+Lout);

126 coeffArr(2,2,6) = 1/2/(La+Lb+Lout);

127 coeffArr(2,3,6) = 1/sqrt(3)/(La+Lb+Lout);

128 coeffArr(3,1,6) = 3/2/(La+Lb+Lout);

129 coeffArr(3,2,6) = −sqrt(3)/2/(La+Lb+Lout);

130 coeffArr(3,3,6) = −1/(La+Lb+Lout);

131 coeffArr(2,2,2) = 2/(Lb+Lc+Lout);

132 coeffArr(2,3,2) = −2/sqrt(3)/(Lb+Lc+Lout);

133 coeffArr(3,2,2) = sqrt(3)/(Lc+Lb+Lout);

134 coeffArr(3,3,2) = −1/(Lc+Lb+Lout);

135 coeffArr(1,1,4) = 3/2/(La+Lc+Lout);

136 coeffArr(1,2,4) = sqrt(3)/2/(Lc+La+Lout);

137 coeffArr(1,3,4) = 1/(La+Lc+Lout);

138 coeffArr(2,1,4) = sqrt(3)/2/(La+Lc+Lout);

139 coeffArr(2,2,4) = 1/2/(La+Lc+Lout);

140 coeffArr(2,3,4) = 1/sqrt(3)/(La+Lc+Lout);

141 coeffArr(3,1,4) = −3/2/(La+Lc+Lout);

142 coeffArr(3,2,4) = −sqrt(3)/2/(La+Lc+Lout);

143 coeffArr(3,3,4) = −1/(La+Lb+Lout);

144 coeffArr(1:end,1:end,1) = coeffArr(1:end,1:end,4);

145 coeffArr(1:end,1:end,3) = coeffArr(1:end,1:end,6);

146 coeffArr(1:end,1:end,5) = coeffArr(1:end,1:end,2);

147 coeffArr(1:2,3,1) = coeffArr(1:2,3,1) *−1;

148 coeffArr(1:2,3,3) = coeffArr(1:2,3,3) *−1;

149 coeffArr(1:2,3,5) = coeffArr(1:2,3,5) *−1;

150 coeffArr(3,1,1) = coeffArr(3,1,1) *−1;

151 coeffArr(3,2,1) = coeffArr(3,2,1) *−1;

152 coeffArr(3,1,3) = coeffArr(3,1,3) *−1;

153 coeffArr(3,2,3) = coeffArr(3,2,3) *−1;

154 coeffArr(3,1,5) = coeffArr(3,1,5) *−1;

155 coeffArr(3,2,5) = coeffArr(3,2,5) *−1;

156 %****************************************

157

158 for j = 1:6

159 for i = 1:2:2 * lenHarm

160 Ncond(1:end,i:i+1,j) = coeffArr(1:end,1:2,j);

161 end

Page 170: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 164

162 end

163 %****************************************

164 for j = 1:6

165 for i = 2 * lenHarm+1:2:2 * lenHarm+lenHarm+1

166 Ncond(1:end,i:i+1,j) = ...

[coeffArr(1,3,j),0;coeffArr(2,3,j),0;coeffArr(3,3,j ),0];

167 end

168 end

169 %****************************************

170

171 coeffArr comm = zeros(3,3,6);

172 Ncomm = zeros(3,3 * lenHarm+1,6);

173

174 coeffArr comm(1:end,1:end,1) = [3/2/(3/2 * L+Lout) 0 −1/(3/2 * L+Lout); ...

175 0 1/L 0;3/2/(3/2 * L+Lout) 0 −1/(3/2 *L+Lout)];

176 coeffArr comm(1:end,1:end,5) = ...

[(3 * L+3* (L+Lout))/(2 * L* L+4* (L+Lout) * L), ...

177 −sqrt(3) * Lout/(2 * L* L+4* (L+Lout) * L),2 * L/(2 * L* L+4* (L+Lout) * L); ...

178 −3* Lout/(2 * sqrt(3) * L* L+4* sqrt(3) * (L+Lout) * L), ...

179 (5 * sqrt(3) * L+sqrt(3) * (L+Lout))/(2 * sqrt(3) * L* L+4* sqrt(3) * (L+Lout) * L), ...

180 6* L/(2 * sqrt(3) * L* L+4* sqrt(3) * (L+Lout) * L); −3/4/(3/2 * L+Lout), ...

181 −3* sqrt(3)/4/(3/2 * L+Lout), −1/(3/2 * L+Lout)];

182 coeffArr comm(1:end,1:end,3) = ...

[(3 * L+3* (L+Lout))/(2 * L* L+4* (L+Lout) * L), ...

183 sqrt(3) * Lout/(2 * L* L+4* (L+Lout) * L),2 * L/(2 * L* L+4* (L+Lout) * L); ...

184 (3 * (L+Lout) −3* L)/(2 * sqrt(3) * L* L+4* sqrt(3) * (L+Lout) * L), ...

185 (5 * sqrt(3) * L+sqrt(3) * (L+Lout))/(2 * sqrt(3) * L* L+4* sqrt(3) * (L+Lout) * L), ...

186 −6* L/(2 * sqrt(3) * L* L+4* sqrt(3) * (L+Lout) * L); −3/4/(3/2 * L+Lout), ...

187 3* sqrt(3)/4/(3/2 * L+Lout) −1/(3/2 * L+Lout)];

188 coeffArr comm(1:end,1:end,2) = coeffArr comm(1:end,1:end,5);

189 coeffArr comm(1:end,1:end,4) = coeffArr comm(1:end,1:end,1);

190 coeffArr comm(1:end,1:end,6) = coeffArr comm(1:end,1:end,3);

191 coeffArr comm(1:2,3,2) = coeffArr comm(1:2,3,2) *−1;

192 coeffArr comm(1:2,3,4) = coeffArr comm(1:2,3,4) *−1;

193 coeffArr comm(1:2,3,6) = coeffArr comm(1:2,3,6) *−1;

194 coeffArr comm(3,1:2,2) = coeffArr comm(3,1:2,2) *−1;

195 coeffArr comm(3,1:2,4) = coeffArr comm(3,1:2,4) *−1;

196 coeffArr comm(3,1:2,6) = coeffArr comm(3,1:2,6) *−1;

197

198 %****************************************

199 for j = 1:6

Page 171: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 165

200 for i = 1:2:2 * lenHarm

201 Ncomm(1:end,i:i+1,j) = coeffArr comm(1:3,1:2,j);

202 end

203 end

204 %****************************************

205 %****************************************

206 for j = 1:6

207 for i = 2 * lenHarm+1:2:2 * lenHarm+lenHarm+1

208 Ncomm(1:end,i:i+1,j) = [coeffArr comm(1,3,j),0; ...

209 coeffArr comm(2,3,j),0;coeffArr comm(3,3,j),0];

210 end

211 end

212 %****************************************

213 mu = zeros(7,1);

214 mu(1:6) = mu in;

215 mu(7) = alpha in;

216 new mu = zeros(7,1);

217 tempArr = [1 0 0;0 1 0;0 0 1];

218 At = zeros(3,3);

219 Nt = zeros(3,4 * lenHarm);

220 Omegat = zeros(3 * lenHarm+1,3 * lenHarm+1);

221 ThetaM = [1 0;0 1];

222

223 count = −h;

224 for i = 1:2:2 * lenHarm

225 Omegat(i:i+1,i:i+1) = [0 −count;count 0];

226 count = count + 1;

227 end

228 count = 0;

229 for i = 2 * lenHarm+1:2:2 * lenHarm+lenHarm

230 Omegat(i:i+1,i:i+1) = [0 −count;count 0];

231 count = count + 1;

232 end

233

234 Mcond = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1);

235 Mcomm = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1);

236 Mt arr = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1,6);

237 derivMp = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1,6,6);

238 Mp = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1,6);

239 Ap = zeros(3,3,6);

240 Np = zeros(3,3 * lenHarm+1,6);

Page 172: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 166

241 Omegap = zeros(3 * lenHarm+1,3 * lenHarm+1,6);

242

243 %This loop is used to solve for the alpha that will yield the re quired

244 %power sourced by the load.

245

246 Ipwr alpha = 0;

247 Ipwr beta = 0;

248

249 Ahat = zeros(3+3 * lenHarm+1+3 * lenHarm+1);

250

251 H = zeros(3 * lenHarm+1,3);

252 Mm = Omegat;

253

254 count = 1;

255 for i = h: −1: −h

256 H(count:count+1,1:2) = 1/2/pi * [cos(i * 2* pi) ...

sin(i * 2* pi); −sin(i * 2* pi) cos(i * 2* pi)];

257 count = count + 2;

258 end

259

260 for i = count:2:count+2 * h+2−1

261 H(i,3) = 1/Tac;

262 end

263

264 Ahat(3+3 * lenHarm+1+1:end,1:3) = H;

265 Ahat(4:3+3 * lenHarm+1,4:3+3 * lenHarm+1) = Omegat;

266 Ahat(3+3 * lenHarm+1+1:end,3+3 * lenHarm+1+1:end) = Mm;

267

268 while (true)

269 %This loop is used to solve for mu(1) −−> mu(6) through a Newton ...

Raphson

270 %Iterative solving technique.

271

272 RotationMatrix = zeros(3 * lenHarm+1,3 * lenHarm+1,6);

273 Zi arr = zeros(3 * lenHarm+1,6);

274 for k = 0:1:5

275 count = 1;

276 for i = −h:1:h

277 RotationMatrix(count:count+1,count:count+1,k+1) = ...

278 [cos(i * (k * pi/3+alpha −phase)), ...

279 −sin(i * (k * pi/3+alpha −phase)); ...

Page 173: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 167

280 sin(i * (k * pi/3+alpha −phase)), ...

281 cos(i * (k * pi/3+alpha −phase))];

282 count = count + 2;

283 end

284 for i = 0:h

285 RotationMatrix(count:count+1,count:count+1,k+1) = ...

286 [cos(i * (k * pi/3+alpha −phase)), ...

287 −sin(i * (k * pi/3+alpha −phase)); ...

288 sin(i * (k * pi/3+alpha −phase)), ...

289 cos(i * (k * pi/3+alpha −phase))];

290 count = count + 2;

291 end

292 Zi arr(1:end,k+1) = RotationMatrix(1:end,1:end,k+1) * Zi;

293 end

294

295 %This block of code generates the Mp matrix elements and the d Mp/dx

296 %elements

297 %This block of code obtaines all the matrix exponentials tha t ...

will be

298 %needed for the first part of the code.

299 %third column is referring to interval with respect to the pr imary

300 %rotation configuration

301 %fourth column contains 3 particular exponential calculat ions

302 expmCommMu = zeros(length(Ahat),length(Ahat),6);

303 expmCondMu = zeros(length(Ahat),length(Ahat),6);

304 expmCondMuPi 3 = zeros(length(Ahat),length(Ahat),6);

305

306 Phi = eye(3+3 * lenHarm+1+3 * lenHarm+1);

307 for i = 1:6

308 Ahat(1:3,1:3+3 * lenHarm+1) = ...

[Acomm(1:end,1:end,i),Ncomm(1:end,1:end,i)];

309 expmCommMu(1:end,1:end,i) = expm(Ahat * mu(i));

310 Ahat(1:3,1:3+3 * lenHarm+1) = ...

[Acond(1:end,1:end,i),Ncond(1:end,1:end,i)];

311 expmCondMu(1:end,1:end,i) = expm( −Ahat * mu(i));

312 expmCondMuPi 3(1:end,1:end,i) = expm(Ahat * pi/3);

313

314 Phi = expmCondMuPi 3(1:end,1:end,i) * ...

315 expmCondMu(1:end,1:end,i) * expmCommMu(1:end,1:end,i) * Phi;

316 end

317

Page 174: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 168

318 %Calculating ...

FCM*************************************************** ****

319 Hp = Phi(4+3 * lenHarm+1:end,1:3);

320 Ap mat = Phi(1:3,1:3);

321 Np mat = Phi(1:3,4:3 * lenHarm+4);

322 Qp = Phi(3 * lenHarm+4+1:end,4:3 * lenHarm+4);

323

324 FCM = Hp* (inv(eye(3,3) −Ap mat)) * Np mat+Qp;

325 I = FCM* Zi arr(1:end,1);

326 %*************************************************** *******************

327 for i = 1:6

328 Mp(1:end,1:end,i) = eye(length(Mp));

329 for j = 1:6

330 derivMp(1:end,1:end,i,j) = eye(length(derivMp));

331 end

332 end

333 %Calculating Mp and ...

derivMp ********************************************

334 for i = 1:6 %i refers to M1 through to M6

335 for j = 0:5 %j steps through to account for a whole period

336 Mcond(1:3,1:3) = Acond(1:end,1:end,Ts(i+j));

337 Mcond(1:3,4:end) = Ncond(1:end,1:end,Ts(i+j));

338 Mcond(4:end,4:end) = Omegat;

339 Mcomm(1:3,1:3) = Acomm(1:end,1:end,Ts(i+j));

340 Mcomm(1:3,4:end) = Ncomm(1:end,1:end,Ts(i+j));

341 Mcomm(4:end,4:end) = Omegat;

342

343 Mp(1:end,1:end,i) = ...

expmCondMuPi 3(1:maxPos,1:maxPos,Ts(j+i)) * ...

344 expmCondMu(1:maxPos,1:maxPos,Ts(j+i)) * ...

345 expmCommMu(1:maxPos,1:maxPos,Ts(i+j)) * Mp(1:end,1:end,i);

346

347 for k = 1:6 %k refers to taking derivative wrt ...

commutation overlap length with indice k

348 if k == (j+1)

349 derivMp(1:end,1:end,k,i) = ...

expmCondMuPi 3(1:maxPos,1:maxPos,Ts(j+i)) * ...

350 (−Mcond* expmCondMu(1:maxPos,1:maxPos,Ts(i+j))+ ...

351 expmCondMu(1:maxPos,1:maxPos,Ts(i+j)) * Mcomm)* expmCommMu(1:maxPos

352 derivMp(1:end,1:end,k,i);

353 else

Page 175: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 169

354 derivMp(1:end,1:end,k,i) = ...

expmCondMuPi 3(1:maxPos,1:maxPos,Ts(j+i)) * ...

355 expmCondMu(1:maxPos,1:maxPos,Ts(j+i)) * ...

356 expmCommMu(1:maxPos,1:maxPos,Ts(i+j)) * derivMp(1:end,1:end,k,i);

357 end

358 end

359 end

360 end

361

362 dMp dmu = zeros(length(Mp),length(Mp),6,6);

363

364 for i = 0:1:5

365 for j = 1:1:6

366 dMp dmu(1:end,1:end,Ts(j+i),i+1) = ...

derivMp(1:end,1:end,j,i+1);

367 end

368 end

369 %*************************************************** *******************

370 for i = 1:6

371 Ap(1:end,1:end,i) = Mp(1:3,1:3,i);

372 Np(1:end,1:end,i) = Mp(1:3,4:end,i);

373 Omegap(1:end,1:end,i) = Mp(4:end,4:end,i);

374 end

375

376 derivMt = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1,6);

377

378 %M2 SOLVE

379 %This block calculates the derivative of the Mt matrix ...

elements. *******

380 for i = 1:6

381 Mcomm(1:3,1:3) = Acomm(1:end,1:end,i);

382 Mcomm(1:3,4:end) = Ncomm(1:end,1:end,i);

383 Mcomm(4:end,4:end) = Omegat;

384

385 Mt arr(1:end,1:end,i) = expmCommMu(1:maxPos,1:maxPos,i);

386 derivMt(1:end,1:end,i) = Mcomm * Mt arr(1:end,1:end,i);

387 end

388 %*************************************************** *******************

389

390 dPhi dmu = zeros(length(Phi),length(Phi),6);

391 Ahat2 = Ahat;

Page 176: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 170

392

393 for i = 1:6

394 dPhi dmu(1:end,1:end,i) = eye(length(Phi));

395 for j = 1:6

396 if i == j

397 Ahat(1:3,1:3+3 * lenHarm+1) = ...

[Acomm(1:end,1:end,j),Ncomm(1:end,1:end,j)];

398 Ahat2(1:3,1:3+3 * lenHarm+1) = ...

[Acond(1:end,1:end,j),Ncond(1:end,1:end,j)];

399 dPhi dmu(1:end,1:end,i) = ...

expmCondMuPi 3(1:end,1:end,j) * ...

400 (−Ahat2 * expmCondMu(1:end,1:end,j)+expmCondMu(1:end,1:end,j) * Ahat)

401 * expmCommMu(1:end,1:end,j) * dPhi dmu(1:end,1:end,i);

402 else

403 dPhi dmu(1:end,1:end,i) = ...

expmCondMuPi 3(1:end,1:end,j) * ...

404 expmCondMu(1:end,1:end,j) * expmCommMu(1:end,1:end,j) * ...

405 dPhi dmu(1:end,1:end,i);

406 end

407 end

408 end

409

410 derivRotation = zeros(length(FCM),length(FCM),6);

411 for j = 0:1:5

412 count = 1;

413 for i = −h:1:h

414 derivRotation(count:count+1,count:count+1,j+1) = ...

[ −i * sin(i * (j * pi/3+alpha −phase)), ...

415 −i * cos(i * (j * pi/3+alpha −phase));i * cos(i * (j * pi/3+alpha −phase)) ...

−i * sin(i * (j * pi/3+alpha −phase))];

416 count = count + 2;

417 end

418 for i = 0:1:h

419 derivRotation(count:count+1,count:count+1,j+1) = ...

[ −i * sin(i * (j * pi/3+alpha −phase)), ...

420 −i * cos(i * (j * pi/3+alpha −phase));i * cos(i * (j * pi/3+alpha −phase)) ...

−i * sin(i * (j * pi/3+alpha −phase))];

421 count = count + 2;

422 end

423 end

424

Page 177: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 171

425 Idc = I(2 * lenHarm+1);

426 Vdc = Zi(2 * lenHarm+1);

427 Irow FCMdalpha = FCM * derivRotation(1:end,1:end,1);

428 Irow FCMdalpha = Irow FCMdalpha(2 * lenHarm+1,1:end);

429 dIdc dalpha = Irow FCMdalpha * Zi;

430

431 %**************************************************

432 J = zeros(7,7);

433 for i = 1:6

434 At = Mt arr(1:2,1:2,i);

435 Nt = Mt arr(1:2,4:end,i);

436 J(i,7) = Mi(i,1:end) * (At * inv(eye(2) −Ap(1:2,1:2,i)) * ...

437 Np(1:2,1:end,i)+Nt) * derivRotation(1:end,1:end,i) * Zi;

438 for j = 1:6

439 if i == j

440 dAt = derivMt(1:2,1:2,i);

441 dNt = derivMt(1:2,4:end,i);

442 else

443 dAt = zeros(2,2);

444 dNt = zeros(2,3 * lenHarm+1);

445 end

446 dAp = dMp dmu(1:2,1:2,j,i);

447 dNp = dMp dmu(1:2,4:end,j,i);

448 invA = inv(eye(2) −Ap(1:2,1:2,i));

449 det = (1 − Ap(1,1,i)) * (1 −Ap(2,2,i)) −Ap(1,2,i) * Ap(2,1,i);

450 ddet dmu = (−1+Ap(2,2,i)) * dAp(1,1) −Ap(2,1,i) * dAp(1,2) −...

451 Ap(1,2,i) * dAp(2,1)+(Ap(1,1) −1) * dAp(2,2);

452 derivInv = ...

1/(detˆ2) * [ −det * dAp(2,2) −(1 −Ap(2,2,i)) * ddet dmu, ...

453 det * dAp(1,2) −Ap(1,2,i) * ddet dmu;det * dAp(2,1) −Ap(2,1,i) * ddet dmu, ...

454 −det * dAp(1,1) −(1 −Ap(1,1,i)) * ddet dmu];

455 J(i,j) = ...

Mi(i,1:end) * (dAt * invA * Np(1:2,1:end,i)+At * invA * dNp+...

456 At * derivInv * Np(1:2,1:end,i)+dNt) * Zi arr(1:end,i);

457 end

458 end

459

460 dFCMdmu = zeros(length(FCM),length(FCM),6);

461 derivInv2 = zeros(3,3);

462 derivAp = zeros(3,3);

463

Page 178: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 172

464 for i = 1:6

465 dAp = dPhi dmu(1:3,1:3,i);

466

467 det = ...

(Ap mat(3,3) −1) * (Ap mat(1,1)+Ap mat(2,2) −Ap mat(1,1) * Ap mat(2,2)+ ...

468 Ap mat(1,2) * Ap mat(2,1) −1);

469 ddet = ...

dAp(3,3) * Ap mat(1,1)+Ap mat(3,3) * dAp(1,1)+dAp(3,3) * Ap mat(2,2)+ ...

470 Ap mat(3,3) * dAp(2,2) −dAp(3,3) * Ap mat(1,1) * Ap mat(2,2) −Ap mat(3,3) * ...

471 dAp(1,1) * Ap mat(2,2) −Ap mat(3,3) * Ap mat(1,1) * dAp(2,2)+dAp(3,3) * ...

472 Ap mat(1,2) * Ap mat(2,1)+Ap mat(3,3) * dAp(1,2) * Ap mat(2,1)+Ap mat(3,3) * ...

473 Ap mat(1,2) * dAp(2,1) −dAp(3,3) −dAp(1,1) −dAp(2,2)+dAp(1,1) * ...

474 Ap mat(2,2)+Ap mat(1,1) * dAp(2,2) −dAp(1,2) * Ap mat(2,1) −Ap mat(1,2) * ...

475 dAp(2,1);

476 Am11 = (Ap mat(3,3) −1) * (Ap mat(2,2) −1);

477 Am12 = −Ap mat(1,2) * (Ap mat(3,3) −1);

478 Am13 = ...

Ap mat(1,3)+Ap mat(1,2) * Ap mat(2,3) −Ap mat(1,3) * Ap mat(2,2);

479 Am21 = −Ap mat(2,1) * (Ap mat(3,3) −1);

480 Am22 = (Ap mat(1,1) −1) * (Ap mat(3,3) −1);

481 Am23 = ...

Ap mat(2,3) −Ap mat(1,1) * Ap mat(2,3)+Ap mat(1,3) * Ap mat(2,1);

482 Am33 = ...

−Ap mat(1,1) −Ap mat(2,2)+Ap mat(1,1) * Ap mat(2,2) −Ap mat(1,2) * ...

483 Ap mat(2,1)+1;

484 dAm11 = ...

dAp(3,3) * Ap mat(2,2)+Ap mat(3,3) * dAp(2,2) −dAp(3,3) −dAp(2,2);

485 dAm12 = −dAp(1,2) * Ap mat(3,3) −Ap mat(1,2) * dAp(3,3)+dAp(1,2);

486 dAm13 = ...

dAp(1,3)+dAp(1,2) * Ap mat(2,3)+Ap mat(1,2) * dAp(2,3) −dAp(1,3) * ...

487 Ap mat(2,2) −Ap mat(1,3) * dAp(2,2);

488 dAm21 = −dAp(2,1) * Ap mat(3,3) −Ap mat(2,1) * dAp(3,3)+dAp(2,1);

489 dAm22 = ...

dAp(1,1) * Ap mat(3,3)+Ap mat(1,1) * dAp(3,3) −dAp(1,1) −dAp(3,3);

490 dAm23 = ...

dAp(2,3) −dAp(1,1) * Ap mat(2,3) −Ap mat(1,1) * dAp(2,3)+dAp(1,3) * ...

491 Ap mat(2,1)+Ap mat(1,3) * dAp(2,1);

492 dAm33 = ...

−dAp(1,1) −dAp(2,2)+dAp(1,1) * Ap mat(2,2)+Ap mat(1,1) * dAp(2,2) ...

493 −dAp(1,2) * Ap mat(2,1) −Ap mat(1,2) * dAp(2,1);

494 Am = [Am11,Am12,Am13;Am21,Am22,Am23;0,0,Am33];

Page 179: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 173

495 dAm = [dAm11,dAm12,dAm13;dAm21,dAm22,dAm23;0,0,dAm33] ;

496

497 dInvA = 1/(det)ˆ2 * ( −1) * ddet * Am+1/det * dAm;

498 dFCMdmu(1:end,1:end,i) = ...

dPhi dmu(3+3 * lenHarm+1+1:end,1:3,i) * ...

499 (inv(eye(3,3) −Ap mat)) * Np mat+Hp* dInvA * Np mat+ ...

500 Hp* inv(eye(3,3) −Ap mat) * dPhi dmu(1:3,4:3 * lenHarm+4,i)+ ...

501 dPhi dmu(3 * lenHarm+5:end,4:4+3 * lenHarm,i);

502 Ctemp = dFCM dmu(1:end,1:end,i) * Zi arr(1:end,1);

503 Ctemp = Ctemp(2 * lenHarm+1);

504 J(7,i) = (Vdc+2 * Rdc* Idc) * Ctemp;

505 end

506

507 J(7,7) = dIdc dalpha * (Vdc+2 * Rdc* Idc);

508 %******************

509

510 M = zeros(7,1);

511 for i = 1:6

512 At = Mt arr(1:2,1:2,i);

513 Nt = Mt arr(1:2,4:end,i);

514 M(i) = ...

0−Mi(i,1:end) * (At * inv(ThetaM −Ap(1:2,1:2,i)) * Np(1:2,1:end,i)+Nt) * Zi arr(1:end

515 end

516 M(7) = Pload − (Idc * Vdc+Rdc* Idcˆ2);

517

518 new mu = mu + J\M;

519

520 flag2 = 0;

521 for i = 1:7

522 if abs(M(i)) > tolerance

523 flag2 = 1;

524 break ;

525 end

526 end

527

528 if flag2 == 0

529 break ;

530 end

531

532 mu = new mu;

533 alpha = new mu(7);

Page 180: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 174

534

535 if max(mu(1:6)) > pi/2

536 flag error = flag error +1;

537 else

538 flag error = 0;

539 end

540 if (flag error > 1)

541 error = 1;

542 break ;

543 end

544 flag2 = 0;

545 countIter = countIter + 1;

546 end

547

548 alpha = mu(7);

549 RotationMatrix2 = zeros(length(FCM));

550 count = 1;

551 for i = −h:1:h

552 RotationMatrix2(count:count+1,count:count+1) = ...

[cos( −i * (alpha −phase)), ...

553 −sin( −i * (alpha −phase));sin( −i * (alpha −phase)) ...

cos( −i * (alpha −phase))];

554 count = count + 2;

555 end

556 for i = 0:1:h

557 RotationMatrix2(count:count+1,count:count+1) = ...

[cos( −i * (alpha −phase)), ...

558 −sin( −i * (alpha −phase));sin( −i * (alpha −phase)) ...

cos( −i * (alpha −phase))];

559 count = count + 2;

560 end

561

562 tempM = eye(3 * lenHarm+1);

563 tempM(2 * lenHarm+3:end,2 * lenHarm+1:end) = ...

2* tempM(2 * lenHarm+3:end,2 * lenHarm+1:end);

564 I = tempM * RotationMatrix2 * I;

565 mu out = mu(1:6);

566

567 [Ia Ib Ic fundCurrents] = getI abc fundCurrents(I,h);

Page 181: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 175

B.2.3 Diode 6-Pulse Rectifier

solveDiode6.m

1 function [Ia Ib Ic fundCurrents phaseAng gamma mu Pload Rdc L Vdc] = ...

2 solveDiode6(Valphabeta,L,R,Rdc in,Ldc,h,Vdc in,P in,mu in,gamma in,phaseAng in)

3

4 global OpenDSSFileLoc

5

6 error = 1;

7 Vdc = Vdc in;

8 Rdc = Rdc in;

9 P = P in;

10 errorFile = fopen([OpenDSSFileLoc, 'errorFile.txt' ], 'w' );

11 if P in > 3

12 c = clock;

13 P = 3;

14 end

15 if P ≤ 0

16 c = clock;

17 Iphase = zeros(h,3);

18 for i = 1:h

19 Iphase(i,1) = i;

20 end

21 Iphase(1,2) = 100;

22 Ia = Iphase;

23 Ib = Iphase;

24 Ic = Iphase;

25 fundCurrents = [0,0;0, −120;0,+120];

26 phaseAng = 0;

27 mu = 0;

28 gamma = 0;

29 phaseAng = 0;

30 return ;

31 end

32

33 %Initializations

34 if mu in == −1

Page 182: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 176

35 Idc ref = ( −Vdc+sqrt(Vdc+4 * Rdc* P))/2/Rdc;

36 mu i = pi/9;

37 convergance = 0;

38

39 while (convergance == 0)

40 J = sqrt(3)/2/L * sin(mu i);

41 Idc avg = 1/2/L * ( −sqrt(3) * cos(mu i)+sqrt(3));

42

43 M = Idc ref −Idc avg;

44 if abs(M) < 0.01

45 break ;

46 end

47 mu i = mu i+inv(J) * M;

48 end

49

50 if mu i < 0 | | mu i > pi/6

51 mu i = pi/6;

52 end

53 mu prev = mu i * ones(6,1);

54 gammaprev = pi/3 * ones(6,1);

55 phaseAng prev = angle(Valphabeta(2 * h+3)+1i * Valphabeta(2 * h+4));

56 else

57 mu prev = mu in;

58 gammaprev = gamma in;

59 phaseAng prev = phaseAng in;

60 end

61 %************

62

63 Rdc = Rdc in;

64 center = 2 * h+1;

65 convergance = 0;

66

67 for i = 1:2:h

68 V = Valphabeta(center −i * 2:center+i * 2+1);

69 while (convergance == 0)

70 [Ia Ib Ic fundCurrents phaseAng gamma mu Pload error Vdc] = ...

71 solveDiode6Model(V,L,R,Rdc,Ldc,i,0,P,mu prev,gamma prev,phaseAng prev);

72

73 ratio = Pload/P;

74 if abs(1 −ratio) * 100 > 1.0001

75 c = clock;

Page 183: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 177

76 Rdc = Rdc* ratio;

77 elseif error == 1

78 L = L* 0.5;

79 else

80 convergance = 1;

81 end

82

83 if error == 0

84 mu prev = mu;

85 gammaprev = gamma;

86 phaseAng prev = phaseAng;

87 end

88

89 end

90 mu prev = mu;

91 gammaprev = gamma;

92 phaseAng prev = phaseAng;

93 convergance = 0;

94 end

solveDiode6Model.m

1 function [Ia Ib Ic fundCurrents phaseAng gamma mu Pload error Vdc] = ...

2 solveDiode6Model(Valphabeta,L,R,Rdc,Ldc,h,Vdc,Pdc,m u i,gamma i,phase i)

3

4 global SymMtx invSymMtx

5

6 %Initializations ***************************

7 countIter = 0;

8 w = 1; %line frequency in rad/s

9 Rout = Rdc;

10 Lout = Ldc;

11 tolerance = 0.0001;

12 f = w/2/pi;

13 Tac = 1/f;

14 Vout = Vdc;

15 lenHarm = 2 * h+1;

Page 184: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 178

16 Ra = R;

17 Rb = R;

18 Rc = R;

19 La = L;

20 Lb = L;

21 Lc = L;

22 error = 0;

23 flag error = 0;

24

25 V abc = SymMtx * [0;Valphabeta(lenHarm+2)+1i * Valphabeta(lenHarm+3); ...

26 Valphabeta(2 * h−1)+1i * Valphabeta(2 * h)];

27 Mag abc = [abs(V abc(1));abs(V abc(2));abs(V abc(3))];

28 Phase abc = [angle(V abc(1));angle(V abc(2));angle(V abc(3))];

29

30 CTF = 2/3 * [1 −1/2 −1/2;0 sqrt(3)/2 −sqrt(3)/2;1/sqrt(2) 1/sqrt(2) ...

1/sqrt(2)];

31 invCTF = inv(CTF);

32 invCTFsmall = invCTF(1:3,1:2);

33 arrPosArr = [1;2;3;1;2;3];

34

35 Mi = zeros(6,3);

36 Mi(2,1:end) = [1 0 0];

37 Mi(3,1:end) = −1* [ −1/2 −sqrt(3)/2 0];

38 Mi(1,1:end) = −1* [ −1/2 sqrt(3)/2 0];

39 Mi(5,1:end) = −1* [1 0 0];

40 Mi(6,1:end) = [ −1/2 −sqrt(3)/2 0];

41 Mi(4,1:end) = [ −1/2 sqrt(3)/2 0];

42 Mi gamma = [0 0 1];

43 %end initializations ************************

44

45 Vsabc phasor = zeros(3,1);

46 for i = 1:3

47 [x y] = pol2cart(Phase abc(i),Mag abc(i));

48 Vsabc phasor(i) = x + 1i * y;

49 end

50

51 temp = [1 −1 0;0 1 −1; −1 0 ...

1] * [Vsabc phasor(1);Vsabc phasor(2);Vsabc phasor(3)];

52

53 %Testing out new algorithm for switching times **********************

54 symMatrix = invSymMtx * Vsabc phasor;

Page 185: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 179

55

56 posSeq = symMatrix(2);

57

58 phaseAng = angle(posSeq) −0;

59 Ts = zeros(18,1);

60 Ts(1:end) = [1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6];

61

62 Zi = zeros(3 * lenHarm+1,1);

63

64 Zi(1:2 * lenHarm) = Valphabeta;

65 Zi(2 * lenHarm+1) = Vdc;

66

67 %Now that the Ts(1,1) and alpha are known and the input vector has been

68 %provided...we can use a rotation matrix to move the input ve ctor to ...

a time

69 %equal to Ts(1,1) + alpha

70 %Ts(* , * ) contains the swithing times and the 2 phase voltage ...

conduction for

71 %each conduction interval from 0 −> 2* pi

72 %An example: Ts(i,1) contains the next switching time, and T s(i,2) ...

contains

73 %the 2 phase voltage conduction for Ts(i −1,1) −−> Ts(i,1)

74

75 Acomm = zeros(3,3,6);

76 Acond = zeros(3,3,6);

77 Ncond = zeros(3,3 * lenHarm+1,6);

78 %Transition from Vab −> Vac

79 Acomm(1:2,1:end,1) = [ −(3/2 * R+Rout)/(3/2 * L+Lout),0,0; ...

80 0, −R/L,0];

81 Acomm(3,1:end,1) = [0,0, −(3/2 * R+Rout)/(3/2 * L+Lout)];

82 %Transition from Vca −> Vcb

83 Acomm(1:2,1:end,5) = ...

[1/(2 * L* L+4* (L+Lout) * L) * ( −2* L* R−3* (L+Lout) * R−L* (R+Rout)), ...

84 1/(2 * L* L+4* (L+Lout) * L) * (sqrt(3) * (L+Lout) * R−sqrt(3) * L* (R+Rout)),0; ...

85 1/(2 * sqrt(3) * L* L+4* sqrt(3) * L* (L+Lout)) * (3 * (L+Lout) * R−3* L* (R+Rout)), ...

86 1/(2 * sqrt(3) * L* L+4* sqrt(3) * L* (L+Lout)) * ( −2* sqrt(3) * L* R−sqrt(3) * (L+Lout) * R−3* sqrt(3)

87 Acomm(3,1:end,5) = [0,0, −(3/2 * R+Rout)/(3/2 * L+Lout)];

88 %Transition from Vbc −> Vba

89 Acomm(1:2,1:end,3) = ...

[ −(2 * L* R+3* (L+Lout) * R+L* (R+Rout))/(2 * L* L+4* (L+Lout) * L), ...

90 −(sqrt(3) * (L+Lout) * R−sqrt(3) * L* (R+Rout))/(2 * L* L+4* (L+Lout) * L),0; ...

Page 186: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 180

91 −(3 * (L+Lout) * R−3* L* (R+Rout))/(2 * sqrt(3) * L* L+4* sqrt(3) * (L+Lout) * L), ...

92 ( −2* sqrt(3) * L* R−sqrt(3) * (L+Lout) * R−sqrt(3) * 3* L* (R+Rout))/(2 * sqrt(3) * L* L+4* sqrt(3)

93 Acomm(3,1:end,3) = [0,0, −(3/2 * R+Rout)/(3/2 * L+Lout)];

94 %Transition from Vba −> Vca

95 Acomm(1:end,1:end,4) = Acomm(1:end,1:end,1);

96 %Transition from Vac −> Vbc

97 Acomm(1:end,1:end,2) = Acomm(1:end,1:end,5);

98 %Transition from Vcb −> Vab

99 Acomm(1:end,1:end,6) = Acomm(1:end,1:end,3);

100

101 %Now initializing the conduction A arrays

102

103 Acond(1:2,1:end,6) = [ −(Ra+Rb+Rout)/(La+Lb+Lout),0,0; ...

104 0, −(Ra+Rb+Rout)/(La+Lb+Lout),0];

105 Acond(3,1:end,6) = [0,0, −(Ra+Rb+Rout)/(La+Lb+Lout)];

106 Acond(1:2,1:end,2) = [ −(Ra+Rb+Rout)/(La+Lb+Lout),0,0; ...

107 0, −(Ra+Rb+Rout)/(La+Lb+Lout),0];

108 Acond(3,1:end,2) = [0,0, −(Rc+Rb+Rout)/(Lc+Lb+Lout)];

109 Acond(1:2,1:end,4) = [ −(Ra+Rb+Rout)/(La+Lb+Lout),0,0; ...

110 0, −(Ra+Rb+Rout)/(La+Lb+Lout),0];

111 Acond(3,1:end,4) = [0,0, −(Ra+Rc+Rout)/(La+Lc+Lout)];

112 Acond(1:end,1:end,1) = Acond(1:end,1:end,4);

113 Acond(1:end,1:end,3) = Acond(1:end,1:end,6);

114 Acond(1:end,1:end,5) = Acond(1:end,1:end,2);

115 %****************************************

116 coeffArr = zeros(3,3,6);

117 coeffArr(1,1,6) = 3/2/(La+Lb+Lout);

118 coeffArr(1,2,6) = −sqrt(3)/2/(La+Lb+Lout);

119 coeffArr(1,3,6) = −1/(La+Lb+Lout);

120 coeffArr(2,1,6) = −sqrt(3)/2/(La+Lb+Lout);

121 coeffArr(2,2,6) = 1/2/(La+Lb+Lout);

122 coeffArr(2,3,6) = 1/sqrt(3)/(La+Lb+Lout);

123 coeffArr(3,1,6) = 3/2/(La+Lb+Lout);

124 coeffArr(3,2,6) = −sqrt(3)/2/(La+Lb+Lout);

125 coeffArr(3,3,6) = −1/(La+Lb+Lout);

126 coeffArr(2,2,2) = 2/(Lb+Lc+Lout);

127 coeffArr(2,3,2) = −2/sqrt(3)/(Lb+Lc+Lout);

128 coeffArr(3,2,2) = sqrt(3)/(Lc+Lb+Lout);

129 coeffArr(3,3,2) = −1/(Lc+Lb+Lout);

130 coeffArr(1,1,4) = 3/2/(La+Lc+Lout);

131 coeffArr(1,2,4) = sqrt(3)/2/(Lc+La+Lout);

Page 187: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 181

132 coeffArr(1,3,4) = 1/(La+Lc+Lout);

133 coeffArr(2,1,4) = sqrt(3)/2/(La+Lc+Lout);

134 coeffArr(2,2,4) = 1/2/(La+Lc+Lout);

135 coeffArr(2,3,4) = 1/sqrt(3)/(La+Lc+Lout);

136 coeffArr(3,1,4) = −3/2/(La+Lc+Lout);

137 coeffArr(3,2,4) = −sqrt(3)/2/(La+Lc+Lout);

138 coeffArr(3,3,4) = −1/(La+Lb+Lout);

139 coeffArr(1:end,1:end,1) = coeffArr(1:end,1:end,4);

140 coeffArr(1:end,1:end,3) = coeffArr(1:end,1:end,6);

141 coeffArr(1:end,1:end,5) = coeffArr(1:end,1:end,2);

142 coeffArr(1:2,3,1) = coeffArr(1:2,3,1) *−1;

143 coeffArr(1:2,3,3) = coeffArr(1:2,3,3) *−1;

144 coeffArr(1:2,3,5) = coeffArr(1:2,3,5) *−1;

145 coeffArr(3,1,1) = coeffArr(3,1,1) *−1;

146 coeffArr(3,2,1) = coeffArr(3,2,1) *−1;

147 coeffArr(3,1,3) = coeffArr(3,1,3) *−1;

148 coeffArr(3,2,3) = coeffArr(3,2,3) *−1;

149 coeffArr(3,1,5) = coeffArr(3,1,5) *−1;

150 coeffArr(3,2,5) = coeffArr(3,2,5) *−1;

151 %****************************************

152

153 for j = 1:6

154 for i = 1:2:2 * lenHarm

155 Ncond(1:end,i:i+1,j) = coeffArr(1:end,1:2,j);

156 end

157 end

158 %****************************************

159 for j = 1:6

160 for i = 2 * lenHarm+1:2:2 * lenHarm+lenHarm+1

161 Ncond(1:end,i:i+1,j) = ...

[coeffArr(1,3,j),0;coeffArr(2,3,j),0;coeffArr(3,3,j ),0];

162 end

163 end

164 %****************************************

165

166 coeffArr comm = zeros(3,3,6);

167 Ncomm = zeros(3,3 * lenHarm+1,6);

168

169 coeffArr comm(1:end,1:end,1) = [3/2/(3/2 * L+Lout) 0 −1/(3/2 * L+Lout); ...

170 0 1/L 0;3/2/(3/2 * L+Lout) 0 −1/(3/2 *L+Lout)];

Page 188: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 182

171 coeffArr comm(1:end,1:end,5) = ...

[(3 * L+3* (L+Lout))/(2 * L* L+4* (L+Lout) * L), ...

172 −sqrt(3) * Lout/(2 * L* L+4* (L+Lout) * L),2 * L/(2 * L* L+4* (L+Lout) * L); ...

173 −3* Lout/(2 * sqrt(3) * L* L+4* sqrt(3) * (L+Lout) * L), ...

174 (5 * sqrt(3) * L+sqrt(3) * (L+Lout))/(2 * sqrt(3) * L* L+4* sqrt(3) * (L+Lout) * L), ...

175 6* L/(2 * sqrt(3) * L* L+4* sqrt(3) * (L+Lout) * L); −3/4/(3/2 * L+Lout), ...

176 −3* sqrt(3)/4/(3/2 * L+Lout), −1/(3/2 * L+Lout)];

177 coeffArr comm(1:end,1:end,3) = ...

[(3 * L+3* (L+Lout))/(2 * L* L+4* (L+Lout) * L), ...

178 sqrt(3) * Lout/(2 * L* L+4* (L+Lout) * L),2 * L/(2 * L* L+4* (L+Lout) * L); ...

179 (3 * (L+Lout) −3* L)/(2 * sqrt(3) * L* L+4* sqrt(3) * (L+Lout) * L), ...

180 (5 * sqrt(3) * L+sqrt(3) * (L+Lout))/(2 * sqrt(3) * L* L+4* sqrt(3) * (L+Lout) * L), ...

181 −6* L/(2 * sqrt(3) * L* L+4* sqrt(3) * (L+Lout) * L); −3/4/(3/2 * L+Lout), ...

182 3* sqrt(3)/4/(3/2 * L+Lout) −1/(3/2 * L+Lout)];

183 coeffArr comm(1:end,1:end,2) = coeffArr comm(1:end,1:end,5);

184 coeffArr comm(1:end,1:end,4) = coeffArr comm(1:end,1:end,1);

185 coeffArr comm(1:end,1:end,6) = coeffArr comm(1:end,1:end,3);

186 coeffArr comm(1:2,3,2) = coeffArr comm(1:2,3,2) *−1;

187 coeffArr comm(1:2,3,4) = coeffArr comm(1:2,3,4) *−1;

188 coeffArr comm(1:2,3,6) = coeffArr comm(1:2,3,6) *−1;

189 coeffArr comm(3,1:2,2) = coeffArr comm(3,1:2,2) *−1;

190 coeffArr comm(3,1:2,4) = coeffArr comm(3,1:2,4) *−1;

191 coeffArr comm(3,1:2,6) = coeffArr comm(3,1:2,6) *−1;

192

193 %****************************************

194 for j = 1:6

195 for i = 1:2:2 * lenHarm

196 Ncomm(1:end,i:i+1,j) = coeffArr comm(1:3,1:2,j);

197 end

198 end

199 %****************************************

200 %****************************************

201 for j = 1:6

202 for i = 2 * lenHarm+1:2:2 * lenHarm+lenHarm+1

203 Ncomm(1:end,i:i+1,j) = [coeffArr comm(1,3,j),0; ...

204 coeffArr comm(2,3,j),0;coeffArr comm(3,3,j),0];

205 end

206 end

207 %****************************************

208 mu = mui;

209 phaseAng = phase i;

Page 189: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 183

210 gamma = gammai;

211

212 %The following for loop calculates the ∆ mu(1)...mu(3) terms in the

213 %Jacobian matrix formulation.

214 At = zeros(3,3);

215 Nt = zeros(3,3 * lenHarm+1); %why is this 4

216 Omegat = zeros(3 * lenHarm+1,3 * lenHarm+1);

217

218 count = −h;

219 for i = 1:2:2 * lenHarm

220 Omegat(i:i+1,i:i+1) = [0 −count;count 0];

221 count = count + 1;

222 end

223 count = 0;

224 for i = 2 * lenHarm+1:2:2 * lenHarm+lenHarm

225 Omegat(i:i+1,i:i+1) = [0 −count;count 0];

226 count = count + 1;

227 end

228

229 H = zeros(3 * lenHarm+1,3);

230 Mm = Omegat;

231

232 count = 1;

233 for i = h: −1: −h

234 H(count:count+1,1:2) = 1/2/pi * [cos(i * 2* pi) ...

sin(i * 2* pi); −sin(i * 2* pi) cos(i * 2* pi)];

235 count = count + 2;

236 end

237

238 for i = count:2:count+2 * h+2−1

239 H(i,3) = 1/Tac;

240 end

241

242 Mcond = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1);

243 Mcomm = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1);

244 Mt arr = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1,6);

245 dMp dmu = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1,6,6); %3rd column ...

contains the partial

246 dMp dgamma = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1,6,6); %3rd column ...

contains the partial

247 Mp = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1,6);

Page 190: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 184

248 Ap = zeros(3,3,6);

249 Np = zeros(3,3 * lenHarm+1,6);

250 Omegap = zeros(3 * lenHarm+1,3 * lenHarm+1,6);

251

252 Ahat = zeros(3+3 * lenHarm+1+3 * lenHarm+1);

253

254 Ahat(3+3 * lenHarm+1+1:end,1:3) = H;

255 Ahat(4:3+3 * lenHarm+1,4:3+3 * lenHarm+1) = Omegat;

256 Ahat(3+3 * lenHarm+1+1:end,3+3 * lenHarm+1+1:end) = Mm;

257 phase init = phaseAng;

258

259 while (true)

260 RotationMatrix = zeros(3 * lenHarm+1,3 * lenHarm+1,7);

261 Zi arr = zeros(3 * lenHarm+1,7);

262 gammasum = 0;

263 for k = 1:7

264 count = 1;

265 for i = −h:1:h

266 RotationMatrix(count:count+1,count:count+1,k) = ...

267 [cos(i * (gamma sum−phaseAng)), −sin(i * (gamma sum−phaseAng)); ...

268 sin(i * (gamma sum−phaseAng)),cos(i * (gamma sum−phaseAng))];

269 count = count + 2;

270 end

271 for i = 0:h

272 RotationMatrix(count:count+1,count:count+1,k) = ...

273 [cos(i * (gamma sum−phaseAng)), −sin(i * (gamma sum−phaseAng)); ...

274 sin(i * (gamma sum−phaseAng)),cos(i * (gamma sum−phaseAng))];

275 count = count + 2;

276 end

277 if k < 7

278 gammasum = gammasum + gamma(k);

279 end

280 Zi arr(1:end,k) = RotationMatrix(1:end,1:end,k) * Zi;

281 end

282

283 for j = 1:6

284 Mp(1:end,1:end,j) = eye(length(Mp));

285 for k = 1:6

286 dMp dmu(1:end,1:end,j,k) = eye(3+3 * lenHarm+1);

287 dMp dgamma(1:end,1:end,j,k) = eye(3+3 * lenHarm+1);

288 end

Page 191: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 185

289 end

290

291 expmCommMu = zeros(length(Ahat),length(Ahat),6);

292 expmCondMu = zeros(length(Ahat),length(Ahat),6);

293 expmCondMuPi 3 = zeros(length(Ahat),length(Ahat),6);

294

295 Phi = eye(3+3 * lenHarm+1+3 * lenHarm+1);

296 for i = 1:6

297 Ahat(1:3,1:3+3 * lenHarm+1) = ...

[Acomm(1:end,1:end,i),Ncomm(1:end,1:end,i)];

298 expmCommMu(1:end,1:end,i) = expm(Ahat * mu(i));

299 Ahat(1:3,1:3+3 * lenHarm+1) = ...

[Acond(1:end,1:end,i),Ncond(1:end,1:end,i)];

300 expmCondMu(1:end,1:end,i) = expm( −Ahat * mu(i));

301 expmCondMuPi 3(1:end,1:end,i) = expm(Ahat * gamma(i));

302

303 Phi = expmCondMuPi 3(1:end,1:end,i) * ...

304 expmCondMu(1:end,1:end,i) * expmCommMu(1:end,1:end,i) * Phi;

305 end

306

307 maxPos = 3+3* lenHarm+1;

308

309 for i = 1:6

310 for j = 0:5

311 Mcond(1:3,1:3) = Acond(1:end,1:end,Ts(i+j));

312 Mcond(1:3,4:end) = Ncond(1:end,1:end,Ts(i+j));

313 Mcond(4:end,4:end) = Omegat;

314 Mcomm(1:3,1:3) = Acomm(1:end,1:end,Ts(i+j));

315 Mcomm(1:3,4:end) = Ncomm(1:end,1:end,Ts(i+j));

316 Mcomm(4:end,4:end) = Omegat;

317

318 Mp(1:end,1:end,i) = ...

expmCondMuPi 3(1:maxPos,1:maxPos,Ts(j+i)) * ...

319 expmCondMu(1:maxPos,1:maxPos,Ts(j+i)) * ...

320 expmCommMu(1:maxPos,1:maxPos,Ts(i+j)) * Mp(1:end,1:end,i);

321

322 for k = 1:6

323 if k == (j+1)

324 dMp dmu(1:end,1:end,k,i) = ...

325 expmCondMuPi 3(1:maxPos,1:maxPos,Ts(j+i)) * ...

326 (−Mcond* expmCondMu(1:maxPos,1:maxPos,Ts(i+j))+ ...

Page 192: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 186

327 expmCondMu(1:maxPos,1:maxPos,Ts(i+j)) * Mcomm)* ...

328 expmCommMu(1:maxPos,1:maxPos,Ts(i+j)) * ...

329 dMp dmu(1:end,1:end,k,i);

330

331 dMp dgamma(1:end,1:end,k,i) = Mcond * ...

332 expmCondMuPi 3(1:maxPos,1:maxPos,Ts(j+i)) * ...

333 expmCondMu(1:maxPos,1:maxPos,Ts(j+i)) * ...

334 expmCommMu(1:maxPos,1:maxPos,Ts(i+j)) * ...

335 dMp dgamma(1:end,1:end,k,i);

336 else

337 dMp dmu(1:end,1:end,k,i) = ...

338 expmCondMuPi 3(1:maxPos,1:maxPos,Ts(j+i)) * ...

339 expmCondMu(1:maxPos,1:maxPos,Ts(j+i)) * ...

340 expmCommMu(1:maxPos,1:maxPos,Ts(i+j)) * ...

341 dMp dmu(1:end,1:end,k,i);

342

343 dMp dgamma(1:end,1:end,k,i) = ...

344 expmCondMuPi 3(1:maxPos,1:maxPos,Ts(j+i)) * ...

345 expmCondMu(1:maxPos,1:maxPos,Ts(j+i)) * ...

346 expmCommMu(1:maxPos,1:maxPos,Ts(i+j)) * ...

347 dMp dgamma(1:end,1:end,k,i);

348 end

349 end

350 end

351 end

352

353 dMpgamma = zeros(length(Mp),length(Mp),6,6);

354 dMpmu = zeros(length(Mp),length(Mp),6,6);

355

356 for i = 0:5

357 for j = 1:6

358 dMpgamma(1:end,1:end,Ts(j+i),i+1) = ...

dMp dgamma(1:end,1:end,j,i+1);

359 dMpmu(1:end,1:end,Ts(j+i),i+1) = dMp dmu(1:end,1:end,j,i+1);

360 end

361 end

362

363 for i = 1:6

364 Ap(1:end,1:end,i) = Mp(1:3,1:3,i);

365 Np(1:end,1:end,i) = Mp(1:3,4:end,i);

366 Omegap(1:end,1:end,i) = Mp(4:end,4:end,i);

Page 193: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 187

367 end

368

369 derivMt = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1,6);

370

371 %This block calculates the derivative of the Mt matrix eleme nts.

372 for i = 1:6

373 Mcomm(1:3,1:3) = Acomm(1:end,1:end,i);

374 Mcomm(1:3,4:end) = Ncomm(1:end,1:end,i);

375 Mcomm(4:end,4:end) = Omegat;

376

377 Mt arr(1:end,1:end,i) = expmCommMu(1:maxPos,1:maxPos,i);

378 derivMt(1:end,1:end,i) = Mcomm * Mt arr(1:end,1:end,i);

379 end

380

381 %Derivation of FCM

382 Hp = Phi(4+3 * lenHarm+1:end,1:3);

383 Ap mat = Phi(1:3,1:3);

384 Np mat = Phi(1:3,4:3 * lenHarm+4);

385 Qp = Phi(3 * lenHarm+4+1:end,4:3 * lenHarm+4);

386 FCM = Hp* (inv(eye(3,3) −Ap mat)) * Np mat+Qp;

387 I = FCM* Zi arr(1:end,1);

388

389 derivRotation = zeros(length(FCM),length(FCM),7);

390 gammasum = 0;

391 for j = 1:7

392 count = 1;

393 for i = −h:1:h

394 derivRotation(count:count+1,count:count+1,j) = ...

[ −i * sin(i * (gamma sum−phaseAng)), ...

395 −i * cos(i * (gamma sum−phaseAng));i * cos(i * (gamma sum−phaseAng)) ...

−i * sin(i * (gamma sum−phaseAng))];

396 count = count + 2;

397 end

398 for i = 0:1:h

399 derivRotation(count:count+1,count:count+1,j) = ...

[ −i * sin(i * (gamma sum−phaseAng)), ...

400 −i * cos(i * (gamma sum−phaseAng));i * cos(i * (gamma sum−phaseAng)) ...

−i * sin(i * (gamma sum−phaseAng))];

401 count = count + 2;

402 end

403 if j < 7

Page 194: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 188

404 gammasum = gammasum + gamma(j);

405 end

406 end

407

408 Idc = I(2 * lenHarm+1);

409 if countIter == 0

410 Iinit = Idc;

411 end

412 Vdc = Zi(2 * lenHarm+1);

413

414 %**************************************************

415

416 J11 = zeros(6,6);

417 J12 = zeros(6,7);

418 J21 = zeros(7,6);

419 J22 = zeros(7,7);

420

421 M = zeros(13,1);

422 for i = 1:6

423 At = Mt arr(1:3,1:3,i);

424 Nt = Mt arr(1:3,4:end,i);

425 M(i) = 0 −Mi(i,1:end) * (At * inv(eye(3,3) −Ap(1:3,1:3,i)) * ...

426 Np(1:3,1:end,i)+Nt) * Zi arr(1:end,i);

427 end

428

429 Vabc coeff = zeros(6,2);

430 Vabc coeff(2,1:end) = [1 −L/(2 * L+Lout), −1,L/(2 * L+Lout)] * invCTFsmall;

431 Vabc coeff(3,1:end) = [1, −L/(2 * L+Lout), −1+L/(2 * L+Lout)] * invCTFsmall;

432 Vabc coeff(4,1:end) = [L/(2 * L+Lout),1 −L/(2 * L+Lout), −1] * invCTFsmall;

433 Vabc coeff(5,1:end) = [ −1+L/(2 * L+Lout),1, −L/(2 * L+Lout)] * invCTFsmall;

434 Vabc coeff(6,1:end) = [ −1,L/(2 * L+Lout),1 −L/(2 * L+Lout)] * invCTFsmall;

435 Vabc coeff(1,1:end) = [ −L/(2 * L+Lout), −1+L/(2 * L+Lout),1] * invCTFsmall;

436

437 constMtx = zeros(3,3 * lenHarm+1);

438 for i = 1:2

439 for j = i:2:2 * lenHarm

440 constMtx(i,j) = 1;

441 end

442 end

443 for i = 1:2:lenHarm+1

444 constMtx(3,2 * lenHarm+i) = 1;

Page 195: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 189

445 end

446

447 for i = 1:7

448 Idc temp = Mi gamma* (inv(eye(3,3) −Ap(1:3,1:3,Ts(i))) * ...

449 Np(1:3,1:end,Ts(i))) * Zi arr(1:end,i);

450

451 M(i+6) = 0 − ((L * Rout−R* Lout)/(2 * L+Ldc) * Idc temp+ ...

452 [Vabc coeff(Ts(i),1:end),L/(2 * L+Lout)] * constMtx * Zi arr(1:end,i));

453 end

454

455 %**************************

456 %Calculation of ...

J*************************************************** ***

457 for i = 1:6

458 for j = 1:6

459 %Entries in Quad. (1,1)

460 J11(i,j) = ...

calcJ11(lenHarm,Ap(1:end,1:end,i),Np(1:end,1:end,i) , ...

461 Mt arr(1:end,1:end,i),derivMt(1:end,1:end,i), ...

462 dMpmu(1:end,1:end,j,i),Zi arr(1:end,i),Mi(i,1:end),i −j);

463 if j < i

464 condMtx = derivRotation(1:end,1:end,i);

465 else

466 condMtx = zeros(3 * lenHarm+1,3 * lenHarm+1);

467 end

468 %Entries in Quad. (1,2)

469 J12(i,j) = calcJ12(Ap(1:end,1:end,i),Np(1:end,1:end,i ), ...

470 Mt arr(1:end,1:end,i),dMpgamma(1:end,1:end,j,i), ...

471 Zi arr(1:end,i),Zi,Mi(i,1:end),condMtx);

472 end

473 condMtx = derivRotation(1:end,1:end,i);

474 J12(i,7) = ...

calcJ13(Mt arr(1:end,1:end,i),Ap(1:end,1:end,i),Np(1:end,1:end ,i), ...

475 Zi,Mi(i,1:end),condMtx);

476 end

477 for i = 1:7

478 for j = 1:6

479 %Entries in Quad. (2,1)

480 J21(i,j) = ...

calcJ21(Ap(1:end,1:end,Ts(i)),Np(1:end,1:end,Ts(i)) , ... ...

%might be looking @wrong value??

Page 196: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 190

481 dMpmu(1:end,1:end,j,Ts(i)),Zi arr(1:end,i),L,R,Ldc,Rdc);

482 if j < i

483 condMtx = derivRotation(1:end,1:end,i);

484 else

485 condMtx = zeros(3 * lenHarm+1,3 * lenHarm+1);

486 end

487 J22(i,j) = ...

calcJ22(Ap(1:end,1:end,Ts(i)),Np(1:end,1:end,Ts(i)) , ...

488 dMpgamma(1:end,1:end,j,Ts(i)),Zi arr(1:end,i),Zi, ...

489 condMtx,[Vabc coeff(Ts(i),1:end),L/(2 * L+Lout)] * constMtx,L,R,Ldc,Rdc);

490 end

491 condMtx = derivRotation(1:end,1:end,i);

492 J22(i,7) = ...

calcJ23(Ap(1:end,1:end,Ts(i)),Np(1:end,1:end,Ts(i)) , ...

493 Zi,condMtx,[Vabc coeff(Ts(i),1:end),L/(2 * L+Lout)] * constMtx,L,R,Ldc,Rdc);

494 end

495

496 J = [J11,J12;J21,J22];

497 %*************************************************** *******************

498

499 constraintVar = [mu;gamma;phaseAng];

500 constraintVar = constraintVar + J \M;

501 mu = constraintVar(1:6);

502 gamma = constraintVar(7:12);

503 phaseAng = constraintVar(13);

504

505 flag2 = 0;

506 for i = 1:13

507 if abs(M(i)) > tolerance

508 flag2 = 1;

509 break ;

510 end

511 end

512

513 if flag2 == 0

514 break ;

515 end

516

517 if max(mu(1:6)) > pi/2 | | min(mu(1:6)) < 0

518 flag error = flag error +1;

519 if max(mu(1:6)) > pi | | min(mu(1:6)) < −pi/3

Page 197: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 191

520 flag error = 2;

521 end

522 else

523 flag error = 0;

524 end

525 if (flag error > 1)

526 error = 1;

527 break ;

528 end

529

530 countIter = countIter + 1;

531 end

532

533 for i = 1:6

534 if mu(i) < 0 | | mu(i) > gamma(i)

535 error = 1;

536 end

537 end

538 if error 6= 0

539 Idc = Iinit;

540 end

541

542 RotationMatrix2 = zeros(length(FCM));

543 count = 1;

544 for i = −h:1:h

545 RotationMatrix2(count:count+1,count:count+1) = ...

546 [cos( −i * (0 −phaseAng)), −sin( −i * (0 −phaseAng)); ...

547 sin( −i * (0 −phaseAng)),cos( −i * (0 −phaseAng))];

548 count = count + 2;

549 end

550 for i = 0:h

551 RotationMatrix2(count:count+1,count:count+1) = ...

552 [cos( −i * (0 −phaseAng)), −sin( −i * (0 −phaseAng)); ...

553 sin( −i * (0 −phaseAng)),cos( −i * (0 −phaseAng))];

554 count = count + 2;

555 end

556

557 tempM = eye(3 * lenHarm+1);

558 tempM(2 * lenHarm+3:end,2 * lenHarm+1:end) = ...

2* tempM(2 * lenHarm+3:end,2 * lenHarm+1:end);

559 I = tempM * RotationMatrix2 * I;

Page 198: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 192

560

561 Vdc = Rdc* Idc;

562 Pload = Idcˆ2 * Rdc;

563

564 [Ia Ib Ic fundCurrents] = getI abc fundCurrents(I,h);

calcJ11 6.m

1 function J11 entry = calcJ11 6(Ap,Np,Mt,dMt,dMp,Zi arr,Mi,imj)

2 global lenHarm

3

4 At = Mt(1:3,1:3);

5 if imj == 0

6 dAt = dMt(1:3,1:3);

7 dNt = dMt(1:3,4:end);

8 else

9 dAt = zeros(3,3);

10 dNt = zeros(3,3 * lenHarm+1);

11 end

12 dAp = dMp(1:3,1:3);

13 dNp = dMp(1:3,4:end);

14

15 dInvImMtx = get dInvImMtx 6(Ap,dAp);

16 InvImMtx = inv(eye(3) −Ap);

17

18 J11 entry = ...

Mi * (dAt * InvImMtx * Np+At * InvImMtx * dNp+At * dInvImMtx * Np+dNt) * Zi arr;

calcJ21 6.m

1 function J21 entry = calcJ21 6(Ap,Np,dMp,Zi arr,Mi)

2 global L R Rout Lout

3

Page 199: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 193

4 dAp = dMp(1:3,1:3);

5 dNp = dMp(1:3,4:end);

6

7 dInvImMtx = get dInvImMtx 6(Ap,dAp);

8 InvImMtx = inv(eye(3) −Ap);

9

10 J21 entry = (L * (2 * R+Rout)/(2 * L+Lout) −R)* Mi * (dInvImMtx * Np+InvImMtx * ...

11 dNp) * Zi arr;

calcJ12 6.m

1 function J12 entry = calcJ12 6(Ap,Np,Mt,dMp,Zi arr,Zi,Mi,dRotation)

2

3 At = Mt(1:3,1:3);

4 Nt = Mt(1:3,4:end);

5 dAp = dMp(1:3,1:3);

6 dNp = dMp(1:3,4:end);

7

8 dInvImMtx = get dInvImMtx 6(Ap,dAp);

9 InvImMtx = inv(eye(3) −Ap);

10

11 J12 entry = Mi * (At * InvImMtx * dNp+At * dInvImMtx * Np) * Zi arr+Mi * (At * ...

12 InvImMtx * Np+Nt) * dRotation * Zi;

calcJ22 6.m

1 function J22 entry = ...

calcJ22 6(Ap,Np,dMp,Zi arr,Zi,Mi,dRotation,constMtx)

2 global Lout Rout L R

3

4 dAp = dMp(1:3,1:3);

5 dNp = dMp(1:3,4:end);

6

Page 200: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 194

7 dInvImMtx = get dInvImMtx 6(Ap,dAp);

8 InvImMtx = inv(eye(3) −Ap);

9

10 J22 entry = (L * (2 * R+Rout)/(2 * L+Lout) −R)* Mi * ((dInvImMtx * Np+InvImMtx * ...

11 dNp) * Zi arr+InvImMtx * Np* dRotation * Zi)+constMtx * dRotation * Zi;

calcJ13 6.m

1 function J13 entry = calcJ13 6(Mt,Ap,Np,Zi,Mi,dRotation)

2

3 At = Mt(1:3,1:3);

4 Nt = Mt(1:3,4:end);

5 InvImMtx = inv(eye(3) −Ap);

6

7 J13 entry = Mi * (At * InvImMtx * Np+Nt) * ( −dRotation) * Zi;

calcJ23 6.m

1 function J23 entry = calcJ23 6(Ap,Np,Zi,Mi,dRotation,constMtx)

2 global Lout Rout L R

3

4 InvImMtx = inv(eye(3) −Ap);

5

6 J23 entry = ...

(L * (2 * R+Rout)/(2 * L+Lout) −R) * Mi * InvImMtx * Np* ( −dRotation) * Zi+ ...

7 constMtx * ( −dRotation) * Zi;

get dInvImMtx 6.m

1 function dInvImMtx = get dInvImMtx 6(Mtx,dMtx)

Page 201: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 195

2

3 det = (Mtx(3,3) −1) * (Mtx(1,1)+Mtx(2,2) −Mtx(1,1) * Mtx(2,2)+ ...

4 Mtx(1,2) * Mtx(2,1) −1);

5 ddet = dMtx(3,3) * Mtx(1,1)+Mtx(3,3) * dMtx(1,1)+dMtx(3,3) * Mtx(2,2)+ ...

6 Mtx(3,3) * dMtx(2,2) −dMtx(3,3) * Mtx(1,1) * Mtx(2,2) −Mtx(3,3) * ...

7 dMtx(1,1) * Mtx(2,2) −Mtx(3,3) * Mtx(1,1) * dMtx(2,2)+dMtx(3,3) * ...

8 Mtx(1,2) * Mtx(2,1)+Mtx(3,3) * dMtx(1,2) * Mtx(2,1)+Mtx(3,3) * ...

9 Mtx(1,2) * dMtx(2,1) −dMtx(3,3) −dMtx(1,1) −dMtx(2,2)+dMtx(1,1) * ...

10 Mtx(2,2)+Mtx(1,1) * dMtx(2,2) −dMtx(1,2) * Mtx(2,1) −Mtx(1,2) * ...

11 dMtx(2,1);

12 Am11 = (Mtx(3,3) −1) * (Mtx(2,2) −1);

13 Am12 = −Mtx(1,2) * (Mtx(3,3) −1);

14 Am13 = Mtx(1,3)+Mtx(1,2) * Mtx(2,3) −Mtx(1,3) * Mtx(2,2);

15 Am21 = −Mtx(2,1) * (Mtx(3,3) −1);

16 Am22 = (Mtx(1,1) −1) * (Mtx(3,3) −1);

17 Am23 = Mtx(2,3) −Mtx(1,1) * Mtx(2,3)+Mtx(1,3) * Mtx(2,1);

18 Am33 = −Mtx(1,1) −Mtx(2,2)+Mtx(1,1) * Mtx(2,2) −Mtx(1,2) * ...

19 Mtx(2,1)+1;

20 dAm11 = dMtx(3,3) * Mtx(2,2)+Mtx(3,3) * dMtx(2,2) −dMtx(3,3) −dMtx(2,2);

21 dAm12 = −dMtx(1,2) * Mtx(3,3) −Mtx(1,2) * dMtx(3,3)+dMtx(1,2);

22 dAm13 = dMtx(1,3)+dMtx(1,2) * Mtx(2,3)+Mtx(1,2) * dMtx(2,3) −dMtx(1,3) * ...

23 Mtx(2,2) −Mtx(1,3) * dMtx(2,2);

24 dAm21 = −dMtx(2,1) * Mtx(3,3) −Mtx(2,1) * dMtx(3,3)+dMtx(2,1);

25 dAm22 = dMtx(1,1) * Mtx(3,3)+Mtx(1,1) * dMtx(3,3) −dMtx(1,1) −dMtx(3,3);

26 dAm23 = dMtx(2,3) −dMtx(1,1) * Mtx(2,3) −Mtx(1,1) * dMtx(2,3)+dMtx(1,3) * ...

27 Mtx(2,1)+Mtx(1,3) * dMtx(2,1);

28 dAm33 = −dMtx(1,1) −dMtx(2,2)+dMtx(1,1) * Mtx(2,2)+Mtx(1,1) * dMtx(2,2) ...

29 −dMtx(1,2) * Mtx(2,1) −Mtx(1,2) * dMtx(2,1);

30 Am = [Am11,Am12,Am13;Am21,Am22,Am23;0,0,Am33];

31 dAm = [dAm11,dAm12,dAm13;dAm21,dAm22,dAm23;0,0,dAm33] ;

32

33 dInvImMtx = 1/(det)ˆ2 * ( −1) * ddet * Am+1/det * dAm;

B.2.4 Thyristor 12-Pulse Rectifier

solveThyristor12.m

Page 202: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 196

1 function [Ia,Ib,Ic,fundCurrents,alpha,mu] = ...

solveThyristor12(Valphabeta,L,R, ...

2 Rdc,Ldc,h,Vdc,P in)

3

4 global OpenDSSFileLoc

5

6 P = P in;

7 errorFile = fopen([OpenDSSFileLoc, 'errorFile.txt' ], 'w' );

8

9 if Vdc ≥ 3.34 | | Vdc ≤ 0

10 c = clock;

11 if Vdc ≥ 3.34

12 fprintf(errorFile, '%2.0fh:%2.0fm:%2.0fs 12 pulse thyristor ...

model will not conduct any current because Vdc pu > ...

3.34 \n' ,c(4),c(5),c(6));

13 else

14 fprintf(errorFile, '%2.0fh:%2.0fm:%2.0fs 12 pulse thyristor ...

model will not conduct any current Vdc pu must be > ...

0\n' ,c(4),c(5),c(6));

15 end

16 Iphase = zeros(h,3);

17

18 for i = 1:h

19 Iphase(i,1) = i;

20 end

21 Iphase(1,2) = 100;

22 Ia = Iphase;

23 Ib = Iphase;

24 Ic = Iphase;

25 fundCurrents = [0,0;0, −120;0,+120];

26 alpha = 0;

27 mu = zeros(12,1);

28 return ;

29 end

30

31 if P > 3 | | P < 0

32 c = clock;

33 Iphase = zeros(h,3);

34

35 for i = 1:h

36 Iphase(i,1) = i;

Page 203: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 197

37 end

38 Iphase(1,2) = 100;

39 Ia = Iphase;

40 Ib = Iphase;

41 Ic = Iphase;

42 fundCurrents = [0,0;0, −120;0,+120];

43 alpha = 0;

44 mu = zeros(12,1);

45 return ;

46 end

47

48 %Initializations

49 alpha i = 0;

50 alpha = alpha i;

51 mu = −100;

52 Vs mag = abs(Valphabeta(2 * h+3)+1i * Valphabeta(2 * h+4));

53

54 while (alpha > pi * 3/2 | | alpha < 0 | | mu < 0 | | mu > pi/3)

55 convergance = 0;

56 alpha i = alpha i+pi/3/100;

57 alpha = alpha i;

58 if alpha > pi * 3/2

59 c = clock;

60 Iphase = zeros(h,3);

61

62 for i = 1:h

63 Iphase(i,1) = i;

64 end

65 Iphase(1,2) = 100;

66 Ia = Iphase;

67 Ib = Iphase;

68 Ic = Iphase;

69 fundCurrents = [0,0;0, −120;0,+120];

70 alpha = 0;

71 mu = zeros(12,1);

72 return ;

73 end

74 while (convergance == 0)

75 checkVal = pi/3/sqrt(3) * Vdc/Vs mag−cos(alpha);

76 while (checkVal < −1 | | checkVal > 1)

77 alpha i = alpha i+pi/3/100;

Page 204: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 198

78 alpha = alpha i;

79 checkVal = pi/3/sqrt(3) * Vdc/Vs mag−cos(alpha);

80 if alpha > pi * 3/2

81 c = clock;

82 Iphase = zeros(h,3);

83

84 for i = 1:h

85 Iphase(i,1) = i;

86 end

87 Iphase(1,2) = 100;

88 Ia = Iphase;

89 Ib = Iphase;

90 Ic = Iphase;

91 fundCurrents = [0,0;0, −120;0,+120];

92 alpha = 0;

93 mu = zeros(12,1);

94 return ;

95 end

96 end

97 mu = acos(checkVal) −alpha;

98 Idc calc = ...

1/2/L * ( −sqrt(3) * cos(alpha+mu)+sqrt(3) * cos(alpha)) * Vs mag;

99

100 J = sqrt(3)/2/L * ( −sqrt(3) * sin(alpha) −sin(alpha)/ ...

101 sqrt(1 −(pi/3/sqrt(3) * Vdc/Vs mag−cos(alpha)))) * Vs mag;

102

103 M = P−Vdc* Idc calc;

104

105

106 if abs(M) < 0.00001

107 break ;

108 end

109

110 alpha = alpha+1/J * M;

111 end

112 end

113

114 mu prev = mu * ones(12,1);

115 alpha prev = alpha;

116

117 center = 2 * h+1;

Page 205: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 199

118 convergance = 0;

119 %****************

120

121 for i = 1:2:h

122 V = Valphabeta(center −i * 2:center+i * 2+1);

123 while (convergance == 0)

124 [Ia Ib Ic fundCurrents alpha mu] = ...

125 solveThyristor12Model(V,L,R,Rdc,Ldc,i,0,P,mu prev,alpha prev);

126

127 convergance = 1;

128

129 mu prev = mu;

130 alpha prev = alpha;

131

132 end

133 convergance = 0;

134 end

solveThyristor12Model.m

1 function [Ia,Ib,Ic,fundCurrents,alpha,mu out] = ...

solveThyristor12Model(Valphabeta,L,R, ...

2 Rdc,Ldc,h,Vdc,P,mu in,alpha in)

3

4 global f Mag abc Idc Ts w phase SymMtx invSymMtx

5

6 %Initializations ***************************

7 A = SymMtx;

8 invA = invSymMtx;

9 iterAdd = 0.001;

10 delPhase = 30 * pi/180;

11 countIter = 1;

12 error = 0;

13 flag error = 0;

14 w = 1;

15 tolerance = 0.001;

16 f = w/2/pi;

Page 206: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 200

17 Tac = 1/f;

18 lenHarm = 2 * h+1;

19 Vout = Vdc;

20 Pload = P;

21

22 V abc = SymMtx * [0;Valphabeta(lenHarm+2)+1i * Valphabeta(lenHarm+3); ...

23 Valphabeta(2 * h−1)+1i * Valphabeta(2 * h)];

24 Mag abc = [abs(V abc(1));abs(V abc(2));abs(V abc(3))];

25 Phase abc = [angle(V abc(1));angle(V abc(2));angle(V abc(3))];

26

27 CTF = 2/3 * [1 −1/2 −1/2;0 sqrt(3)/2 −sqrt(3)/2;1/sqrt(2) 1/sqrt(2) ...

1/sqrt(2)];

28 CTFsmall = CTF(1:2,1:3);

29 invCTF = inv(CTF);

30 invCTFsmall = invCTF(1:3,1:2);

31

32 Mi = zeros(12,3);

33 for i = 0:1

34 Mi(1+i,1:end) = [( −2* i+1) * [0 sqrt(3) 0] * invCTFsmall 1];

35 Mi(3+i,1:end) = [( −2* i+1) * [ −sqrt(3) 0 0] * invCTFsmall 1];

36 Mi(5+i,1:end) = [( −2* i+1) * [0 0 sqrt(3)] * invCTFsmall 1];

37 Mi(7+i,1:end) = [( −2* i+1) * [0 −sqrt(3) 0] * invCTFsmall 1];

38 Mi(9+i,1:end) = [( −2* i+1) * [sqrt(3) 0 0] * invCTFsmall 1];

39 Mi(11+i,1:end) = [( −2* i+1) * [0 0 −sqrt(3)] * invCTFsmall 1];

40 end

41 Mi deriv = zeros(12,3);

42 for i = 0:1

43 Mi deriv(1+i,1:end) = [( −2* i+1) * [0 −sqrt(3) 0] * invCTFsmall 0];

44 Mi deriv(3+i,1:end) = [( −2* i+1) * [sqrt(3) 0 0] * invCTFsmall 0];

45 Mi deriv(5+i,1:end) = [( −2* i+1) * [0 0 −sqrt(3)] * invCTFsmall 0];

46 Mi deriv(7+i,1:end) = [( −2* i+1) * [0 sqrt(3) 0] * invCTFsmall 0];

47 Mi deriv(9+i,1:end) = [( −2* i+1) * [ −sqrt(3) 0 0] * invCTFsmall 0];

48 Mi deriv(11+i,1:end) = [( −2* i+1) * [0 0 sqrt(3)] * invCTFsmall 0];

49 end

50 %end initializations ************************

51

52 Vsabc phasor = zeros(3,1);

53 for i = 1:3

54 [x y] = pol2cart(Phase abc(i),Mag abc(i));

55 Vsabc phasor(i) = x + 1i * y;

56 end

Page 207: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 201

57

58 temp = [1 −1 0;0 1 −1; −1 0 ...

1] * [Vsabc phasor(1);Vsabc phasor(2);Vsabc phasor(3)];

59

60 symMatrix = invA * Vsabc phasor;

61

62 posSeq = symMatrix(2);

63 negSeq = symMatrix(3);

64

65 phase = angle(posSeq) −0;

66 Ts = zeros(36,1);

67 Ts(1:end) = [1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7 ,8,9,10,11,12, ...

68 1,2,3,4,5,6,7,8,9,10,11,12];

69

70 count = 1;

71 Zi = zeros(3 * lenHarm+1,1);

72 Zi(1:2 * lenHarm,1) = Valphabeta;

73 Zi(2 * lenHarm+1) = Vdc;

74 %*************************************************** ***********************

75

76 %Now that the Ts(1,1) and alpha are known and the input vector has been

77 %provided...we can use a rotation matrix to move the input ve ctor to ...

a time

78 %equal to Ts(1,1) + alpha

79 %Ts(* , * ) contains the swithing times and the 2 phase voltage ...

conduction for

80 %each conduction interval from 0 −> 2* pi

81 %An example: Ts(i,1) contains the next switching time, and T s(i,2) ...

contains

82 %the 2 phase voltage conduction for Ts(i −1,1) −−> Ts(i,1)

83

84 Ncond coeff = zeros(3,3,12);

85 Acond = zeros(3,3,12);

86

87 Acond(3,3,1:end) = ones(1,1,12) *−(4 * R+Rdc)/(4 * L+Ldc);

88 Ncond coeff(3,3,1:end) = ones(1,1,12) *−1/(4 * L+Ldc);

89

90 Acond coeff 1 = [1+2/sqrt(3); −1/sqrt(3); −1−1/sqrt(3)];

91 Acond coeff 2 = [1+1/sqrt(3);1/sqrt(3); −1−2/sqrt(3)];

92 Acond coeff 3 = [1/sqrt(3);1+1/sqrt(3); −1−2/sqrt(3)];

93 Acond coeff 4 = [ −1/sqrt(3);1+2/sqrt(3); −1−1/sqrt(3)];

Page 208: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 202

94 Acond coeff 5 = [ −1−1/sqrt(3);1+2/sqrt(3); −1/sqrt(3)];

95 Acond coeff 6 = [ −1−2/sqrt(3);1+1/sqrt(3);1/sqrt(3)];

96 Acond coeff 7 = [ −1−2/sqrt(3);1/sqrt(3);1+1/sqrt(3)];

97 Acond coeff 8 = [ −1−1/sqrt(3); −1/sqrt(3);1+2/sqrt(3)];

98 Acond coeff 9 = [ −1/sqrt(3); −1−1/sqrt(3);1+2/sqrt(3)];

99 Acond coeff 10 = [1/sqrt(3); −1−2/sqrt(3);1+1/sqrt(3)];

100 Acond coeff 11 = [1+1/sqrt(3); −1−2/sqrt(3);1/sqrt(3)];

101 Acond coeff 12 = [1+2/sqrt(3); −1−1/sqrt(3); −1/sqrt(3)];

102

103 Acond coeff = ...

[Acond coeff 1,Acond coeff 2,Acond coeff 3,Acond coeff 4, ...

104 Acond coeff 5,Acond coeff 6,Acond coeff 7,Acond coeff 8, ...

105 Acond coeff 9,Acond coeff 10,Acond coeff 11,Acond coeff 12];

106

107 Ncond coeff 2 1 = [1+sqrt(3),0, −1];

108 Ncond coeff 2 2 = [1,0, −1−sqrt(3)];

109 Ncond coeff 2 3 = [0,1, −1−sqrt(3)];

110 Ncond coeff 2 4 = [0,1+sqrt(3), −1];

111 Ncond coeff 2 5 = [ −1,1+sqrt(3),0];

112 Ncond coeff 2 6 = [ −1−sqrt(3),1,0];

113 Ncond coeff 2 7 = [ −1−sqrt(3),0,1];

114 Ncond coeff 2 8 = [ −1,0,1+sqrt(3)];

115 Ncond coeff 2 9 = [0, −1,1+sqrt(3)];

116 Ncond coeff 2 10 = [0, −1−sqrt(3),1];

117 Ncond coeff 2 11 = [1, −1−sqrt(3),0];

118 Ncond coeff 2 12 = [1+sqrt(3), −1,0];

119

120 Ncond coeff 2 = [Ncond coeff 2 1;Ncond coeff 2 2;Ncond coeff 2 3; ...

121 Ncond coeff 2 4;Ncond coeff 2 5;Ncond coeff 2 6;Ncond coeff 2 7; ...

122 Ncond coeff 2 8;Ncond coeff 2 9;Ncond coeff 2 10;Ncond coeff 2 11; ...

123 Ncond coeff 2 12];

124

125 for i = 1:12

126 Acond(1:2,3,i) = CTFsmall * Acond coeff(1:end,i) * Acond(3,3,i);

127 Ncond coeff(1:2,3,i) = ...

CTFsmall * Acond coeff(1:end,i) * Ncond coeff(3,3,i);

128 Ncond coeff(3,1:2,i) = ...

1/(4 * L+Ldc) * Ncond coeff 2(i,1:end) * invCTFsmall;

129 Ncond coeff(1:2,1:2,i) = ...

CTFsmall * Acond coeff(1:end,i) * Ncond coeff(3,1:2,i);

130 end

Page 209: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 203

131

132 Acomm = zeros(3,3,12);

133 Ncommcoeff = zeros(3,3,12);

134

135 Acomm(3,3,1:end)= ones(1,1,12) *−(7/2 * R+Rdc)/(7/2 * L+Ldc);

136 Ncommcoeff(3,3,1:end) = ones(1,1,12) *−1/(7/2 * L+Ldc);

137

138 Acommcoeff 1 1 = [1+2/sqrt(3); −1/2 −1/sqrt(3); −1/2 −1/sqrt(3)];

139 Acommcoeff 1 2 = [1+sqrt(3)/2; 0; −1−sqrt(3)/2];

140 Acommcoeff 1 3 = [1/2+1/sqrt(3); 1/2+1/sqrt(3); −1−2/sqrt(3)];

141 Acommcoeff 1 4 = [0; 1+sqrt(3)/2; −1−sqrt(3)/2];

142 Acommcoeff 1 5 = [ −1/2 −1/sqrt(3); 1+2/sqrt(3); −1/2 −1/sqrt(3)];

143 Acommcoeff 1 6 = [ −1−sqrt(3)/2; 1+sqrt(3)/2; 0];

144 Acommcoeff 1 7 = [ −1−2/sqrt(3); 1/2+1/sqrt(3); 1/2+1/sqrt(3)];

145 Acommcoeff 1 8 = [ −1−sqrt(3)/2; 0; 1+sqrt(3)/2];

146 Acommcoeff 1 9 = [ −1/2 −1/sqrt(3); −1/2 −1/sqrt(3); 1+2/sqrt(3)];

147 Acommcoeff 1 10 = [0; −1−sqrt(3)/2; 1+sqrt(3)/2];

148 Acommcoeff 1 11 = [1/2+1/sqrt(3); −1−2/sqrt(3); 1/2+1/sqrt(3)];

149 Acommcoeff 1 12 = [1+sqrt(3)/2; −1−sqrt(3)/2; 0];

150 Acommcoeff = [Acomm coeff 1 1,Acomm coeff 1 2,Acomm coeff 1 3, ...

151 Acommcoeff 1 4,Acomm coeff 1 5,Acomm coeff 1 6,Acomm coeff 1 7, ...

152 Acommcoeff 1 8,Acomm coeff 1 9,Acomm coeff 1 10,Acomm coeff 1 11, ...

153 Acommcoeff 1 12];

154

155 Acommcoeff 2 1 = [ 0; 1/2+1/sqrt(3); 1/2+1/sqrt(3)];

156 Acommcoeff 2 2 = [ −1/3 −1/2/sqrt(3); 0; 1/3+1/2/sqrt(3)];

157 Acommcoeff 2 3 = −[ 1/2+1/sqrt(3); 1/2+1/sqrt(3); 0];

158 Acommcoeff 2 4 = [ 0; −1/3 −1/2/sqrt(3); 1/3+1/2/sqrt(3)];

159 Acommcoeff 2 5 = [ 1/2+1/sqrt(3); 0; 1/2+1/sqrt(3)];

160 Acommcoeff 2 6 = [ 1/3+1/2/sqrt(3); −1/3 −1/2/sqrt(3); 0];

161 Acommcoeff 2 7 = −[ 0; 1/2+1/sqrt(3); 1/2+1/sqrt(3)];

162 Acommcoeff 2 8 = [ 1/3+1/2/sqrt(3); 0; −1/3 −1/2/sqrt(3)];

163 Acommcoeff 2 9 = [ 1/2+1/sqrt(3); 1/2+1/sqrt(3); 0];

164 Acommcoeff 2 10 = [ 0; 1/3+1/2/sqrt(3); −1/3 −1/2/sqrt(3)];

165 Acommcoeff 2 11 = −[ 1/2+1/sqrt(3); 0; 1/2+1/sqrt(3)];

166 Acommcoeff 2 12 = [ −1/3 −1/2/sqrt(3); 1/3+1/2/sqrt(3); 0];

167 Acommcoeff 2 = ...

−R/L * [Acomm coeff 2 1,Acomm coeff 2 2,Acomm coeff 2 3, ...

168 Acommcoeff 2 4,Acomm coeff 2 5,Acomm coeff 2 6,Acomm coeff 2 7, ...

169 Acommcoeff 2 8,Acomm coeff 2 9,Acomm coeff 2 10,Acomm coeff 2 11, ...

170 Acommcoeff 2 12];

Page 210: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 204

171

172 Acommcoeff 3 = zeros(3,3,12);

173 Acommcoeff 3(1:end,1:end,1) = R/L * [ 0,0,0; 0, −1,0; 0,0, −1];

174 Acommcoeff 3(1:end,1:end,2) = R/L * [ −1/3 1/3 0; 1/3 −2/3 1/3; 0 1/3 ...

−1/3];

175 Acommcoeff 3(1:end,1:end,3) = R/L * [ −1 0 0; 0 −1 0; 0 0 0];

176 Acommcoeff 3(1:end,1:end,4) = R/L * [ −2/3 1/3 1/3; 1/3 −1/3 0; 1/3 0 ...

−1/3];

177 Acommcoeff 3(1:end,1:end,5) = R/L * [ −1 0 0; 0 0 0; 0 0 −1];

178 Acommcoeff 3(1:end,1:end,6) = R/L * [ −1/3 0 1/3; 0 −1/3 1/3; 1/3 1/3 ...

−2/3];

179 Acommcoeff 3(1:end,1:end,7) = R/L * [ 0 0 0; 0 −1 0; 0 0 −1];

180 Acommcoeff 3(1:end,1:end,8) = R/L * [ −1/3 1/3 0; 1/3 −2/3 1/3; 0 1/3 ...

−1/3];

181 Acommcoeff 3(1:end,1:end,9) = R/L * [ −1 0 0; 0 −1 0; 0 0 0];

182 Acommcoeff 3(1:end,1:end,10) = R/L * [ −2/3 1/3 1/3; 1/3 −1/3 0; 1/3 ...

0 −1/3];

183 Acommcoeff 3(1:end,1:end,11) = R/L * [ −1 0 0; 0 0 0; 0 0 −1];

184 Acommcoeff 3(1:end,1:end,12) = R/L * [ −1/3 0 1/3; 0 −1/3 1/3; 1/3 ...

1/3 −2/3];

185

186 Ncommcoeff 2 1 = [ 1+sqrt(3), −1/2, −1/2];

187 Ncommcoeff 2 2 = [ 1+sqrt(3), sqrt(3)/2, −1];

188 Ncommcoeff 2 3 = [ 1/2, 1/2, −sqrt(3) −1];

189 Ncommcoeff 2 4 = [ sqrt(3)/2, 1+sqrt(3), −1];

190 Ncommcoeff 2 5 = [ −1/2, 1+sqrt(3), −1/2];

191 Ncommcoeff 2 6 = [ −1, 1+sqrt(3), sqrt(3)/2];

192 Ncommcoeff 2 7 = [ −1−sqrt(3), 1/2, 1/2];

193 Ncommcoeff 2 8 = [ −1, sqrt(3)/2, 1+sqrt(3)];

194 Ncommcoeff 2 9 = [ −1/2, −1/2, sqrt(3)+1];

195 Ncommcoeff 2 10 = [ sqrt(3)/2, −1, 1+sqrt(3)];

196 Ncommcoeff 2 11 = [ 1/2, −1−sqrt(3), 1/2];

197 Ncommcoeff 2 12 = [ 1+sqrt(3), −1, sqrt(3)/2];

198 Ncommcoeff 2 = [Ncomm coeff 2 1;Ncomm coeff 2 2;Ncomm coeff 2 3; ...

199 Ncommcoeff 2 4;Ncomm coeff 2 5;Ncomm coeff 2 6;Ncomm coeff 2 7; ...

200 Ncommcoeff 2 8;Ncomm coeff 2 9;Ncomm coeff 2 10;Ncomm coeff 2 11; ...

201 Ncommcoeff 2 12];

202

203 Ncommcoeff 3 = zeros(3,3,12);

204 Ncommcoeff 3(1:end,1:end,1) = [ 0, 0, 0; 0, 1/2, −1/2; 0, −1/2, 1/2];

205 Ncommcoeff 3(1:end,1:end,2) = [ 0, −1/2, 0; 0, 1, 0; 0, −1/2, 0];

Page 211: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 205

206 Ncommcoeff 3(1:end,1:end,3) = [ 1/2, −1/2, 0; −1/2, 1/2, 0; 0, 0, 0];

207 Ncommcoeff 3(1:end,1:end,4) = [ 1, 0, 0; −1/2, 0, 0; −1/2, 0, 0];

208 Ncommcoeff 3(1:end,1:end,5) = [ 1/2, 0, −1/2; 0, 0, 0; −1/2, 0, 1/2];

209 Ncommcoeff 3(1:end,1:end,6) = [ 0, 0, −1/2; 0, 0, −1/2; 0, 0, 1];

210 Ncommcoeff 3(1:end,1:end,7) = [ 0, 0, 0; 0, 1/2, −1/2; 0, −1/2, 1/2];

211 Ncommcoeff 3(1:end,1:end,8) = [ 0, −1/2, 0; 0, 1, 0; 0, −1/2, 0];

212 Ncommcoeff 3(1:end,1:end,9) = [ 1/2, −1/2, 0; −1/2, 1/2, 0; 0, 0, 0];

213 Ncommcoeff 3(1:end,1:end,10) = [ 1, 0, 0; −1/2, 0, 0; −1/2, 0, 0];

214 Ncommcoeff 3(1:end,1:end,11) = [ 1/2, 0, −1/2; 0, 0, 0; −1/2, 0, 1/2];

215 Ncommcoeff 3(1:end,1:end,12) = [ 0, 0, −1/2; 0, 0, −1/2; 0, 0, 1];

216

217 for i = 1:12

218 Ncommcoeff(3,1:2,i) = ...

1/(7/2 * L+Ldc) * Ncommcoeff 2(i,1:end) * invCTFsmall;

219 Acomm(1:2,3,i) = CTFsmall * Acommcoeff(1:end,i) * Acomm(3,3,i)+ ...

220 CTFsmall * Acommcoeff 2(1:end,i);

221 Acomm(1:2,1:2,i) = CTFsmall * Acommcoeff 3(1:end,1:end,i) * invCTFsmall;

222 Ncommcoeff(1:2,1:2,i) = ...

1/L * CTFsmall * Ncommcoeff 3(1:end,1:end,i) * ...

223 invCTFsmall+CTFsmall * Acommcoeff(1:end,i) * Ncommcoeff(3,1:2,i);

224 Ncommcoeff(1:2,3,i) = ...

CTFsmall * Acommcoeff(1:end,i) * Ncommcoeff(3,3,i);

225 end

226

227 %*************************************************** ***********************

228 Ncond = zeros(3,2 * lenHarm+2 * h+2,12);

229 for j = 1:12

230 for i = 1:2:2 * lenHarm

231 Ncond(1:end,i:i+1,j) = Ncond coeff(1:end,1:2,j);

232 end

233 end

234 %****************************************

235 for j = 1:12

236 for i = 2 * lenHarm+1:2:2 * lenHarm+lenHarm+1

237 Ncond(1:end,i:i+1,j) = [Ncond coeff(1:end,3,j),zeros(3,1)];

238 end

239 end

240 %****************************************

241

242 Ncomm = zeros(3,3 * lenHarm+1,12);

243

Page 212: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 206

244 %****************************************

245 for j = 1:12

246 for i = 1:2:2 * lenHarm

247 Ncomm(1:end,i:i+1,j) = Ncomm coeff(1:end,1:2,j);

248 end

249 end

250 %****************************************

251 %****************************************

252 for j = 1:12

253 for i = 2 * lenHarm+1:2:2 * lenHarm+lenHarm+1

254 Ncomm(1:end,i:i+1,j) = [Ncomm coeff(1:end,3,j),zeros(3,1)];

255 end

256 end

257 %****************************************

258 mu = ones(13,1);

259 mu(1:12) = mu in;

260 mu(13) = alpha in;

261 alpha = alpha in;

262 new mu = zeros(13,1);

263 At = zeros(3,3);

264 Nt = zeros(3,3 * lenHarm+1);

265 Omegat = zeros(3 * lenHarm+1,3 * lenHarm+1);

266 ThetaM = eye(3);

267

268 count = −h;

269 for i = 1:2:2 * lenHarm

270 Omegat(i:i+1,i:i+1) = [0 −count;count 0];

271 count = count + 1;

272 end

273 count = 0;

274 for i = 2 * lenHarm+1:2:2 * lenHarm+lenHarm

275 Omegat(i:i+1,i:i+1) = [0 −count;count 0];

276 count = count + 1;

277 end

278 Mcond = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1);

279 Mcomm = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1);

280 Mt arr = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1,12);

281 derivMp = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1,12,12);

282 Mp = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1,12);

283 Ap = zeros(3,3,12);

284 Np = zeros(3,3 * lenHarm+1,12);

Page 213: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 207

285 Omegap = zeros(3 * lenHarm+1,3 * lenHarm+1,12);

286

287 Ahat = zeros(3+3 * lenHarm+1+3 * lenHarm+1);

288

289 H = zeros(3 * lenHarm+1,3);

290 Mm = Omegat;

291

292 count = 1;

293 for i = h: −1: −h

294 H(count:count+1,1:2) = 1/2/pi * [cos(2 * i * pi) ...

sin(2 * i * pi); −sin(2 * i * pi) cos(2 * i * pi)]; %this COULD be wrong, ...

not sure though.

295 count = count + 2;

296 end

297

298 for i = count:2:count+2 * h+2−1

299 H(i,3) = 1/Tac;

300 end

301

302 Ahat(3+3 * lenHarm+1+1:end,1:3) = H;

303 Ahat(4:3+3 * lenHarm+1,4:3+3 * lenHarm+1) = Omegat;

304 Ahat(3+3 * lenHarm+1+1:end,3+3 * lenHarm+1+1:end) = Mm;

305

306 while (true)

307 RotationMatrix = zeros(3 * lenHarm+1,3 * lenHarm+1,12);

308 Zi arr = zeros(3 * lenHarm+1,12);

309 for k = 0:1:11

310 count = 1;

311 for i = −h:1:h

312 RotationMatrix(count:count+1,count:count+1,k+1) = ...

313 [cos(i * (k * pi/6+alpha −phase)), ...

314 −sin(i * (k * pi/6+alpha −phase)); ...

315 sin(i * (k * pi/6+alpha −phase)), ...

316 cos(i * (k * pi/6+alpha −phase))];

317 count = count + 2;

318 end

319 for i = 0:h

320 RotationMatrix(count:count+1,count:count+1,k+1) = ...

321 [cos(i * (k * pi/6+alpha −phase)), ...

322 −sin(i * (k * pi/6+alpha −phase)); ...

323 sin(i * (k * pi/6+alpha −phase)), ...

Page 214: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 208

324 cos(i * (k * pi/6+alpha −phase))];

325 count = count + 2;

326 end

327 Zi arr(1:end,k+1) = RotationMatrix(1:end,1:end,k+1) * Zi;

328 end

329 for j = 1:12

330 Mp(1:end,1:end,j) = eye(length(Mp));

331 for k = 1:12

332 derivMp(1:end,1:end,j,k) = ...

eye(length(derivMp)); %zeros(length(derivMp));%

333 end

334 end

335

336 expmCommMu = zeros(length(Ahat),length(Ahat),12);

337 expmCondMu = zeros(length(Ahat),length(Ahat),12);

338 expmCondMuPi 3 = zeros(length(Ahat),length(Ahat),12);

339

340 Phi = eye(3+3 * lenHarm+1+3 * lenHarm+1);

341 for i = 1:12

342 Ahat(1:3,1:3+3 * lenHarm+1) = ...

[Acomm(1:end,1:end,i),Ncomm(1:end,1:end,i)];

343 expmCommMu(1:end,1:end,i) = expm(Ahat * mu(i));

344 Ahat(1:3,1:3+3 * lenHarm+1) = ...

[Acond(1:end,1:end,i),Ncond(1:end,1:end,i)];

345 expmCondMu(1:end,1:end,i) = expm( −Ahat * mu(i));

346 expmCondMuPi 3(1:end,1:end,i) = expm(Ahat * pi/6);

347

348 Phi = expmCondMuPi 3(1:end,1:end,i) * ...

349 expmCondMu(1:end,1:end,i) * expmCommMu(1:end,1:end,i) * Phi;

350 end

351

352 maxPos = 3+3* lenHarm+1;

353

354 for i = 0:11

355 for j = 1:12

356 Mcond(1:3,1:3) = Acond(1:end,1:end,Ts(i+j));

357 Mcond(1:3,4:end) = Ncond(1:end,1:end,Ts(i+j));

358 Mcond(4:end,4:end) = Omegat;

359 Mcomm(1:3,1:3) = Acomm(1:end,1:end,Ts(i+j));

360 Mcomm(1:3,4:end) = Ncomm(1:end,1:end,Ts(i+j));

361 Mcomm(4:end,4:end) = Omegat;

Page 215: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 209

362

363 Mp(1:end,1:end,i+1) = ...

expmCondMuPi 3(1:maxPos,1:maxPos,Ts(j+i)) * ...

364 expmCondMu(1:maxPos,1:maxPos,Ts(j+i)) * expmCommMu(1:maxPos,1:maxPos,Ts(i+

365

366 for k = 1:12

367 if k == j

368 derivMp(1:end,1:end,k,i+1) = ...

expmCondMuPi 3(1:maxPos,1:maxPos,Ts(j+i)) * ...

369 (−Mcond* expmCondMu(1:maxPos,1:maxPos,Ts(i+j))+ ...

370 expmCondMu(1:maxPos,1:maxPos,Ts(i+j)) * Mcomm)* expmCommMu(1:maxPos

371 derivMp(1:end,1:end,k,i+1);

372 else

373 derivMp(1:end,1:end,k,i+1) = ...

expmCondMuPi 3(1:maxPos,1:maxPos,Ts(j+i)) * ...

374 expmCondMu(1:maxPos,1:maxPos,Ts(j+i)) * ...

375 expmCommMu(1:maxPos,1:maxPos,Ts(i+j)) * derivMp(1:end,1:end,k,i+1)

376 end

377 end

378 end

379 end

380

381 dMp dmu = zeros(length(Mp),length(Mp),12,12);

382 for i = 0:1:11

383 for j = 1:1:12

384 dMp dmu(1:end,1:end,Ts(j+i),i+1) = ...

derivMp(1:end,1:end,j,i+1);

385 end

386 end

387

388 for i = 1:1:12

389 Ap(1:end,1:end,i) = Mp(1:3,1:3,i);

390 Np(1:end,1:end,i) = Mp(1:3,4:end,i);

391 Omegap(1:end,1:end,i) = Mp(4:end,4:end,i);

392 end

393

394 derivMt = zeros(3+3 * lenHarm+1,3+3 * lenHarm+1,12);

395

396 %This block calculates the derivative of the Mt matrix eleme nts.

397 for k = 1:12

398 Mcomm(1:3,1:3) = Acomm(1:end,1:end,Ts(k));

Page 216: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 210

399 Mcomm(1:3,4:end) = Ncomm(1:end,1:end,Ts(k));

400 Mcomm(4:end,4:end) = Omegat;

401

402 Mt arr(1:end,1:end,k) = expmCommMu(1:maxPos,1:maxPos,k);

403 derivMt(1:end,1:end,k) = Mcomm * Mt arr(1:end,1:end,k);

404 end

405

406 %Derivation of FCM

407 Hp = Phi(4+3 * lenHarm+1:end,1:3);

408 Ap mat = Phi(1:3,1:3);

409 Np mat = Phi(1:3,4:3 * lenHarm+4);

410 Qp = Phi(3 * lenHarm+4+1:end,4:3 * lenHarm+4);

411 FCM = Hp* (inv(eye(3,3) −Ap mat)) * Np mat+Qp;

412

413 dPhi dmu = zeros(length(Phi),length(Phi),12);

414 for i = 1:12

415 dPhi dmu(1:end,1:end,i) = eye(length(Phi));

416 end

417

418 Ahat2 = Ahat;

419

420 for i = 1:12

421 for j = 1:12

422 if i 6= j

423 dPhi dmu(1:end,1:end,i) = ...

expmCondMuPi 3(1:end,1:end,j) * ...

424 expmCondMu(1:end,1:end,j) * expmCommMu(1:end,1:end,j) * ...

425 dPhi dmu(1:end,1:end,i);

426 else

427 Ahat(1:3,1:3+3 * lenHarm+1) = ...

[Acomm(1:end,1:end,j),Ncomm(1:end,1:end,j)];

428 Ahat2(1:3,1:3+3 * lenHarm+1) = ...

[Acond(1:end,1:end,j),Ncond(1:end,1:end,j)];

429 dPhi dmu(1:end,1:end,i) = ...

expmCondMuPi 3(1:end,1:end,j) * ...

430 (−Ahat2 * expmCondMu(1:end,1:end,j)+expmCondMu(1:end,1:end,j) * Ahat)

431 * expmCommMu(1:end,1:end,j) * dPhi dmu(1:end,1:end,i);

432 end

433 end

434 end

435

Page 217: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 211

436 I = FCM* Zi arr(1:end,1);

437 derivRotation = zeros(length(FCM),length(FCM),12);

438 for j = 0:1:11

439 count = 1;

440 for i = −h:1:h

441 derivRotation(count:count+1,count:count+1,j+1) = ...

[ −i * sin(i * (j * pi/6+alpha −phase)), ...

442 −i * cos(i * (j * pi/6+alpha −phase));i * cos(i * (j * pi/6+alpha −phase)) ...

−i * sin(i * (j * pi/6+alpha −phase))];

443 count = count + 2;

444 end

445 for i = 0:1:h

446 derivRotation(count:count+1,count:count+1,j+1) = ...

[ −i * sin(i * (j * pi/6+alpha −phase)), ...

447 −i * cos(i * (j * pi/6+alpha −phase));i * cos(i * (j * pi/6+alpha −phase)) ...

−i * sin(i * (j * pi/6+alpha −phase))];

448 count = count + 2;

449 end

450 end

451

452 Idc = I(2 * lenHarm+1);

453 if countIter == 1

454 Iinit = Idc;

455 end

456 Vdc = Zi(2 * lenHarm+1);

457 Ctemp = FCM* derivRotation(1:end,1:end,1);

458 Ctemp = Ctemp(2 * lenHarm+1,1:end);

459 dIdc dalpha = Ctemp * Zi;

460

461 J = zeros(13,13);

462 derivInv2 = zeros(3,3);

463 for i = 1:12

464 for j = 1:12

465 At = Mt arr(1:3,1:3,i);

466 if i == j

467 dAt = derivMt(1:3,1:3,i);

468 dNt = derivMt(1:3,4:end,i);

469 else

470 dAt = zeros(3,3);

471 dNt = zeros(3,3 * lenHarm+1);

472 end

Page 218: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 212

473 dAp = dMp dmu(1:3,1:3,j,i);

474 dNp = dMp dmu(1:3,4:end,j,i);

475 invA = inv(ThetaM −Ap(1:3,1:3,i));

476 det = (1 −Ap(3,3,i)) * (1 −Ap(1,1,i) −Ap(2,2,i)+Ap(1,1,i) * ...

477 Ap(2,2,i) −Ap(1,2,i) * Ap(2,1,i));

478

479 ddet mu = ...

( −1+Ap(2,2,i)+Ap(3,3,i) −Ap(3,3,i) * Ap(2,2,i)) * dAp(1,1)+ ...

480 (−Ap(2,1,i)+Ap(3,3,i) * Ap(2,1,i)) * dAp(1,2)+ ...

481 (−Ap(1,2,i)+Ap(3,3,i) * Ap(1,2,i)) * dAp(2,1)+ ...

482 ( −1+Ap(1,1,i)+Ap(3,3,i) −Ap(3,3,i) * Ap(1,1,i)) * dAp(2,2)+ ...

483 ( −1+Ap(1,1,i)+Ap(2,2,i) −Ap(1,1,i) * Ap(2,2,i)+Ap(1,2,i) * Ap(2,1,i)) * dAp(3,3)

484 derivInv2(1,1) = ...

det * ( −dAp(2,2) −dAp(3,3)+Ap(2,2,i) * dAp(3,3)+ ...

485 Ap(3,3,i) * dAp(2,2)) −ddet mu* (1 −Ap(2,2,i) −Ap(3,3,i)+Ap(2,2,i) * Ap(3,3,i));

486 derivInv2(1,2) = ...

det * (dAp(1,2) −Ap(1,2,i) * dAp(3,3) −Ap(3,3,i) * dAp(1,2)) −...

487 ddet mu* (Ap(1,2,i) −Ap(1,2,i) * Ap(3,3,i));

488 derivInv2(2,1) = ...

det * (dAp(2,1) −Ap(2,1,i) * dAp(3,3) −Ap(3,3,i) * dAp(2,1)) −...

489 ddet mu* (Ap(2,1,i) −Ap(2,1,i) * Ap(3,3,i));

490 derivInv2(2,2) = ...

det * ( −dAp(1,1) −dAp(3,3)+Ap(1,1,i) * dAp(3,3)+ ...

491 Ap(3,3,i) * dAp(1,1)) −ddet mu* (1 −Ap(1,1,i) −Ap(3,3,i)+Ap(1,1,i) * Ap(3,3,i));

492 derivInv2(3,3) = ...

det * ( −dAp(1,1) −dAp(2,2)+Ap(1,1,i) * dAp(2,2)+ ...

493 Ap(2,2,i) * dAp(1,1) −Ap(1,2,i) * dAp(2,1) −Ap(2,1,i) * dAp(1,2)) −...

494 ddet mu* (1 −Ap(1,1,i) −Ap(2,2,i)+Ap(1,1,i) * Ap(2,2,i) −Ap(1,2,i) * Ap(2,1,i));

495 derivInv2 = 1/(det)ˆ2 * derivInv2;

496 J(i,j) = ...

Mi deriv(i,1:end) * (dAt * invA * Np(1:3,1:end,i)+At * invA * dNp+...

497 At * derivInv2 * Np(1:3,1:end,i)+dNt) * Zi arr(1:end,i);

498 end

499 end

500

501 for i = 1:12

502 At = Mt arr(1:3,1:3,i);

503 Nt = Mt arr(1:3,4:end,i);

504 J(i,13) = Mi deriv(i,1:end) * (At * inv(ThetaM −Ap(1:3,1:3,i)) * ...

505 Np(1:3,1:end,i)+Nt) * derivRotation(1:end,1:end,i) * Zi;

506 end

Page 219: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 213

507

508 dFCMdmu = zeros(length(FCM),length(FCM),12);

509 derivInv2 = zeros(3,3);

510 derivAp = zeros(3,3);

511 det = ...

(1 −Ap mat(3,3)) * (1 −Ap mat(1,1) −Ap mat(2,2)+Ap mat(1,1) * Ap mat(2,2) −...

512 Ap mat(1,2) * Ap mat(2,1));

513 for i = 1:12

514 derivAp = dPhi dmu(1:3,1:3,i);

515 ddet mu = ...

( −1+Ap mat(2,2)+Ap mat(3,3) −Ap mat(3,3) * Ap mat(2,2)) * derivAp(1,1)+ ...

516 (−Ap mat(2,1)+Ap mat(3,3) * Ap mat(2,1)) * derivAp(1,2)+ ...

517 (−Ap mat(1,2)+Ap mat(3,3) * Ap mat(1,2)) * derivAp(2,1)+ ...

518 ( −1+Ap mat(1,1)+Ap mat(3,3) −Ap mat(3,3) * Ap mat(1,1)) * derivAp(2,2)+ ...

519 ( −1+Ap mat(1,1)+Ap mat(2,2) −Ap mat(1,1) * Ap mat(2,2)+Ap mat(1,2) * Ap mat(2,1))

520 derivInv2(1,1) = ...

det * ( −derivAp(2,2) −derivAp(3,3)+Ap mat(2,2) * derivAp(3,3)+ ...

521 Ap mat(3,3) * derivAp(2,2)) −ddet mu* (1 −Ap mat(2,2) −Ap mat(3,3)+Ap mat(2,2) *

522 derivInv2(1,2) = ...

det * (derivAp(1,2) −Ap mat(1,2) * derivAp(3,3) −Ap mat(3,3) * derivAp(1,2)) −...

523 ddet mu* (Ap mat(1,2) −Ap mat(1,2) * Ap mat(3,3));

524 derivInv2(2,1) = ...

det * (derivAp(2,1) −Ap mat(2,1) * derivAp(3,3) −Ap mat(3,3) * derivAp(2,1)) −...

525 ddet mu* (Ap mat(2,1) −Ap mat(2,1) * Ap mat(3,3));

526 derivInv2(2,2) = ...

det * ( −derivAp(1,1) −derivAp(3,3)+Ap mat(1,1) * derivAp(3,3)+ ...

527 Ap mat(3,3) * derivAp(1,1)) −ddet mu* (1 −Ap mat(1,1) −Ap mat(3,3)+Ap mat(1,1) *

528 derivInv2(3,3) = ...

det * ( −derivAp(1,1) −derivAp(2,2)+Ap mat(1,1) * derivAp(2,2)+ ...

529 Ap mat(2,2) * derivAp(1,1) −Ap mat(1,2) * derivAp(2,1) −Ap mat(2,1) * derivAp(1,2)

530 ddet mu* (1 −Ap mat(1,1) −Ap mat(2,2)+Ap mat(1,1) * Ap mat(2,2) −Ap mat(1,2) * Ap

531 derivInv2 = 1/(det)ˆ2 * derivInv2;

532 dFCMdmu(1:end,1:end,i) = ...

dPhi dmu(3+3 * lenHarm+1+1:end,1:3,i) * ...

533 (inv(eye(3,3) −Ap mat)) * Np mat+Hp* derivInv2 * Np mat+ ...

534 Hp* inv(eye(3,3) −Ap mat) * dPhi dmu(1:3,4:3 * lenHarm+4,i)+ ...

535 dPhi dmu(3 * lenHarm+5:end,4:4+3 * lenHarm,i);

536 Ctemp = dFCM dmu(1:end,1:end,i) * Zi arr(1:end,1);

537 Ctemp = Ctemp(2 * lenHarm+1);

538 J(13,i) = (Vdc+2 * Rdc* Idc) * Ctemp;

539 end

Page 220: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 214

540 J11 = zeros(12,12);

541 for i = 1:12

542 for j =1:12

543 J11(i,j) = ...

calcJ11(lenHarm,Ap(1:end,1:end,i),Np(1:end,1:end,i) , ...

544 Mt arr(1:end,1:end,i),derivMt(1:end,1:end,i), ...

545 dMp dmu(1:end,1:end,j,i),Zi arr(1:end,i),Mi(i,1:end),i −j);

546 end

547 end

548 J(1:12,1:12) = J11;

549

550 J(13,13) = dIdc dalpha * (Vdc+2 * Rdc* Idc);

551

552 M = zeros(13,1);

553 for i = 1:12

554 At = Mt arr(1:3,1:3,i);

555 Nt = Mt arr(1:3,4:end,i);

556 M(i) = ...

0−Mi(i,1:end) * (At * inv(ThetaM −Ap(1:3,1:3,i)) * Np(1:3,1:end,i)+Nt) * Zi arr(1:end

557 end

558

559 M(13) = Pload − (Idc * Vdc+Rdc* Idcˆ2);

560 new mu = mu + J\M;

561

562 flag2 = 0;

563 for i = 1:13

564 if abs(M(i)) > tolerance

565 flag2 = 1;

566 break ;

567 end

568 end

569

570 if flag2 == 0

571 break ;

572 end

573

574 if countIter > 25

575 break ;

576 end

577 mu = new mu;

578 alpha = new mu(13);

Page 221: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 215

579 if max(mu(1:12)) > pi/6 | | min(mu(1:12)) < 0

580 flag error = flag error +1;

581 else

582 flag error = 0;

583 end

584

585 countIter = countIter + 1;

586 end

587

588 RotationMatrix2 = zeros(length(FCM));

589 count = 1;

590 for i = −h:1:h

591 RotationMatrix2(count:count+1,count:count+1) = ...

[cos( −i * (alpha −phase)), ...

592 −sin( −i * (alpha −phase));sin( −i * (alpha −phase)) ...

cos( −i * (alpha −phase))];

593 count = count + 2;

594 end

595 for i = 0:1:h

596 RotationMatrix2(count:count+1,count:count+1) = ...

[cos( −i * (alpha −phase)), ...

597 −sin( −i * (alpha −phase));sin( −i * (alpha −phase)) ...

cos( −i * (alpha −phase))];

598 count = count + 2;

599 end

600

601 tempM = eye(3 * lenHarm+1);

602 tempM(2 * lenHarm+3:end,2 * lenHarm+1:end) = ...

2* tempM(2 * lenHarm+3:end,2 * lenHarm+1:end);

603 I = tempM * RotationMatrix2 * I;

604 mu out = mu(1:12);

605

606 for i = 1:6

607 if mu(i) < 0 | | mu(i) > gamma(i)

608 error = 1;

609 end

610 end

611 if error 6= 0

612 Idc = Iinit;

613 end

614

Page 222: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 216

615 Pest = Idc * Vdc+Rdc* Idcˆ2;

616

617 [Ia Ib Ic fundCurrents] = getI abc fundCurrents(I,h);

B.2.5 Diode 12-Pulse Rectifier

solveDiode12.m

1 function [Ia Ib Ic fundCurrents phaseAng gamma mu Pload Rdc L Vdc] = ...

2 solveDiode12(Valphabeta,L,R,Rdc in,Ldc,h,Vdc in,P in,mu in,gamma in,phaseAng in)

3

4 global OpenDSSFileLoc

5

6 error = 1;

7 Vdc = Vdc in;

8 Rdc = Rdc in;

9 P = P in;

10 errorFile = fopen([OpenDSSFileLoc, 'errorFile.txt' ], 'w' );

11 if P in > 3

12 c = clock;

13 P = 3;

14 end

15 if P in ≤ 0

16 c = clock;

17 Iphase = zeros(h,3);

18 for i = 1:h

19 Iphase(i,1) = i;

20 end

21 Iphase(1,2) = 100;

22 Ia = Iphase;

23 Ib = Iphase;

24 Ic = Iphase;

25 fundCurrents = [0,0;0, −120;0,+120];

26 phaseAng = 0;

27 gamma = 0;

28 mu = 0;

29 Pload = 0;

Page 223: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 217

30 return ;

31 end

32

33 %Initializations

34 if mu in == −1

35 Idc ref = ( −Vdc+sqrt(Vdc+4 * Rdc* P))/2/Rdc;

36 mu i = pi/18;

37 convergance = 0;

38

39 while (convergance == 0)

40 J = sqrt(3)/2/L * sin(mu i);

41 Idc avg = 1/2/L * ( −sqrt(3) * cos(mu i)+sqrt(3));

42

43 M = Idc ref −Idc avg;

44 if abs(M) < 0.01

45 break ;

46 end

47 mu i = mu i+inv(J) * M;

48 end

49

50 if mu i < 0 | | mu i > pi/6

51 mu i = pi/12;

52 end

53 mu prev = mu i * ones(12,1);

54 gammaprev = pi/6 * ones(12,1);

55 phaseAng prev = angle(Valphabeta(2 * h+3)+1i * Valphabeta(2 * h+4));

56 else

57 mu prev = mu in;

58 gammaprev = gamma in;

59 phaseAng prev = phaseAng in;

60 end

61 %************

62

63 Rdc = Rdc in;

64 center = 2 * h+1;

65 convergance = 0;

66

67 for i = 1:2:h

68 V = Valphabeta(center −i * 2:center+i * 2+1);

69 while (convergance == 0)

Page 224: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 218

70 [Ia Ib Ic fundCurrents phaseAng gamma mu Pload error Rdc ...

Vdc] = ...

71 solveDiode12Model(V,L,R,Rdc,Ldc,i,0,P,mu prev,gamma prev,phaseAng prev);

72

73 ratio = Pload/P;

74 if abs(1 −ratio) * 100 > 1.0001

75 c = clock;

76 Rdc = Rdc* ratio;

77 elseif error == 1

78 L = L* 0.5;

79 else

80 convergance = 1;

81 end

82

83 if error == 0

84 mu prev = mu;

85 gammaprev = gamma;

86 phaseAng prev = phaseAng;

87 end

88

89 end

90 mu prev = mu;

91 gammaprev = gamma;

92 phaseAng prev = phaseAng;

93 convergance = 0;

94 end

95

96 fclose(errorFile);

solveDiode12Model.m

1 function [Ia Ib Ic fundCurrents phaseAng gamma mu Pload error Rdc ...

Vdc] = ...

2 solveDiode12Model(Valphabeta,L,R,Rdc,Ldc,h,Vdc,Pdc, mu i,gamma i,phase i)

3

4 global SymMtx invSymMtx

5

Page 225: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 219

6 error = 0;

7 flag error = 0;

8 Vout = Vdc;

9 [w,Vbase,tol,f,Tac,lenHarm,CTF,CTFsm, ...

10 invCTF,invCTFsm,Mi,phase,Ts,Vab coeff,Zi] = ...

inputs 12pulse diode(Valphabeta,L,R,Ldc,Rdc,h,Vdc);

11

12 [Acomm,Ncomm,Acond,Ncond,Omegat,Ahat,H] = ...

input circuiteqns(h,R,L,Rdc, ...

13 Ldc,lenHarm,CTFsm,invCTFsm,Tac);

14

15 mu = mui;

16 phase = phase i;

17 gamma = gammai;

18

19 count = 0;

20 while (true)

21 Zi arr = rotMtx(lenHarm,h,gamma,phase,Zi); %Fine.

22

23 %solving for FCM and exponential matrices

24 [FCM expmCondMuPi 3 expmCondMu expmCommMu Hp Apmat Np mat Qp] = ...

25 solveFCM(lenHarm,Ahat,Acomm,Ncomm,Acond,Ncond,mu,ga mma);

26

27 I = FCM* Zi arr(1:end,1);

28

29 %Solve Mp

30 [Mp dMpmu dMpgamma Ap Np] = solveMp(lenHarm,Acond,Ncond, ...

31 Acomm,Ncomm,Omegat,expmCondMuPi 3,expmCondMu,expmCommMu,Ts);

32

33 %solving Mt and dMt d(mu)

34 [Mt dMt dmu] = solveMt(lenHarm,Acomm,Ncomm,Omegat,expmCommMu) ;

35

36 %solving for the derivative of the rotational matrix

37 derivRotation = deriv rotMtx(lenHarm,h,gamma,phase);

38

39 %calculate M

40 M = calcM(Mi,Vab coeff,Mt,Ap,Np,Zi arr,Ts,lenHarm,L,R,Ldc,Rdc);

41

42 %calculate Jacobian J

43 J = calcJ(Mi,Vab coeff,Mt,dMt dmu,dMpmu,dMpgamma,Ap,Np,Zi arr,Zi, ...

44 Ts,lenHarm,L,R,Ldc,Rdc,derivRotation);

Page 226: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 220

45

46 Idc = I(2 * lenHarm+1);

47 if count == 0

48 Iinit = Idc;

49 end

50

51 Vdc = Zi(2 * lenHarm+1);

52 constraintVar = [mu;gamma;phase];

53 constraintVar = constraintVar + inv(J) * M;

54 mu = constraintVar(1:12);

55 gamma = constraintVar(13:24);

56 phase = constraintVar(25);

57

58 flag2 = 0;

59 for i = 1:25

60 if abs(M(i)) > tol

61 flag2 = 1;

62 break ;

63 end

64 end

65

66 if flag2 == 0

67 break ;

68 end

69 if (flag error ≥ 100)

70 break ;

71 else

72 if max(mu(1:12)) > pi/3 | | min(mu(1:12)) < −pi/3

73 flag error = flag error +1;

74 if max(mu(1:6)) > pi | | min(mu(1:6)) < −pi

75 flag error = flag error+3;

76 end

77 else

78 flag error = 0;

79 end

80 if (flag error > 2)

81 error = 1;

82 gamma = gammai;

83 phase = phase i;

84 mu = mui;

85 flag error = 100;

Page 227: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 221

86 break ;

87 end

88 end

89

90 count = count + 1;

91 if count > 25

92 flag error = 100;

93 end

94 end

95

96 for i = 1:12

97 if mu(i) < 0 | | mu(i) > gamma(i)

98 error = 1;

99 end

100 end

101 if error 6= 0

102 Idc = Iinit;

103 end

104

105 Vdc = Idc * Rdc;

106

107 phaseAng = phase;

108 Pload = Rdc * Idcˆ2;

109

110 RotationMatrix2 = zeros(length(FCM));

111 count = 1;

112 for j = −h:1:h

113 RotationMatrix2(count:count+1,count:count+1) = ...

114 [cos( −j * (0 −phase)), −sin( −j * (0 −phase)); ...

115 sin( −j * (0 −phase)),cos( −j * (0 −phase))];

116 count = count + 2;

117 end

118 for j = 0:h

119 RotationMatrix2(count:count+1,count:count+1) = ...

120 [cos( −j * (0 −phase)), −sin( −j * (0 −phase)); ...

121 sin( −j * (0 −phase)),cos( −j * (0 −phase))];

122 count = count + 2;

123 end

124

125 tempM = eye(3 * lenHarm+1);

Page 228: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 222

126 tempM(2 * lenHarm+3:end,2 * lenHarm+1:end) = ...

2* tempM(2 * lenHarm+3:end,2 * lenHarm+1:end);

127 I = tempM * RotationMatrix2 * I;

128

129 [Ia Ib Ic fundCurrents] = getI abc fundCurrents(I,h);

inputs 12pulse diode.m

1 function [w,Vbase,tol,f,Tac,lenHarm,CTF,CTFsm, ...

2 invCTF,invCTFsm,Mi,phase,Ts,Vab coeff,Zi] = ...

3 inputs 12pulse diode(Valphabeta,L,R,Ldc,Rdc,h,Vdc)

4

5 A = [1 1 1;1 exp(1i * 240* pi/180) exp(1i * 120* pi/180); ...

6 1 exp(1i * 120* pi/180) exp(1i * 240* pi/180)];

7 invA = inv(A);

8

9 w = 1;

10

11 Vbase = 1;

12 tol = 0.001;

13 f = w/2/pi;

14 Tac = 1/f;

15 Vout = Vdc;

16 V abc = A * [0;1.0;0.0];

17 Mag abc = [abs(V abc(1));abs(V abc(2));abs(V abc(3))];

18 Phase abc = [angle(V abc(1));angle(V abc(2));angle(V abc(3))];

19

20 lenHarm = 2 * h+1;

21 CTF = 2/3 * [1 −1/2 −1/2;0 sqrt(3)/2 −sqrt(3)/2;1/sqrt(2) 1/sqrt(2) ...

1/sqrt(2)];

22 CTFsm = CTF(1:2,1:3);

23 invCTF = inv(CTF);

24 invCTFsm = invCTF(1:3,1:2);

25

26 Mi = zeros(12,3);

27 for i = 0:1

28 Mi(1+i,1:end) = [( −2* i+1) * [0 sqrt(3) 0] * invCTFsm 1];

Page 229: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 223

29 Mi(3+i,1:end) = [( −2* i+1) * [ −sqrt(3) 0 0] * invCTFsm 1];

30 Mi(5+i,1:end) = [( −2* i+1) * [0 0 sqrt(3)] * invCTFsm 1];

31 Mi(7+i,1:end) = [( −2* i+1) * [0 −sqrt(3) 0] * invCTFsm 1];

32 Mi(9+i,1:end) = [( −2* i+1) * [sqrt(3) 0 0] * invCTFsm 1];

33 Mi(11+i,1:end) = [( −2* i+1) * [0 0 −sqrt(3)] * invCTFsm 1];

34 end

35

36 Vab coeff1 = [ −L/(4 * L+Ldc) * (1+sqrt(3)), −1+L/(4 * L+Ldc),1] * invCTFsm;

37 Vab coeff2 = [ −L/(4 * L+Ldc) * (1+sqrt(3)), −sqrt(3),L/(4 * L+Ldc)] * invCTFsm;

38 Vab coeff3 = [1 −L/(4 * L+Ldc), −1,L/(4 * L+Ldc) * (1+sqrt(3))] * invCTFsm;

39 Vab coeff4 = [sqrt(3) −L/(4 * L+Ldc) * sqrt(3), −L/(4 * L+Ldc) * (1+sqrt(3)), ...

40 L/(4 * L+Ldc)] * invCTFsm;

41 Vab coeff5 = [1, −L/(4 * L+Ldc) * (1+sqrt(3)),L/(4 * L+Ldc) −1] * invCTFsm;

42 Vab coeff6 = [L/(4 * L+Ldc), −(1+sqrt(3)) * L/(4 * L+Ldc), −sqrt(3)] * invCTFsm;

43 Vab coeff7 = [L/(4 * L+Ldc) * (1+sqrt(3)), −L/(4 * L+Ldc)+1, −1] * invCTFsm;

44 Vab coeff8 = [L/(4 * L+Ldc),sqrt(3) −L/(4 * L+Ldc) * sqrt(3), ...

45 −L/(4 * L+Ldc) * (1+sqrt(3))] * invCTFsm;

46 Vab coeff9 = [L/(4 * L+Ldc) −1,1, −L/(4 * L+Ldc) * (1+sqrt(3))] * invCTFsm;

47 Vab coeff10 = [ −sqrt(3),L/(4 * L+Ldc), −L/(4 * L+Ldc) * (1+sqrt(3))] * invCTFsm;

48 Vab coeff11 = [ −1,L/(4 * L+Ldc) * (1+sqrt(3)), −L/(4 * L+Ldc)+1] * invCTFsm;

49 Vab coeff12 = [ −L/(4 * L+Ldc) * (1+sqrt(3)),L/(4 * L+Ldc), ...

50 −L/(4 * L+Ldc) * sqrt(3)+sqrt(3)] * invCTFsm;

51

52 Vab coeff = [Vab coeff1;Vab coeff2;Vab coeff3;Vab coeff4;Vab coeff5; ...

53 Vab coeff6;Vab coeff7;Vab coeff8;Vab coeff9;Vab coeff10;Vab coeff11; ...

54 Vab coeff12];

55

56 Vsabc phasor = zeros(3,1);

57 for i = 1:3

58 [x y] = pol2cart(Phase abc(i),Mag abc(i));

59 Vsabc phasor(i) = x + 1i * y;

60 end

61

62 temp = [1 −1 0;0 1 −1; −1 0 ...

1] * [Vsabc phasor(1);Vsabc phasor(2);Vsabc phasor(3)];

63

64 symMatrix = invA * Vsabc phasor;

65

66 posSeq = symMatrix(2);

67 negSeq = symMatrix(3);

68

Page 230: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 224

69 phase = angle(Valphabeta(2 * h+3)+1i * Valphabeta(2 * h+4));

70 Ts = zeros(24,1);

71 Ts(1:end) = [1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7 ,8,9,10,11,12];

72

73 Zi = zeros(3 * lenHarm+1,1);

74

75 Zi(1:2 * lenHarm,1) = Valphabeta;

76 Vdc vect dc = Vout;

77

78 Zi(2 * lenHarm+1) = Vdc vect dc;

79

80 end

input circuiteqns.m

1 function [Acomm,Ncomm,Acond,Ncond,Omegat,Ahat,H] = ...

2 input circuiteqns(h,R,L,Rdc,Ldc,lenHarm,CTFsm,invCTFsm,Ta c)

3

4 Ncond coeff = zeros(3,3,12);

5 Acond = zeros(3,3,12);

6

7 Acond(3,3,1:end) = ones(1,1,12) *−(4 * R+Rdc)/(4 * L+Ldc);

8 Ncond coeff(3,3,1:end) = ones(1,1,12) *−1/(4 * L+Ldc);

9

10 Acond coeff 1 = [1+2/sqrt(3); −1/sqrt(3); −1−1/sqrt(3)];

11 Acond coeff 2 = [1+1/sqrt(3);1/sqrt(3); −1−2/sqrt(3)];

12 Acond coeff 3 = [1/sqrt(3);1+1/sqrt(3); −1−2/sqrt(3)];

13 Acond coeff 4 = [ −1/sqrt(3);1+2/sqrt(3); −1−1/sqrt(3)];

14 Acond coeff 5 = [ −1−1/sqrt(3);1+2/sqrt(3); −1/sqrt(3)];

15 Acond coeff 6 = [ −1−2/sqrt(3);1+1/sqrt(3);1/sqrt(3)];

16 Acond coeff 7 = [ −1−2/sqrt(3);1/sqrt(3);1+1/sqrt(3)];

17 Acond coeff 8 = [ −1−1/sqrt(3); −1/sqrt(3);1+2/sqrt(3)];

18 Acond coeff 9 = [ −1/sqrt(3); −1−1/sqrt(3);1+2/sqrt(3)];

19 Acond coeff 10 = [1/sqrt(3); −1−2/sqrt(3);1+1/sqrt(3)];

20 Acond coeff 11 = [1+1/sqrt(3); −1−2/sqrt(3);1/sqrt(3)];

21 Acond coeff 12 = [1+2/sqrt(3); −1−1/sqrt(3); −1/sqrt(3)];

22

Page 231: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 225

23 Acond coeff = ...

[Acond coeff 1,Acond coeff 2,Acond coeff 3,Acond coeff 4, ...

24 Acond coeff 5,Acond coeff 6,Acond coeff 7,Acond coeff 8, ...

25 Acond coeff 9,Acond coeff 10,Acond coeff 11,Acond coeff 12];

26

27 Ncond coeff 2 1 = [1+sqrt(3),0, −1];

28 Ncond coeff 2 2 = [1,0, −1−sqrt(3)];

29 Ncond coeff 2 3 = [0,1, −1−sqrt(3)];

30 Ncond coeff 2 4 = [0,1+sqrt(3), −1];

31 Ncond coeff 2 5 = [ −1,1+sqrt(3),0];

32 Ncond coeff 2 6 = [ −1−sqrt(3),1,0];

33 Ncond coeff 2 7 = [ −1−sqrt(3),0,1];

34 Ncond coeff 2 8 = [ −1,0,1+sqrt(3)];

35 Ncond coeff 2 9 = [0, −1,1+sqrt(3)];

36 Ncond coeff 2 10 = [0, −1−sqrt(3),1];

37 Ncond coeff 2 11 = [1, −1−sqrt(3),0];

38 Ncond coeff 2 12 = [1+sqrt(3), −1,0];

39

40 Ncond coeff 2 = [Ncond coeff 2 1;Ncond coeff 2 2;Ncond coeff 2 3; ...

41 Ncond coeff 2 4;Ncond coeff 2 5;Ncond coeff 2 6;Ncond coeff 2 7; ...

42 Ncond coeff 2 8;Ncond coeff 2 9;Ncond coeff 2 10;Ncond coeff 2 11; ...

43 Ncond coeff 2 12];

44

45 for i = 1:12

46 Acond(1:2,3,i) = CTFsm * Acond coeff(1:end,i) * Acond(3,3,i);

47 Ncond coeff(1:2,3,i) = ...

CTFsm* Acond coeff(1:end,i) * Ncond coeff(3,3,i);

48 Ncond coeff(3,1:2,i) = 1/(4 * L+Ldc) * Ncond coeff 2(i,1:end) * invCTFsm;

49 Ncond coeff(1:2,1:2,i) = ...

CTFsm* Acond coeff(1:end,i) * Ncond coeff(3,1:2,i);

50 end

51

52 Acomm = zeros(3,3,12);

53 Ncommcoeff = zeros(3,3,12);

54

55 Acomm(3,3,1:end)= ones(1,1,12) *−(7/2 * R+Rdc)/(7/2 * L+Ldc);

56 Ncommcoeff(3,3,1:end) = ones(1,1,12) *−1/(7/2 * L+Ldc);

57

58 Acommcoeff 1 1 = [1+2/sqrt(3); −1/2 −1/sqrt(3); −1/2 −1/sqrt(3)];

59 Acommcoeff 1 2 = [1+sqrt(3)/2; 0; −1−sqrt(3)/2];

60 Acommcoeff 1 3 = [1/2+1/sqrt(3); 1/2+1/sqrt(3); −1−2/sqrt(3)];

Page 232: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 226

61 Acommcoeff 1 4 = [0; 1+sqrt(3)/2; −1−sqrt(3)/2];

62 Acommcoeff 1 5 = [ −1/2 −1/sqrt(3); 1+2/sqrt(3); −1/2 −1/sqrt(3)];

63 Acommcoeff 1 6 = [ −1−sqrt(3)/2; 1+sqrt(3)/2; 0];

64 Acommcoeff 1 7 = [ −1−2/sqrt(3); 1/2+1/sqrt(3); 1/2+1/sqrt(3)];

65 Acommcoeff 1 8 = [ −1−sqrt(3)/2; 0; 1+sqrt(3)/2];

66 Acommcoeff 1 9 = [ −1/2 −1/sqrt(3); −1/2 −1/sqrt(3); 1+2/sqrt(3)];

67 Acommcoeff 1 10 = [0; −1−sqrt(3)/2; 1+sqrt(3)/2];

68 Acommcoeff 1 11 = [1/2+1/sqrt(3); −1−2/sqrt(3); 1/2+1/sqrt(3)];

69 Acommcoeff 1 12 = [1+sqrt(3)/2; −1−sqrt(3)/2; 0];

70 Acommcoeff = [Acomm coeff 1 1,Acomm coeff 1 2,Acomm coeff 1 3, ...

71 Acommcoeff 1 4,Acomm coeff 1 5,Acomm coeff 1 6,Acomm coeff 1 7, ...

72 Acommcoeff 1 8,Acomm coeff 1 9,Acomm coeff 1 10,Acomm coeff 1 11, ...

73 Acommcoeff 1 12];

74

75 Acommcoeff 2 1 = [ 0; 1/2+1/sqrt(3); 1/2+1/sqrt(3)];

76 Acommcoeff 2 2 = [ −1/3 −1/2/sqrt(3); 0; 1/3+1/2/sqrt(3)];

77 Acommcoeff 2 3 = −[ 1/2+1/sqrt(3); 1/2+1/sqrt(3); 0];

78 Acommcoeff 2 4 = [ 0; −1/3 −1/2/sqrt(3); 1/3+1/2/sqrt(3)];

79 Acommcoeff 2 5 = [ 1/2+1/sqrt(3); 0; 1/2+1/sqrt(3)];

80 Acommcoeff 2 6 = [ 1/3+1/2/sqrt(3); −1/3 −1/2/sqrt(3); 0];

81 Acommcoeff 2 7 = −[ 0; 1/2+1/sqrt(3); 1/2+1/sqrt(3)];

82 Acommcoeff 2 8 = [ 1/3+1/2/sqrt(3); 0; −1/3 −1/2/sqrt(3)];

83 Acommcoeff 2 9 = [ 1/2+1/sqrt(3); 1/2+1/sqrt(3); 0];

84 Acommcoeff 2 10 = [ 0; 1/3+1/2/sqrt(3); −1/3 −1/2/sqrt(3)];

85 Acommcoeff 2 11 = −[ 1/2+1/sqrt(3); 0; 1/2+1/sqrt(3)];

86 Acommcoeff 2 12 = [ −1/3 −1/2/sqrt(3); 1/3+1/2/sqrt(3); 0];

87 Acommcoeff 2 = ...

−R/L * [Acomm coeff 2 1,Acomm coeff 2 2,Acomm coeff 2 3, ...

88 Acommcoeff 2 4,Acomm coeff 2 5,Acomm coeff 2 6,Acomm coeff 2 7, ...

89 Acommcoeff 2 8,Acomm coeff 2 9,Acomm coeff 2 10,Acomm coeff 2 11, ...

90 Acommcoeff 2 12];

91

92 Acommcoeff 3 = zeros(3,3,12);

93 Acommcoeff 3(1:end,1:end,1) = R/L * [ 0,0,0; 0, −1,0; 0,0, −1];

94 Acommcoeff 3(1:end,1:end,2) = R/L * [ −1/3 1/3 0; 1/3 −2/3 1/3; 0 1/3 ...

−1/3];

95 Acommcoeff 3(1:end,1:end,3) = R/L * [ −1 0 0; 0 −1 0; 0 0 0];

96 Acommcoeff 3(1:end,1:end,4) = R/L * [ −2/3 1/3 1/3; 1/3 −1/3 0; 1/3 0 ...

−1/3];

97 Acommcoeff 3(1:end,1:end,5) = R/L * [ −1 0 0; 0 0 0; 0 0 −1];

Page 233: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 227

98 Acommcoeff 3(1:end,1:end,6) = R/L * [ −1/3 0 1/3; 0 −1/3 1/3; 1/3 1/3 ...

−2/3];

99 Acommcoeff 3(1:end,1:end,7) = R/L * [ 0 0 0; 0 −1 0; 0 0 −1];

100 Acommcoeff 3(1:end,1:end,8) = R/L * [ −1/3 1/3 0; 1/3 −2/3 1/3; 0 1/3 ...

−1/3];

101 Acommcoeff 3(1:end,1:end,9) = R/L * [ −1 0 0; 0 −1 0; 0 0 0];

102 Acommcoeff 3(1:end,1:end,10) = R/L * [ −2/3 1/3 1/3; 1/3 −1/3 0; 1/3 ...

0 −1/3];

103 Acommcoeff 3(1:end,1:end,11) = R/L * [ −1 0 0; 0 0 0; 0 0 −1];

104 Acommcoeff 3(1:end,1:end,12) = R/L * [ −1/3 0 1/3; 0 −1/3 1/3; 1/3 ...

1/3 −2/3];

105

106 Ncommcoeff 2 1 = [ 1+sqrt(3), −1/2, −1/2];

107 Ncommcoeff 2 2 = [ 1+sqrt(3), sqrt(3)/2, −1];

108 Ncommcoeff 2 3 = [ 1/2, 1/2, −sqrt(3) −1];

109 Ncommcoeff 2 4 = [ sqrt(3)/2, 1+sqrt(3), −1];

110 Ncommcoeff 2 5 = [ −1/2, 1+sqrt(3), −1/2];

111 Ncommcoeff 2 6 = [ −1, 1+sqrt(3), sqrt(3)/2];

112 Ncommcoeff 2 7 = [ −1−sqrt(3), 1/2, 1/2];

113 Ncommcoeff 2 8 = [ −1, sqrt(3)/2, 1+sqrt(3)];

114 Ncommcoeff 2 9 = [ −1/2, −1/2, sqrt(3)+1];

115 Ncommcoeff 2 10 = [ sqrt(3)/2, −1, 1+sqrt(3)];

116 Ncommcoeff 2 11 = [ 1/2, −1−sqrt(3), 1/2];

117 Ncommcoeff 2 12 = [ 1+sqrt(3), −1, sqrt(3)/2];

118 Ncommcoeff 2 = [Ncomm coeff 2 1;Ncomm coeff 2 2;Ncomm coeff 2 3; ...

119 Ncommcoeff 2 4;Ncomm coeff 2 5;Ncomm coeff 2 6;Ncomm coeff 2 7; ...

120 Ncommcoeff 2 8;Ncomm coeff 2 9;Ncomm coeff 2 10;Ncomm coeff 2 11; ...

121 Ncommcoeff 2 12];

122

123 Ncommcoeff 3 = zeros(3,3,12);

124 Ncommcoeff 3(1:end,1:end,1) = [ 0, 0, 0; 0, 1/2, −1/2; 0, −1/2, 1/2];

125 Ncommcoeff 3(1:end,1:end,2) = [ 0, −1/2, 0; 0, 1, 0; 0, −1/2, 0];

126 Ncommcoeff 3(1:end,1:end,3) = [ 1/2, −1/2, 0; −1/2, 1/2, 0; 0, 0, 0];

127 Ncommcoeff 3(1:end,1:end,4) = [ 1, 0, 0; −1/2, 0, 0; −1/2, 0, 0];

128 Ncommcoeff 3(1:end,1:end,5) = [ 1/2, 0, −1/2; 0, 0, 0; −1/2, 0, 1/2];

129 Ncommcoeff 3(1:end,1:end,6) = [ 0, 0, −1/2; 0, 0, −1/2; 0, 0, 1];

130 Ncommcoeff 3(1:end,1:end,7) = [ 0, 0, 0; 0, 1/2, −1/2; 0, −1/2, 1/2];

131 Ncommcoeff 3(1:end,1:end,8) = [ 0, −1/2, 0; 0, 1, 0; 0, −1/2, 0];

132 Ncommcoeff 3(1:end,1:end,9) = [ 1/2, −1/2, 0; −1/2, 1/2, 0; 0, 0, 0];

133 Ncommcoeff 3(1:end,1:end,10) = [ 1, 0, 0; −1/2, 0, 0; −1/2, 0, 0];

134 Ncommcoeff 3(1:end,1:end,11) = [ 1/2, 0, −1/2; 0, 0, 0; −1/2, 0, 1/2];

Page 234: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 228

135 Ncommcoeff 3(1:end,1:end,12) = [ 0, 0, −1/2; 0, 0, −1/2; 0, 0, 1];

136

137 for i = 1:12

138 Ncommcoeff(3,1:2,i) = 1/(7/2 * L+Ldc) * Ncommcoeff 2(i,1:end) * invCTFsm;

139 Acomm(1:2,3,i) = CTFsm * Acommcoeff(1:end,i) * Acomm(3,3,i)+ ...

140 CTFsm* Acommcoeff 2(1:end,i);

141 Acomm(1:2,1:2,i) = CTFsm * Acommcoeff 3(1:end,1:end,i) * invCTFsm;

142 Ncommcoeff(1:2,1:2,i) = 1/L * CTFsm* Ncommcoeff 3(1:end,1:end,i) * ...

143 invCTFsm+CTFsm* Acommcoeff(1:end,i) * Ncommcoeff(3,1:2,i);

144 Ncommcoeff(1:2,3,i) = CTFsm * Acommcoeff(1:end,i) * Ncommcoeff(3,3,i);

145 end

146

147 %*************************************************** ***********************

148 Ncond = zeros(3,2 * lenHarm+2 * h+2,12);

149 for j = 1:12

150 for i = 1:2:2 * lenHarm

151 Ncond(1:end,i:i+1,j) = Ncond coeff(1:end,1:2,j);

152 end

153 end

154 %****************************************

155 for j = 1:12

156 for i = 2 * lenHarm+1:2:2 * lenHarm+lenHarm+1

157 Ncond(1:end,i:i+1,j) = [Ncond coeff(1:end,3,j),zeros(3,1)];

158 end

159 end

160 %****************************************

161

162 Ncomm = zeros(3,3 * lenHarm+1,12);

163

164 %****************************************

165 for j = 1:12

166 for i = 1:2:2 * lenHarm

167 Ncomm(1:end,i:i+1,j) = Ncomm coeff(1:end,1:2,j);

168 end

169 end

170 %****************************************

171 %****************************************

172 for j = 1:12

173 for i = 2 * lenHarm+1:2:2 * lenHarm+lenHarm+1

174 Ncomm(1:end,i:i+1,j) = [Ncomm coeff(1:end,3,j),zeros(3,1)];

175 end

Page 235: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 229

176 end

177 %****************************************

178

179 Omegat = zeros(3 * lenHarm+1,3 * lenHarm+1);

180

181 count = −h;

182 for i = 1:2:2 * lenHarm

183 Omegat(i:i+1,i:i+1) = [0 −count;count 0];

184 count = count + 1;

185 end

186 count = 0;

187 for i = 2 * lenHarm+1:2:2 * lenHarm+lenHarm

188 Omegat(i:i+1,i:i+1) = [0 −count;count 0];

189 count = count + 1;

190 end

191

192 Ahat = zeros(3+3 * lenHarm+1+3 * lenHarm+1);

193

194 H = zeros(3 * lenHarm+1,3);

195 Mm = Omegat;

196

197 count = 1;

198 for i = h: −1: −h

199 H(count:count+1,1:2) = 1/2/pi * [cos(2 * i * pi) sin(2 * i * pi); ...

200 −sin(2 * i * pi) cos(2 * i * pi)];

201 count = count + 2;

202 end

203

204 for i = count:2:count+2 * h+2−1

205 H(i,3) = 1/Tac;

206 end

207

208 Ahat(3+3 * lenHarm+1+1:end,1:3) = H;

209 Ahat(4:3+3 * lenHarm+1,4:3+3 * lenHarm+1) = Omegat;

210 Ahat(3+3 * lenHarm+1+1:end,3+3 * lenHarm+1+1:end) = Mm;

rotMtx.m

Page 236: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 230

1 function Zi arr = rotMtx(lenHarm,h,gamma,phase,Zi)

2

3 RotationMatrix = zeros(3 * lenHarm+1,3 * lenHarm+1,13);

4 Zi arr = zeros(3 * lenHarm+1,13);

5

6 gammasum = 0;

7

8 for i = 1:13

9 count = 1;

10 for j = −h:1:h

11 RotationMatrix(count:count+1,count:count+1,i) = ...

12 [cos(j * (gamma sum−phase)), −sin(j * (gamma sum−phase)); ...

13 sin(j * (gamma sum−phase)),cos(j * (gamma sum−phase))];

14 count = count + 2;

15 end

16 for j = 0:h

17 RotationMatrix(count:count+1,count:count+1,i) = ...

18 [cos(j * (gamma sum−phase)), −sin(j * (gamma sum−phase)); ...

19 sin(j * (gamma sum−phase)),cos(j * (gamma sum−phase))];

20 count = count + 2;

21 end

22 if i < 13

23 gammasum = gammasum + gamma(i);

24 end

25 Zi arr(1:end,i) = RotationMatrix(1:end,1:end,i) * Zi;

26 end

deriv rotMtx.m

1 function derivRotation = deriv rotMtx(lenHarm,h,gamma,phase)

2

3 maxPos = 3* lenHarm+1;

4 derivRotation = zeros(maxPos,maxPos,13);

5 gammasum = 0;

6

7 for i = 1:13

Page 237: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 231

8 count = 1;

9 for j = −h:1:h

10 derivRotation(count:count+1,count:count+1,i) = ...

11 [ −j * sin(j * (gamma sum−phase)), −j * cos(j * (gamma sum−phase)); ...

12 j * cos(j * (gamma sum−phase)) −j * sin(j * (gamma sum−phase))];

13 count = count + 2;

14 end

15 for j = 0:1:h

16 derivRotation(count:count+1,count:count+1,i) = ...

17 [ −j * sin(j * (gamma sum−phase)), −j * cos(j * (gamma sum−phase)); ...

18 j * cos(j * (gamma sum−phase)) −j * sin(j * (gamma sum−phase))];

19 count = count + 2;

20 end

21 if i < 13

22 gammasum = gammasum + gamma(i);

23 end

24 end

calcM.m

1 function M = calcM(Mi,Vab coeff,Mt,Ap,Np,Zi arr,Ts,lenHarm,L,R,Ldc,Rdc)

2

3 M = zeros(25,1);

4 for i = 1:12

5 At = Mt(1:3,1:3,i);

6 Nt = Mt(1:3,4:end,i);

7 M(i) = 0 −Mi(i,1:end) * (At * inv(eye(3,3) −Ap(1:3,1:3,i)) * ...

8 Np(1:3,1:end,i)+Nt) * Zi arr(1:end,i);

9 end

10

11 constMtx = zeros(3,3 * lenHarm+1);

12 for i = 1:2

13 for j = i:2:2 * lenHarm

14 constMtx(i,j) = 1;

15 end

16 end

17 for i = 1:2:lenHarm+1

Page 238: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 232

18 constMtx(3,2 * lenHarm+i) = 1;

19 end

20

21 for i = 1:13

22 Idc = [0 0 1] * (inv(eye(3,3) −Ap(1:3,1:3,Ts(i))) * ...

23 Np(1:3,1:end,Ts(i))) * Zi arr(1:end,i);

24

25 M(i+12) = 0 − ((L * (4 * R+Rdc)/(4 * L+Ldc) −R) * Idc+ ...

26 [Vab coeff(Ts(i),1:end),L/(4 * L+Ldc)] * constMtx * Zi arr(1:end,i));

27 end

solveMt.m

1 function [Mt dMt dmu] = solveMt(lenHarm,Acomm,Ncomm,Omegat,expmCommMu)

2

3 maxPos = 3+3* lenHarm+1;

4 dMt dmu = zeros(maxPos,maxPos,12);

5 Mt = zeros(maxPos,maxPos,12);

6 Mcomm = zeros(maxPos,maxPos);

7

8 for i = 1:12

9 Mcomm(1:3,1:3) = Acomm(1:end,1:end,i);

10 Mcomm(1:3,4:end) = Ncomm(1:end,1:end,i);

11 Mcomm(4:end,4:end) = Omegat;

12

13 Mt(1:end,1:end,i) = expmCommMu(1:maxPos,1:maxPos,i);

14 dMt dmu(1:end,1:end,i) = Mcomm * Mt(1:end,1:end,i);

15 end

solveMp.m

1 function [Mp dMpmu dMpgamma Ap Np] = solveMp(lenHarm,Acond,Ncond, ...

2 Acomm,Ncomm,Omegat,expmCondMuPi 3,expmCondMu,expmCommMu,Ts)

Page 239: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 233

3

4 maxPos = 3+3* lenHarm+1;

5 dMp dmu = zeros(maxPos,maxPos,12,12);

6 dMp dgamma = zeros(maxPos,maxPos,12,12);

7 Mp = zeros(maxPos,maxPos,12);

8 Ap = zeros(3,3,12);

9 Np = zeros(3,3 * lenHarm+1,12);

10 dMpgamma = zeros(length(Mp),length(Mp),12,12);

11 dMpmu = zeros(length(Mp),length(Mp),12,12);

12 Mcond = zeros(maxPos,maxPos);

13 Mcomm = zeros(maxPos,maxPos);

14

15 for j = 1:12

16 Mp(1:end,1:end,j) = eye(maxPos,maxPos);

17 for k = 1:12

18 dMp dmu(1:end,1:end,j,k) = eye(maxPos,maxPos);

19 dMp dgamma(1:end,1:end,j,k) = eye(maxPos,maxPos);

20 end

21 end

22

23 %solving for Mp and dMp and Ap and Np

24 for i = 1:12

25 for j = 0:11

26 Mcond(1:3,1:3) = Acond(1:end,1:end,Ts(i+j));

27 Mcond(1:3,4:end) = Ncond(1:end,1:end,Ts(i+j));

28 Mcond(4:end,4:end) = Omegat;

29 Mcomm(1:3,1:3) = Acomm(1:end,1:end,Ts(i+j));

30 Mcomm(1:3,4:end) = Ncomm(1:end,1:end,Ts(i+j));

31 Mcomm(4:end,4:end) = Omegat;

32

33 Mp(1:end,1:end,i) = ...

expmCondMuPi 3(1:maxPos,1:maxPos,Ts(j+i)) * ...

34 expmCondMu(1:maxPos,1:maxPos,Ts(j+i)) * ...

35 expmCommMu(1:maxPos,1:maxPos,Ts(i+j)) * Mp(1:end,1:end,i);

36

37 for k = 1:12

38 if k == (j+1)

39 dMp dmu(1:end,1:end,k,i) = ...

40 expmCondMuPi 3(1:maxPos,1:maxPos,Ts(j+i)) * ...

41 (−Mcond* expmCondMu(1:maxPos,1:maxPos,Ts(i+j))+ ...

42 expmCondMu(1:maxPos,1:maxPos,Ts(i+j)) * Mcomm)* ...

Page 240: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 234

43 expmCommMu(1:maxPos,1:maxPos,Ts(i+j)) * ...

44 dMp dmu(1:end,1:end,k,i);

45

46 dMp dgamma(1:end,1:end,k,i) = Mcond * ...

47 expmCondMuPi 3(1:maxPos,1:maxPos,Ts(j+i)) * ...

48 expmCondMu(1:maxPos,1:maxPos,Ts(j+i)) * ...

49 expmCommMu(1:maxPos,1:maxPos,Ts(i+j)) * ...

50 dMp dgamma(1:end,1:end,k,i);

51 else

52 dMp dmu(1:end,1:end,k,i) = ...

53 expmCondMuPi 3(1:maxPos,1:maxPos,Ts(j+i)) * ...

54 expmCondMu(1:maxPos,1:maxPos,Ts(j+i)) * ...

55 expmCommMu(1:maxPos,1:maxPos,Ts(i+j)) * ...

56 dMp dmu(1:end,1:end,k,i);

57

58 dMp dgamma(1:end,1:end,k,i) = ...

59 expmCondMuPi 3(1:maxPos,1:maxPos,Ts(j+i)) * ...

60 expmCondMu(1:maxPos,1:maxPos,Ts(j+i)) * ...

61 expmCommMu(1:maxPos,1:maxPos,Ts(i+j)) * ...

62 dMp dgamma(1:end,1:end,k,i);

63 end

64 end

65 end

66 end

67

68 for i = 0:11

69 for j = 1:12

70 dMpgamma(1:end,1:end,Ts(j+i),i+1) = ...

dMp dgamma(1:end,1:end,j,i+1);

71 dMpmu(1:end,1:end,Ts(j+i),i+1) = dMp dmu(1:end,1:end,j,i+1);

72 end

73 end

74 for i = 1:12

75 Ap(1:end,1:end,i) = Mp(1:3,1:3,i);

76 Np(1:end,1:end,i) = Mp(1:3,4:end,i);

77 end

solveFCM.m

Page 241: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 235

1 function [FCM expmCondMuPi 3 expmCondMu expmCommMu Hp Apmat Np mat ...

Qp]= ...

2 solveFCM(lenHarm,Ahat,Acomm,Ncomm,Acond,Ncond,mu,ga mma)

3

4 arrLen = 3+3 * lenHarm+1+3 * lenHarm+1;

5

6 expmCommMu = zeros(arrLen,arrLen,12);

7 expmCondMu = zeros(arrLen,arrLen,12);

8 expmCondMuPi 3 = zeros(arrLen,arrLen,12);

9

10 Ahat mod = Ahat;

11 Phi = eye(arrLen,arrLen);

12 for i = 1:12

13 Ahat mod(1:3,1:3+3 * lenHarm+1) = ...

[Acomm(1:end,1:end,i),Ncomm(1:end,1:end,i)];

14 expmCommMu(1:end,1:end,i) = expm(Ahat mod* mu(i));

15 Ahat mod(1:3,1:3+3 * lenHarm+1) = ...

[Acond(1:end,1:end,i),Ncond(1:end,1:end,i)];

16 expmCondMu(1:end,1:end,i) = expm( −Ahat mod* mu(i));

17 expmCondMuPi 3(1:end,1:end,i) = expm(Ahat mod* gamma(i));

18

19 Phi = expmCondMuPi 3(1:end,1:end,i) * ...

20 expmCondMu(1:end,1:end,i) * expmCommMu(1:end,1:end,i) * Phi;

21 end

22

23 Hp = Phi(4+3 * lenHarm+1:end,1:3);

24 Ap mat = Phi(1:3,1:3);

25 Np mat = Phi(1:3,4:3 * lenHarm+4);

26 Qp = Phi(3 * lenHarm+4+1:end,4:3 * lenHarm+4);

27

28 FCM = Hp* (inv(eye(3,3) −Ap mat)) * Np mat+Qp;

calcJ.m

1 function J = calcJ(Mi,Vab coeff,Mt,dMt dmu,dMpmu,dMpgamma,Ap,Np, ...

2 Zi arr,Zi,Ts,lenHarm,L,R,Ldc,Rdc,derivRotation)

Page 242: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 236

3

4 J11 = zeros(12,12);

5 J12 = zeros(12,13);

6 J21 = zeros(13,12);

7 J22 = zeros(13,13);

8

9 constMtx = zeros(3,3 * lenHarm+1);

10 for i = 1:2

11 for j = i:2:2 * lenHarm

12 constMtx(i,j) = 1;

13 end

14 end

15 for i = 1:2:lenHarm+1

16 constMtx(3,2 * lenHarm+i) = 1;

17 end

18

19 for i = 1:12

20 for j = 1:12

21 %Entries in Quad. (1,1)

22 J11(i,j) = ...

calcJ11(lenHarm,Ap(1:end,1:end,i),Np(1:end,1:end,i) , ...

23 Mt(1:end,1:end,i),dMt dmu(1:end,1:end,i), ...

24 dMpmu(1:end,1:end,j,i),Zi arr(1:end,i),Mi(i,1:end),i −j);

25 if j < i

26 condMtx = derivRotation(1:end,1:end,i);

27 else

28 condMtx = zeros(3 * lenHarm+1,3 * lenHarm+1);

29 end

30 %Entries in Quad. (1,2)

31 J12(i,j) = calcJ12(Ap(1:end,1:end,i),Np(1:end,1:end,i ), ...

32 Mt(1:end,1:end,i),dMpgamma(1:end,1:end,j,i), ...

33 Zi arr(1:end,i),Zi,Mi(i,1:end),condMtx);

34 end

35 condMtx = derivRotation(1:end,1:end,i);

36 J12(i,13) = ...

calcJ13(Mt(1:end,1:end,i),Ap(1:end,1:end,i),Np(1:en d,1:end,i), ...

37 Zi,Mi(i,1:end),condMtx);

38 end

39 for i = 1:13

40 for j = 1:12

41 %Entries in Quad. (2,1)

Page 243: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 237

42 J21(i,j) = ...

calcJ21(Ap(1:end,1:end,Ts(i)),Np(1:end,1:end,Ts(i)) , ...

43 dMpmu(1:end,1:end,j,Ts(i)),Zi arr(1:end,i),L,R,Ldc,Rdc);

44 if j < i

45 condMtx = derivRotation(1:end,1:end,i);

46 else

47 condMtx = zeros(3 * lenHarm+1,3 * lenHarm+1);

48 end

49 J22(i,j) = ...

calcJ22(Ap(1:end,1:end,Ts(i)),Np(1:end,1:end,Ts(i)) , ...

50 dMpgamma(1:end,1:end,j,Ts(i)),Zi arr(1:end,i),Zi, ...

51 condMtx,[Vab coeff(Ts(i),1:end),L/(4 * L+Ldc)] * constMtx,L,R,Ldc,Rdc);

52 end

53 condMtx = derivRotation(1:end,1:end,i);

54 J22(i,13) = calcJ23(Ap(1:end,1:end,Ts(i)),Np(1:end,1: end,Ts(i)), ...

55 Zi,condMtx,[Vab coeff(Ts(i),1:end),L/(4 * L+Ldc)] * constMtx,L,R,Ldc,Rdc);

56 end

57

58 J = [J11,J12;J21,J22];

calcJ11.m

1 function J11 entry = calcJ11(lenHarm,Ap,Np,Mt,dMt,dMp,Zi arr,Mi,imj)

2

3 At = Mt(1:3,1:3);

4 if imj == 0

5 dAt = dMt(1:3,1:3);

6 dNt = dMt(1:3,4:end);

7 else

8 dAt = zeros(3,3);

9 dNt = zeros(3,3 * lenHarm+1);

10 end

11 dAp = dMp(1:3,1:3);

12 dNp = dMp(1:3,4:end);

13

14 dInvImMtx = get dInvImMtx(Ap,dAp);

15 InvImMtx = inv(eye(3) −Ap);

Page 244: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 238

16

17 J11 entry = ...

Mi * (dAt * InvImMtx * Np+At * InvImMtx * dNp+At * dInvImMtx * Np+dNt) * Zi arr;

calcJ12.m

1 function J12 entry = calcJ12(Ap,Np,Mt,dMp,Zi arr,Zi,Mi,dRotation)

2 At = Mt(1:3,1:3);

3 Nt = Mt(1:3,4:end);

4 dAp = dMp(1:3,1:3);

5 dNp = dMp(1:3,4:end);

6

7 dInvImMtx = get dInvImMtx(Ap,dAp);

8 InvImMtx = inv(eye(3) −Ap);

9

10 J12 entry = Mi * (At * InvImMtx * dNp+At * dInvImMtx * Np) * Zi arr+Mi * (At * ...

11 InvImMtx * Np+Nt) * dRotation * Zi;

calcJ13.m

1 function J13 entry = calcJ13(Mt,Ap,Np,Zi,Mi,dRotation)

2

3 At = Mt(1:3,1:3);

4 Nt = Mt(1:3,4:end);

5 InvImMtx = inv(eye(3) −Ap);

6

7 J13 entry = Mi * (At * InvImMtx * Np+Nt) * ( −dRotation) * Zi;

calcJ21.m

Page 245: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 239

1 function J21 entry = calcJ21(Ap,Np,dMp,Zi arr,L,R,Ldc,Rdc)

2

3 dAp = dMp(1:3,1:3);

4 dNp = dMp(1:3,4:end);

5

6 dInvImMtx = get dInvImMtx(Ap,dAp);

7 InvImMtx = inv(eye(3) −Ap);

8

9 J21 entry = (L * (4 * R+Rdc)/(4 * L+Ldc) −R) * [0 0 1] * (dInvImMtx * Np+InvImMtx * ...

10 dNp) * Zi arr;

calcJ22.m

1 function J22 entry = ...

calcJ22(Ap,Np,dMp,Zi arr,Zi,dRotation,constMtx,L,R,Ldc,Rdc)

2

3 dAp = dMp(1:3,1:3);

4 dNp = dMp(1:3,4:end);

5

6 dInvImMtx = get dInvImMtx(Ap,dAp);

7 InvImMtx = inv(eye(3) −Ap);

8

9 J22 entry = (L * (4 * R+Rdc)/(4 * L+Ldc) −R) * [0 0 ...

1] * ((dInvImMtx * Np+InvImMtx * ...

10 dNp) * Zi arr+InvImMtx * Np* dRotation * Zi)+constMtx * dRotation * Zi;

calcJ23.m

1 function J23 entry = calcJ23(Ap,Np,Zi,dRotation,constMtx,L,R,Ldc,R dc)

2

3 InvImMtx = inv(eye(3) −Ap);

4

Page 246: Harmonic Models of Common Converter Topologies for Accurate Harmonic Analysis of Distribution

Appendix B. Matlab Source Code 240

5 J23 entry = (L * (4 * R+Rdc)/(4 * L+Ldc) −R) * [0 0 ...

1] * InvImMtx * Np* ( −dRotation) * Zi+ ...

6 constMtx * ( −dRotation) * Zi;