55
UPTEC E12003 Examensarbete 30 hp Februari 2012 Power grid integration using Kalman filtering Magnus Djerf Påbyggnadsprogrammet till civilingenjörsexamen i elektroteknik Master Programme in Electrical Engineering

Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

UPTEC E12003

Examensarbete 30 hpFebruari 2012

Power grid integration using Kalman filtering

Magnus Djerf

Påbyggnadsprogrammet till civilingenjörsexamen i elektroteknikMaster Programme in Electrical Engineering

Page 2: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas
Page 3: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Teknisk- naturvetenskaplig fakultet UTH-enheten Besöksadress: Ångströmlaboratoriet Lägerhyddsvägen 1 Hus 4, Plan 0 Postadress: Box 536 751 21 Uppsala Telefon: 018 – 471 30 03 Telefax: 018 – 471 30 00 Hemsida: http://www.teknat.uu.se/student

Abstract

Power grid integration using Kalman filtering

Magnus Djerf

Renewable power sources with a relatively uneven or constant DC power productionrequire synchronization methods to work with the current utility power grid. Thesolution to this synchronization problem has been solved with semiconductor basedconverters and advanced switching algorithms. To enable switching algorithms thatwork well with the grids amplitude, phase-shift and frequency, the current waveformhas to be measured and estimated. There are many sources of noise that will add distortion of the current waveform,making its appearance less similar to the grids. The distorted measurement affects theaccuracy of the converters negatively. Therefore, using a filter algorithm to attenuatethe grid noise is required. This project uses a Kalman filter with the aim to decrease the noise and estimatethe current phase shift for a three phase power-grid. To achieve reliable and fast calculation, implementing the Kalman filter within a FPGAwere done.The project contains results from both simulated MATLAB data and the FPGAs realtime data. The method was able to estimate the grid within a few Hz frequencydeviation and enable some noise reduction. For larger degree of harmonic distortionduring steady state operation, the Kalman filter could remove more of the harmonicdistortion. Limits and differences with MATLAB are discussed for the FPGAimplemented Kalman filter.

Tryckt av: Ångströmlaboratoriet UppsalaISSN: 1654-7616, UPTEC E12003Examinator: Nora MassziÄmnesgranskare: Tomas OlofssonHandledare: Remya Krishna

Page 4: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

AcknowledgementsFirst I would like to thank the Division of Electricity for providing

equipment to make this project possible. I express my gratitude to every-one involved but especially my supervisor Remya Krishna and Deepak Ela-malayil Soman. Their support and encouragement meant a lot throughoutthe project. I would also like to thank Johan Abrahamsson for his helpand valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas Olofsson for his patienceand help to improve the written material for this thesis. I would also liketo thank my co-worker Bengi Tolunay for her help to improve the moodduring hours of code compilation. Many thanks to family and friends fortheir help, support and positive attitude.

Page 5: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Contents1 Introduction and Overview 8

1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.2 Project overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 91.3 Report Organization . . . . . . . . . . . . . . . . . . . . . . . . . 10

2 Noise Sources and Grid Changes 112.1 Error Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.2 Quantization Noise . . . . . . . . . . . . . . . . . . . . . . . . . . 112.3 Thermal Noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122.4 Transient Noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122.5 Harmonic Noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122.6 Frequency Deviation . . . . . . . . . . . . . . . . . . . . . . . . . 13

3 Kalman States and Theory 143.1 State Space form . . . . . . . . . . . . . . . . . . . . . . . . . . . 143.2 Kalman Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153.3 Initial values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.4 Three Phase extrapolation . . . . . . . . . . . . . . . . . . . . . . 17

4 MATLAB Simulation 194.1 Experimental setup . . . . . . . . . . . . . . . . . . . . . . . . . . 194.2 Results MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . 21

4.2.1 Simulation 1 . . . . . . . . . . . . . . . . . . . . . . . . . 214.2.2 Simulation 2 . . . . . . . . . . . . . . . . . . . . . . . . . 224.2.3 Simulation 3 . . . . . . . . . . . . . . . . . . . . . . . . . 244.2.4 Simulation 4 . . . . . . . . . . . . . . . . . . . . . . . . . 254.2.5 Simulation 5 . . . . . . . . . . . . . . . . . . . . . . . . . 27

4.3 Conclusions from MATLAB simulations . . . . . . . . . . . . . . 28

5 Hardware and Program interface 295.1 FPGA(Field Programmable Gate Array) . . . . . . . . . . . . . . 295.2 Chassi (compactRIO 9114) . . . . . . . . . . . . . . . . . . . . . 305.3 Real-Time Controller . . . . . . . . . . . . . . . . . . . . . . . . . 315.4 ADC and DAC Modules . . . . . . . . . . . . . . . . . . . . . . . 32

5.4.1 NI 9205 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325.4.2 NI 9264 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

5.5 Labview interface . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

6 Implementation 346.1 Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

7 Results obtained with the FPGA implementation 377.1 Experiment details . . . . . . . . . . . . . . . . . . . . . . . . . . 377.2 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

7.2.1 Simulation 1 . . . . . . . . . . . . . . . . . . . . . . . . . 387.2.2 Simulation 2 . . . . . . . . . . . . . . . . . . . . . . . . . 397.2.3 Simulation 3 . . . . . . . . . . . . . . . . . . . . . . . . . 417.2.4 Simulation 4 . . . . . . . . . . . . . . . . . . . . . . . . . 437.2.5 Simulation 5 . . . . . . . . . . . . . . . . . . . . . . . . . 44

5

Page 6: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

7.3 FPGA Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 46

8 Evaluation and Conclusion 478.1 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478.2 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488.3 Scope for future work . . . . . . . . . . . . . . . . . . . . . . . . 48

A MATLAB Code 50

B Labview Design 51

6

Page 7: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

List of Figures1 Project Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Signal Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Flowchart of the Kalman filter . . . . . . . . . . . . . . . . . . . 174 Random noise influenced measurement signal. . . . . . . . . . . . 215 Random noise influenced measurement signal (Spectrum) . . . . 226 Harmonic Additive Noise 15% 10% and 5% . . . . . . . . . . . . 237 Harmonic Additive Noise 15% 10% 5% (Spectrum) . . . . . . . . 238 Three phase extrapolation . . . . . . . . . . . . . . . . . . . . . . 249 Three phase extrapolation (Spectrum) . . . . . . . . . . . . . . . 2510 Constant deviating frequency 53 Hz . . . . . . . . . . . . . . . . 2611 Constant deviating frequency 53 Hz (Spectrum) . . . . . . . . . . 2612 Constant deviating frequency 47 Hz . . . . . . . . . . . . . . . . 2713 Constant deviating frequency 47 Hz (Spectrum) . . . . . . . . . . 2814 Example of FPGA connections . . . . . . . . . . . . . . . . . . . 2915 CompactRIO chassi . . . . . . . . . . . . . . . . . . . . . . . . . 3116 Real-Time Controller . . . . . . . . . . . . . . . . . . . . . . . . . 3217 Memory Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . 3418 Labview Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3519 FPGA Harmonics Generation . . . . . . . . . . . . . . . . . . . . 3820 Steady State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3921 Steady State (Spectrum) . . . . . . . . . . . . . . . . . . . . . . . 3922 Harmonic at 40% . . . . . . . . . . . . . . . . . . . . . . . . . . . 4023 Harmonic at 40% (Spectrum) . . . . . . . . . . . . . . . . . . . . 4124 Decreasing Phase 46.97Hz . . . . . . . . . . . . . . . . . . . . . . 4225 Decreasing Phase 46.97Hz (Spectrum) . . . . . . . . . . . . . . . 4226 Increasing Phase 52.84Hz . . . . . . . . . . . . . . . . . . . . . . 4327 Increasing Phase 52.84Hz (Spectrum) . . . . . . . . . . . . . . . 4428 Harmonic additive noise third, fifth and seventh . . . . . . . . . . 4529 Harmonic additive noise in third, fifth and seventh(Spectrum) . . 45

7

Page 8: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

1 Introduction and Overview

1.1 IntroductionRenewable power sources have a larger influence in modern society where largerparts of the electrical power comes from such renewable sources. With gen-erator designs optimized for the local power resources, a difference from thetraditional rotating synchronous machines can be seen. The power producedmight not have the same frequency, phase and amplitude as the rest of thepower grid. This demands synchronization methods to connect these renewablesources. Converters based on semiconductor switches that handles high power isone solution to solve the synchronization problem. By timing the switching forthe converters to recreate a grid friendly current, a synchronization between thesource and utility grid can be made possible. Most power electronics semicon-ductor switches involved with grid synchronization, uses a Phase Locked Loop(PLL), that has limits regarding frequency change and noise sensitivity. Thisproject focus on a grid estimation based on a Kalman filter instead of the PLLsince no prefiltetering is required.One of the purposes with this work, is to evaluate how many Hz the grid candeviate from a steady state case and still give reasonable noise reduction andfrequency adaption. The other main purpose of this report, is to give a moredetailed evaluation regarding how good the method works during steady statewith a small frequency change and higher degree of harmonic noise.

8

Page 9: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

1.2 Project overviewWhile this report mainly handles the Kalman filter and its input-output re-lations, the whole perspective described in Figure 1 is important. The mainobjective is to produce an Alternating Current (AC), in-phase with the grid,based upon an uneven or constant Direct Current (DC) power production froma renewable power source. The renewable power source which can not be con-nected directly to the grid has to be converted to a constant DC level throughrectifier bridges and capacitor banks. In case the renewable power source alreadyproduces a direct current, the rectifiers and capacitor blocks can be neglected.

Meeting the demands of the grid synchronization, phase information in the cur-rent power grid is important. To measure the grid within a reasonable voltagerange, a potential divider downscales the voltage level. This potential dividerhas been named sensor in the figure below. The downscaled version of the powersignal can then pass through the Analog to Digital converter (ADC) for a digitalrepresentation of the grid voltage.

Inside the FPGA application, the current phase shift of the grid voltage be-comes estimated through the Kalman filter while attenuating disturbances. Toensure unity power factor, or reactive power production the current controllerspurpose is to produce a current depending on the utility demand. The FPGAalso contains a Space Vector Modulation (SVM) block that generate pulses fora high voltage, transistor based, inverter[1]. The input for the SVM shouldbe a three phase sinusoid with the same phase shift as the grid and this re-quires small time-steps between data points. With the in-phase, relatively noisefree grid representation, the SVM produces logical output corresponding to thethree phase grid information. The logical output will decide in which order thetransistor switches within the inverter should be on or off and for how long[2].With a constant DC supply voltage to the inverter from the renewable powersource, the resulting waveform will be high power pulses with different length,that needs filtering to take the smooth sinusoidal shape. The final filtered ver-sion can then pass a Power Common Connection (PCC) to become integratedwith the power grid.

9

Page 10: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 1: Project Overview

1.3 Report OrganizationChapter one covers the introductional part and the overview of the project andfurther explains the macroscopic structure. The Kalman filters input and thesources of error involved is covered in Chapter 2 along with a brief explana-tion of natural frequency variation. Chapter 3 explains State space form of avoltage grid signal, Kalman filter theory and how a three phase signal can beestimated with only one measured phase. The same theory used in chapter 3 isimplemented with MATLAB code and evaluated in chapter 4.

Chapter 5 gives a brief hardware and software description with focus on theequipment surrounding the FPGA and software interface used.

Chapter 6 contains the FPGA implemented design.The seventh chapter gives the experimental details and practical results

along with a brief section that highlights important facts. The final chapterdiscuss and concludes the results with suggestion on scope for future work.

10

Page 11: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

2 Noise Sources and Grid ChangesThis chapter involves what kind of errors the measured grid voltage can expectonce it passes the ADC, mentioned in previous chapter. Additional informationregarding the natural frequency variation will also be explained

2.1 Error SourcesAssuming that the ADC samples fast enough to meet the Nyquist samplingCriteria, a valid representation of the grid voltage is given in a digital format.There are several sources that can produce a voltage value that deviates, fromwhat is expected, in the measured grid voltage. Different physical phenomenacauses varying sources of error, both in appearance and amount of power. Bymodeling these sources as a time discrete additive component, a simple errormodel is created, see figure 2. The aim of this model, is to describe a correctvoltage value s(t)(signal) with varying sources of additional noise n(t). Thefollowing sections will cover different types of noise sources involved for an ADconverted voltage signal.

Figure 2: Signal model with a signal of interest s(t) and an additive noise termn(t).

2.2 Quantization NoiseWhen an analog signal passes through an ADC, it might not be representedcorrectly. If the incoming signal exceeds the maximum voltage value availableon the converter, the representation will be the highest value available. Theresolution and the nominal input ranges are some of the main reason for Quan-tization errors. Nominal input ranges depends on the ADC and the user shouldmake sure that the input analog signal stays within this range.

Resolution is decided by the amount of quantization levels that exist in therange and will represent the digitalized version of the signal in terms of a con-stant values. Higher resolution will produce less error and better representationof the signal in a digital format. When the current value to be sampled, fallsbetween two quantization levels, it will be incorrect by maximum ∆x

2 (where

11

Page 12: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

∆x is the quantization intervals range). By having more quantization levels,the ∆x decreases and also the amount of error in every sample.

2.3 Thermal NoiseThermal Noise is a material based issue that exist in every electrical applicationand is caused by random motion of electrons within a conductor. The noise isalmost constant for the whole spectrum, exists in every frequency, and has anapproximate normal distribution. While the thermal noise is small in respect topower within the actual measured voltage value, it might still affect the value tosome degree. Noise power is described in (1) where kb is Boltzmann constant,T is temperature in Kelvin and ∆f , the bandwidth.

Pn = kBT∆f (1)

2.4 Transient NoiseSudden electrical discharge such as load disconnection and lightning strikes af-fects the grid and is another source of error, called transients. Transients can bedivided into two categories, impulsive and oscillatory[3]. In general the transientbased noise has short duration but high power. The oscillative power can have asudden low frequent sinusoidal shape, appearing within the grid representationsignal.

2.5 Harmonic NoiseElectrical components within the grid can produce a certain amount of har-monic distortion. The sources from which this noise is produced, is related tonon-linear loads. This type of load is often related to different types of powerconverters such as rectifiers. There is also a high degree of harmonic distortioncoming from fluorescent based loads.

When the grid current passes through non-linear loads, the load might notdraw a current with a linear sinusoidal waveform. By assuming that the sinu-soidal waveform follows the additive error model mentioned above, the correctgrid voltage will have additional noise. This noise, consists of multiple sinusoidalwaveforms based on integer multiples of the fundamental frequency 50 Hz. Forhigher degrees of harmonic distortion, the actual grid voltage representation willloose its original shape. The power grid can absorb parts of the harmonic noisebut some degree of distortion could be expected. Higher order harmonics aresignificantly attenuated by the power system and can therefore be neglected [3].By adding the power contribution of each individual harmonic Pn and divideit with the power present in the fundamental sinusoid, P1, a measurement thatreflects the amount of harmonic distortion is given(2). This measurement iscalled Total Harmonic Distortion (THD). For the Swedish power grid, the THDshould not exceed 4% over time nor exceed the individual guideline for eachharmonic according to the Swedish Power Grid [4].

THD =

∞∑n=2

Pn

P1(2)

12

Page 13: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

2.6 Frequency DeviationFrequency within the power grid depends on the balance between the loadsconnected and the generators present within the system [3]. Variation outsideof +/- 0.1 Hz is considered to be faulty and may be deduced from abruptchanges in either load or generation part of the system. The worst cases forthe frequency variation occurs when large power units are disconnected and thefrequency drop could be 0.05 Hz/s which would mean 0.1 HZ deviation withintwo seconds [5]. When additional generators are connected an increase of 0.025Hz/s can be expected which result in 0.1 Hz change within four seconds. Thesame frequency drop and increase can be expected for a system during normalsteady state operations but within the range of +/-0.1 Hz.

13

Page 14: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

3 Kalman States and TheoryThis chapter covers the State space form for a grid representation and relatedKalman filter theory with goal to fit the measured voltage of the grid.

3.1 State Space formMost signal input and output relations can be described by a difference equa-tion, but there are some advantages by choosing a state space form. Dependingon the state representation, the future behavior of the system can be estimated.Everything based upon that the states describes every important physical phe-nomena in the system. The state space form has the advantage of being veryflexible way of describing the system as well as less sensitive to errors[6].

For a power grid voltage signal, the signals behavior can only be on a sinu-soidal form (3) and is denoted S1(t). S1(t) is the current time discrete voltagevalue given a certain amplitude A, angular frequency w and phase shift ϕ. Thethree phase voltage signals (4-5) are only mentioned for future reference andwill not be included in the coming state space form.Since the sinusoidal signal can be described with three components, amplitude,angular frequency and phase, the states for this model have to reflect thesecomponents in some way.

S1(t) = A ∗ sin(wt+ ϕ) (3)

S2(t) = A ∗ sin(wt+ ϕ+2π

3) (4)

S3(t) = A ∗ sin(wt+ ϕ+4π

3) (5)

Through an angle transformation formula[8], the extended version of (3) re-sult in (6). Making the states linearly dependent with respect to phase andamplitude from the extended voltage signal in (6) result in two states(7-8). As-suming the frequency is relatively constant over time, the signal representationcan be described through an amplitude and phase shift.

S1(t) = A ∗ cos(ϕ) cos(wt)−A ∗ sin(ϕ) sin(wt) (6)

x1 = A ∗ cos(ϕ) (7)

x2 = A ∗ sin(ϕ) (8)

By defining x1 and x2 as the state variables that should be estimated ineach new time step. Under the assumption that no delay occurs,(9) describesthe state variables with additional noise w(t). This noise represents how muchthe states randomly change over time and also picks up small errors within themodel.To describe the actual voltage signal y(t) with the model for the current statevalues (10) requires a non stationary deterministic vector

[cos(wt) −sin(wt)

].

14

Page 15: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

The uncertainty of the current measurement (10) will be modeled with addi-tional measurement noise v(t). By using this model, the assumption of a con-stant frequency will result in a slightly incorrect model during frequency varia-tion. This gives a state equation(9) whereA =

(1 00 1

)and C =

[cos(wt) −sin(wt)

].

A should not be mistaken for the amplitude related term described in (3-6).[x1(t+ 1)x2(t+ 1)

]=

[1 00 1

] [x1(t)x2(t)

]+ w(t) (9)

y(t) =[cos(wt) −sin(wt)

] [x1(t)x2(t)

]+ v(t) (10)

3.2 Kalman FilterAssuming a system is described in similar time discrete state space form (9-10)there is a filter method available, a so-called Kalman filter. A Kalman filter isa filter method that minimize the mean square error of the states for a givenstate space system. The filter uses a linear regression method to minimize thevariance of the estimation error for the states.A more generally used form to write the state space form is given in (11-12)where x(t) is a column vector containing both states x1(t) and x2(t).State equation

x(t+ 1) = Ax(t) + w(t) (11)

Observation equationy(t) = C(t)x(t) + v(t) (12)

The deterministic part of the model (11) is described in A and describes howthe estimates propagates with time, while the w(t) term is an additive processnoise term explained in the earlier section.In (12), the measured signal can have an additive measurement noise v(t) whichusually is uncorrelated with the process noise present in (11), also explainedin the earlier section. Independence between process and measurement noisecan therefore be assumed. For later use, it is wise to define the measured errorcovariance and the process error covariance respectively R and Q.

From here on forth, the following example notation will be used for thecoming equations. Z(t | t − 1) indicates the Z value in current time, givenmeasurements and estimates up to the previous time step (t− 1).

Prediction error covariance P (t | t − 1) which is minimized in the Kalmanfilter, where the state estimate x(t | t) is based upon measurements and previousstate values given the current time step (t).

P (t | t) = E[(x(t)− x(t | t))(x(t)− x(t | t))T ] (13)

By substituting the state estimates in (13) x(t | t) and x(t) with equation(14) and respectively (11) gives the resulting form (16).

x(t+ 1 | t) = Ax(t | t) (14)

15

Page 16: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

y(t | t) = Cx(t | t) (15)

P (t+ 1 | t) = E[Ax(t) + w(t)−Ax(t | t)][Ax(t) + w(t)−Ax(t | t)]T (16)

With factorization and substitution with (13), the complete form describinghow an estimate transfer to the next time step is given in(17). TheQ term comesfrom the earlier defined covariance of the process noise that affects uncertaintyof the estimates. Equation (17) mainly describes how the estimation of thestates comes out without further information regarding the measured voltagesignal y(t) (12).

P (t+ 1 | t) = AP (t | t)AT +Q (17)

For each iteration a new measurement will produce an estimated output(15) based on the state estimate in the current time y(t + 1 | t) = Cx(t +1 | t). By recreating the estimated grid voltage, it can be compared to theactual measurement y(t), given in the observation equation (12). Subtractingthe actual measurement with the estimated output is called the residuals andin case it goes to zero the estimated voltage value in the current time step ispractically the same as the measured.

The residuals multiplied with a gain K(t) will be a correction term of thenext coming state estimate(19). Kalman gain K(t) (18) updates every iterationand multiplied with the residuals decide how much the uncertainty increase ordecrease from the previous state estimates. The R parameter, corresponding tothe measurement error covariance and its influence will be explained below.The error covariance becomes updated (20) to be used in the coming iteration inthe next time step(17). Figure 3 further explains the time steps for the Kalmanfilter in a flowchart below. The numbers indicates in which order each newiteration executes.

K(t) = AP (t | t− 1)C(t)T [C(t)P (t | t− 1)C(t)′ +R]−1 (18)

x(t | t) = x(t | t− 1) +K(t)[y(t)− y(t | t− 1)] (19)

P (t | t) = P (t | t− 1)−K(t)C(t)P (t | t− 1) (20)

The Q and R parameters in (17) and (18) are design parameters with theorigin in process noise described in (11) and the measurement noise in (12).These parameters will have to consider the incorrect model during frequencyvariation as well as noise related measurements such as the noise sources ex-plained in chapter 2.R is the measurement noise covariance and can be determine based upon prior

16

Page 17: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 3: Flowchart of the Kalman filter

knowledge and measurements. If R is chosen small, there will be more trustin each measurement. If it is the opposite, measurements are considered lesstrustworthy. While the R parameter is easier to predetermine, the Q parameteris more difficult to anticipate, to fit a model. Small values for the Q covari-ance matrix will result in a system with slow adaption speed when the systemchanges but the ability to remove incorrect values. By choosing the parameterhigh, the system reacts faster and relevance of the model decreases. This makesthe filter more trusting regarding singular measured values. The Kalman filtersbalance between a fast system and noise sensitivity based upon both the Q andRs parameters mutual relation[7]. The parameter choice is the only way toaffect the system design and tuning these parameters is important.

3.3 Initial valuesThe initial phase and amplitude information described in the states (7-8) couldhave a phase shift when the first measurement is taken. An initial guess willtherefore not affect the coming results, except for a slightly faster convergencerate in some cases when the values coincidentally are close in the time step.By choosing the initial guess of the error covariance P (t | t) to something large,the model can assume an incorrect value at the beginning, than afterwardsconverge towards the minimum error covariance.

3.4 Three Phase extrapolationThe estimated output y(t | t) represent one phase estimation based on one mea-sured phase. Assuming the three phase power grid system is balanced, formula

17

Page 18: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

(3-4) explains a 120 degrees phase shift between each phase and is a valid ap-proximation.To create additional phase, S2 and S3 that are based on S1, a similar trigono-metric formula used for the linearization(6) can be applied. S1 becomes knownthrough equation(15) and recreating additional phase shifted signals with thecurrent states result in (21-22). The only restriction would be to either knowthe amplitude or keep it constant at 1 volt to ensure correct phase shift.

S2 =[cos(wt) −sin(wt)

] [ cos(120) sin(120)− sin(120) cos(120)

] [x1(t | t)x2(t | t)

](21)

S3 =[cos(wt) −sin(wt)

] [ cos(240) sin(240)− sin(240) cos(240)

] [x1(t | t)x2(t | t)

](22)

18

Page 19: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

4 MATLAB SimulationThis chapter covers some experiments done in MATLAB with the purpose toget an idea of the Kalman filters performance. Another purpose is to see whatdifferent tuning does in respect to frequency deviation and harmonic distortion.

4.1 Experimental setupTo check if the Kalman filter has sufficient performance during steady stateoperation and for frequency variations outside the steady state. The algorithmhas been implemented using the Kalman filter theory explained in the previouschapter through the MATLAB function presented in Appendix A.The Kalman filter function handles a noise corrupted grid signal and return thefiltered version of the same signal based upon the Q and R tuning. For mostof the following results, a sampling rate of 20 kHz has been used but a slowersampling rate of 2 kHz will be used for reference.

To get a better idea how much the harmonics are suppressed, the spectral infor-mation from both the noise influenced grid signal and the Kalman filtered arecompared.The following list shows some of the experimental setups used for the differentsimulations.

• Sampling rate for simulation 1-3 is 20 kHz and 2kHz for simulation 4-5.

• For most experiments below, a fundamental 50 Hz sinusoid with an ampli-tude of 1 Volt, was used. To simulate the steady state frequency variationof +/-0.1 Hz, an increase of 0.002 Hz every new period was used. Thisresult in a 0.1 Hz increase within 1 second. This were done in Simulation1-3.

• Simulation 4-5 uses a constant frequency deviation of either +3 Hz or -3Hz.

• MATLABs randn() function produces normally distributed noise withmean value zero and standard deviation of one. By multiplying this noisewith a gain of 0.02, a 2% noise signal can be added to the fundamental(Simulation 1-3). This additive noise terms purpose in the simulation wereto model higher degree of harmonics as well as thermal noise present.

• In two simulations, the normally distributed gain were 0.04 (4%) insteadof (2%) (Simulation 4-5).

• For simulations containing harmonic distortion, additional sinusoids hasbeen added to the fundamental after multiplication with a gain. 10%harmonic will be a multiplication of 0.1. Thus 10% of the amplitude ofthe fundamental(Simulation 3).

• The harmonics tested in simulation 2 are the first three odd harmonicsstarting from the third at 150 Hz. The gain multiplication are 0.15, 0.1and 0.05 representing the third, fifth, and seventh.

19

Page 20: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

• Simulation 3 is the only simulation that shows the additional two recreatedgrid phases based on equation (21-22).

• One second of simulation time has been used for all experiments belowbut for a better visual experience only a few periods of data have beenchosen.

• The amplitude spectrum uses all data during the whole simulation time ofone second. For good visual experience, only a small part of the spectrumis shown. This part vary from different simulations and contain at leastthe highest harmonic used.

• For all simulations the initial values for x1(0) = 0 and x2(0) = 0.

• The initial values for the error covariance matrix P (0 | 0) has been chosento an identity matrix

After several experiments with different choices of the process noise covari-ance, Q were chosen to have a diagonal form based upon countless of simulationswhere stability were a problem. If the non-diagonal elements were chosen large,the system had a chance to start to oscillate and not converge towards the cor-rect waveform. Therefore, every simulation will be based upon a diagonal Qmatrix.

Tuning parameters will be shown in each section below in the context whereit is used.For the following figures, the blue signal represent the measured noisy voltagesignal. Simulation 1-2 and 4-5 have a correct voltage signal reference withoutany noise that is used for comparing. This signal is colored green except forfigure 8, where it is black.

20

Page 21: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

4.2 Results MATLAB4.2.1 Simulation 1

The objective of this simulation is to show the performance when thermal noiseand higher harmonics are present in the grid voltage signal. A slight frequencyincrease every new period result in 50.1 Hz deviation within one second. Thussimulating a natural steady state deviation. Figure 4 shows the measured gridsignal, its Kalman estimate and a reference signal without noise. With no phaseshift in the measured grid signal, the frequency increase occurs in time 0.615and 0.635.Figure 5 shows the corresponding spectrum for the Kalman estimate and themeasured grid signal. The following tuning and noise parameters have beenused.

• Process noise parameter Q =

[0.0001 0

0 0.0001

].

• Measurement noise parameter R = 1.5.

• Additive normally distributed noise 2%.

Figure 4: Kalman estimate of a random noise influenced measurement signalcompared with a reference signal without noise. The frequency is increasedevery new period and within steady state deviation.

21

Page 22: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 5: Spectrum of the random noise influenced measurement signal and thecorresponding Kalman estimate.

4.2.2 Simulation 2

Simulation 2 shows the performance of the Kalman filter while under influenceof a large degree of odd harmonics and thermal noise. The same frequencyincrease as previous simulation were used, resulting in a 50.1 Hz deviation afterone second. Figure 6 shows the Kalman estimation with the goal to follow thefundamental sinusoid without noise. The corresponding spectrum figure 7 showshow much each odd harmonic is attenuated by the Kalman filter compared tothe reference grid signal. Red markers have been added on the local largestpeaks in the Kalman filtered spectrum.

• Process noise parameter Q =

[0.00000001 0

0 0.00000001

].

• Measurement noise parameter R = 5.5.

• Additive normally distributed noise 2%.

• Third harmonic 150 Hz at 15%.

• Fifth harmonic 250 Hz at 10%.

• Seventh harmonic 350 Hz at 5%.

22

Page 23: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 6: Kalman estimate for a simulated measured signal containing harmonicadditive noise 15%, 10% and 5% for the first three odd harmonics. The goal ofthe estimate is to follow the dotted reference signal without noise.

Figure 7: Spectrum of the harmonic distorted reference signal and its Kalmanestimate. The attenuation of each of each harmonic can be seen.

23

Page 24: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

4.2.3 Simulation 3

Simulation 3 has the purpose to show the additional two phases of the threephase grid. The thermal noise remains the same as previous while harmonicshave been reduced. Figure 8 shows the Kalman estimated phase and the recre-ated phases based on (21-22). The goal of the Kalman estimate is to followthe measured signal without noise. The measured signal shown in figure 8 hasthe same frequency increase as previously simulations and since the time scaleis close to one, the frequency is close to 50.1. Thus showing that the estimatemanage to follow the measured signal without noise, with some degree of fre-quency deviation. The spectrum shown in figure 9 only compares the measuredsignal with the Kalman estimate. The spectrum also shows a suppressed thirdharmonic.

• Process noise parameter Q =

[0.000001 0

0 0.000001

].

• Measurement noise parameter R = 2.5

• Additive normally distributed noise 2%.

• Third harmonic 150 Hz at 10%.

Figure 8: The three phase extrapolation given one Kalman estimated phase. A10% third harmonic is present in the measured signal

24

Page 25: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 9: Spectrum of the measured reference signal with random noise anda third harmonic present. The spectrum is compared to one of the Kalmanestimated phases.

4.2.4 Simulation 4

Simulation 4 shows how the Kalman filter performs outside steady state witha constant higher frequency at 53 Hz. There is no frequency variation apartfrom the constant higher frequency. The sampling rate has been reduced to 2kHz while the normal distributed noise has been increased to 4%. Figure 10shows how the Kalman estimation of the referense grid signal looks like. Thetuning was choosen to enable the the estimate to follow the reference grid signalinstead of noise suppression and figure 11 shows that it is harder to suppressthe noise with the given tuning.

• Process noise parameter Q =

[0.35 0

0 0.35

].

• Measurement noise parameter R = 2.8.

• Additive normally distributed noise 4%.

25

Page 26: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 10: Measured signal with a constant deviating frequency at 53 Hz andadditive 4% normal distributed noise. The Kalman estimate should follow thereference signal but without noise.

Figure 11: Spectrum for a measured reference signal with a 3 Hz constant fre-quency deviation from 50 Hz. The spectrum for corresponding Kalman estimateis compared with the reference signal.

26

Page 27: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

4.2.5 Simulation 5

Figure 12-13 shows a similar result as in the previous simulation with the samenoise and sampling rate. The only difference is the constant deviating frequencyof 47 Hz instead of 53 Hz.

• Process noise parameter Q =

[0.35 0

0 0.35

].

• Measurement noise parameter R = 2.8.

• Additive normally distributed noise 4%.

Figure 12: Measured signal with a constant deviating frequency at 47 Hz andadditive 4% normal distributed noise. The Kalman estimate should follow thereference signal but without noise.

27

Page 28: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 13: Spectrum for a measured reference signal with a -3 Hz constant fre-quency deviation from 50 Hz. The spectrum for corresponding Kalman estimateis compared with the reference signal.

4.3 Conclusions from MATLAB simulationsThe most important simulation results were shown for the steady state caseswhere different choices of R and Q would follow the grid signal. For a highdegree of harmonic distortion, figure 6-7 showed that each harmonic could besuppressed while the frequency changed. It is also important to see how smallthe covariance of the process noise Q is tuned to enable such suppression. Bycomparing to the much larger Q used in simulation 4 and 5, sampling rate hasa large influence. Concerning the 3 Hz deviation used in the later simulations,the Kalman filter manages to estimate the phase even though the deterministicvector C is based upon a constant frequency, 50 Hz. The only drawback beingthat noise suppression is harder in these cases.

28

Page 29: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

5 Hardware and Program interfaceThis section describes the hardware used for an implemented version of theKalman filter and the devices used for visual confirmation.

5.1 FPGA(Field Programmable Gate Array)A Field Programmable Gate Array consist of programmable switches and logicalcells that can be wired through correct switching. An example of connectionscan be seen in figure 14. Each logical cell can be configured to perform a simpletask, while the programmable switches make the interconnections to make aroute between logical operations, that can result in a more complex operation.The programming of the FPGA is based on a HDL (Hardware DescriptionLanguage) that makes the internal configurations[10].

Figure 14: Example of FPGA connections

A FPGAs logic cell contains Flip-Flops, LUTs(Look-Up Tables), Block-Memories and DSP48s.Flip-flops within a FPGA have a task to synchronize logic and shift valuesbetween iterations. LUTs can be used to handle logic operations like AND,NAND, OR and NOR but can also handle temporary storage. The block mem-ories could be used for temporary storage between iterations or reading constantvalues. Some FPGAs have memories that handles read while writing.High speed arithmetic slices (DSP48s) are one type of embedded block that en-ables fast arithmetic operations within the FPGA. The block contains one mul-tiplier and accumulator that either add or subtract. Depending on the FPGA

29

Page 30: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

type, larger amount of bit representation can be multiplied together. [Virtex 5FPGA XtremeDSP Design Considerations User Guide]. 48 in the name standsfor the number of bits the accumulation can handle. One objective for theDSP48s blocks, is to relieve both LUT and Flip-Flops from the arduous task ofperforming resource consuming mathematical operations.

5.2 Chassi (compactRIO 9114)Most of the equipment used for the application are mainly for experimental pur-poses and not practically in the industry. The experimental setup enables easyoverview and access to different signals. The compactRIO chassi (By NationalInstruments) used in this application is reconfigurable and contains the FPGAcore. Depending on the model of the compactRIO, the FPGA cores and chassidesigns will be different. For this specific applications chassi, a Xilinx Virtex5-LX50 is embedded in the bottom of the chassi. This FPGAs main circuitrycontains 28,800 LUTs and Flip-flops. Multipliers are of DSP48 type (25x18 bitmultipliers) and amount to 48 pieces. The embedded memory has 1,728kbitsavailable for storage. During normal operations, the FPGA executes with theclock-rate 40Mhz, but can be configured to slower or faster rates.

Input and output are available within the chassi through sockets designed to fitcertain Modules.The input/output source is connected through a D-sub-miniature 19 pin con-nector. Each module have their own D-sub connection to enable faster paralleldata transfer to the FPGA. The chassi used in this application, is a Şcom-pactRIO 9114Ť with eight module slots available, see figure 15. Most of theexterior consist of a heat-sink material to enable cooling. The chassi design inthe figure requires a real time controller for communication and programmingof the FPGA. Three DMA (Direct Memory Access) channels are able to senddata back to either the Real-Time Controller or the host computer.

30

Page 31: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 15: CompactRIO chassi

5.3 Real-Time ControllerThe following text explains the CompactRIOs 9022 Real-Time controller andthe main features. The Real-Time Controller shown in figure 16 deliver powerto the compactRIO chassi and is mounted together with the chassi case. Com-munication with the chassi and its FPGA goes through a PCI bus. This enablesthe programming from the host computer through the controller and into theFPGA.Ethernet and serial ports makes the connection via TCP/IP and serial protocolsfor data transfer back and forth between the host computer. The interior of thecontroller has 2 GB nonvolatile memory and additional 256 MB DDR2 memoryfor program storage and data logging. Execution of programs are performedwith the embedded 533 MHz real-time processor. In this case, the Real-TimeControllers purpose is to connection to the host computer and to enable pro-gramming of the FPGA.

31

Page 32: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 16: Real-Time Controller

5.4 ADC and DAC ModulesFor easy signal generation and data acquisition the use of input-output modulesis required to work with the Chassi and FPGA. The experimental moduleshave different objectives depending on signal type to be handled. Mountingthe modules directly onto the compact RIO chassis through the D-subminaturewith 19 pins connection, enables the read or write option from each module.

5.4.1 NI 9205

The NI 9205 module work as an ADC and handles multiple input voltage signalsover 32 different channels. Each channel can be modified to work with differentranges from (+/-)200mV, (+/-)1V, (+/-)5V and (+/-)10V. The resolution forthe ADC is 16 bits which result in 65536 levels of representation. With a smallerrange for the given ADC resolution, the quantization error decreases. Randomnoise decreases with a smaller nominal range. In case of voltage values thatexceed the maximum range of the channel, protection for over-voltage ensuresa safety limit at (+/-)30V. When the (+/-)10V is used a minimal over-range of4 % is available for extra accuracy.Since the multiplexer is shared, the amount of channels used affects the speedof the conversion. Aggregate sampling rate for the devise is 250kS/s and will bedivided be the amount of channels used. Triggering the sampling by the user isalso an important feature enabled. In Figure 1, this module represent the ADCblock.

5.4.2 NI 9264

The NI 9264 module is a DAC (Digital to Analog Converter) with 16 outputchannels providing a voltage signal with small current. Each channel has a

32

Page 33: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

resolution of 16 bits that can produce simultaneous outputs since they containindividual DA converters. The module can convert 25kS/s at maximum for eachchannel. Maximum output voltage for each channel is, +10.65 and minimum-10.65. Over-voltage at +/-27V can protect the module at 25 degrees Celsius.This module has only been used to verify if the estimated phase signals, arecorrect.

5.5 Labview interfaceIn this application, the visual programming language Labview has been used andthe hardware products described above are all specially designed to be compat-ible with the graphical programing language. When programming the FPGAwithin the CompactRIO chassi, the Labview visual block code has to be trans-formed into something the Xilinx compiler recognizes. This is done throughLabview’s own tools and results in block code representation. The compilationthrough Xilinx result in a HDL representation which can configure the FPGA.

Since Labview and Xilinx compile the source code into a HDL language, itis hard to determine how each block will be represented in LUTs, Flip-flopsand DSP48s. In case of large design which requires many pieces of circuitry,it is uncertain how much the resulting compiled version has been optimized inrespect to resource sharing. Sharing resources can however be time consum-ing and might affect a time crucial path[Xilinx Synthesis and simulation designguide].

In contrast to MATLAB design, the FPGA can not handle Double precisionvalues and is restricted to a maximum of 32 bits fixed point accuracy. Ifa mathematical operation within the FPGA has a resulting value that is be-tween representation levels, some accuracy is lost. Performing at the maximumamount of available representation digits is however not optimal, since the usageof LUTs might be unnecessary high. Especially for large designs with lots ofmathematical operations.

33

Page 34: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

6 ImplementationThe objective of this chapter is to explain the main features of how to implementa similar Kalman filter design as in chapter 3. With the idea to make it a timeand resource efficient design for a FPGA with limited amount of LUTs, Flip-Flops, Multipliers and Memory.

6.1 DesignA FPGA is not designed solely for matrix operations and therefore every matrixoperation have been replaced with element-wise mathematical blocks. The rea-son is to utilize the most in terms of parallel processing. Appendix B shows anexample of a (2 × 2) matrix multiplication and the amount of blocks required.To make each new Kalman estimation faster and resource efficient, identity ma-trix and their mathematical operations have been excluded. Matrix A from (11)is a identity matrix and can be neglected as long as the Kalman filter is a onestep predictor. Equation 23-24 describes the reduced versions of equation 17-18without the deterministic A matrix. Since the conclusion from the MATLABsimulation were that Q had to be in a diagonal form to make it stable, theimplemented model can be reduced further. The Q matrix only contributionbeing its diagonal elements thus resulting in only two additions in (23).

P (t+ 1 | t) = P (t | t) +Q (23)

K(t) = P (t | t− 1)CT [CP (t | t− 1)CT +R]−1 (24)

Figure 18 below shows the Kalman filter design, where the layout follows theKalman filter flowchart figure 3. Each bubble within the flowchart represent atimed sequence in Labview, executing in the same order, 1-4. See Appendix Bfor a more detailed design.Previous iterations values are stored within small memory blocks that can beaccessed for the next iteration. Memories have been created to store P (t | t),K(t) and x(t | t). To be able to store and extract these values they can notbe in matrix form, therefore each element is stored in a one-dimensional arrayinstead. For row and column vectors, the storage is similar and the followingelements are stored in increasing index order.

Figure 17: Memory Storage

34

Page 35: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 18: Labview Design35

Page 36: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

The only non stationary parameter for this specific Kalman filter is the Cvector explained in (10). To recreate this parameter for an infinite amount oftime, two pre-programmed memory blocks enables extraction of singular fixedpoint values. By extracting these values with 50µs interval, two fundamentalsinusoid with an amplitude of 1, are created. Thus representing the time varyingparameters within the C vector. An example is shown in figure 19. The For loopthat surrounds the timed sequence enables this extraction where the For loopiteration decides which address in the memory to access. This concept result in400 Kalman iterations per period, resulting in 20000 Kalman iterations everysecond. To ascertain that the timing is correct for extraction, a delay timerdetermine the operation speed. Recreating one second of a 50 Hz according to(25). Without the delay, the Kalman filter would finish one iteration withinapproximately 25− 30µs.

400 (values/period) ∗ 50µs ∗ 50 (periods) = 1 (sec) (25)

Within each new iteration, the Kalman filter performs a phase estimate basedon a sampled value of the grid signal. This signal comes from the NI 9205 ADCmodule.To enable continuous operation, the block code is places within a while loop,taking measurements and estimating the phase until the user stops the appli-cation. Initialization of parameters are done outside the while loop, since theyare only required at the first time-step and would otherwise overwrite necessaryinformation.

The signal recreation based on one measured phase from the three phasegrid is performed in the same manner as in chapter 3. This makes the inputADC amplitude limited to +/- 1 V to ensure reasonable results on the othertwo phases. The other two recreated phases (21-22) are handled within the lasttimed sequence 4. A more detailed version of each timed sequence can be foundin Appendix B.

36

Page 37: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

7 Results obtained with the FPGA implementa-tion

This chapter shows the visual results for a FPGA implemented Kalman filter.Similar simulations were previously done in MATLAB, chapter 4.

7.1 Experiment detailsTo repeat a similar experiment as previously done in MATLAB, some mod-ifications to the Kalman design were done. For spectral information of thereference grid voltage and the Kalman estimated phase, the use of First In FirstOut (FIFO) memories enabled the spectral comparison. This operation was notdone inside the FPGA and the data were instead fed back to the (host)computerfor analysis in Labview. The following equipment was used to get a simulationof a noise influenced voltage grid.

• By using a low voltage AC generator with variable amplitude and fre-quency, a downscaled grid voltage signal could be simulated. This signalpasses the ADC converter(NI 9205). The amplitude were set at 1 voltwith a frequency relatively close to 50 Hz.

• To simulate the odd harmonics at exactly 150 Hz, 250 Hz and 350 Hz, somedesign changes were done inside the FPGA. Using the same method as forthe C vector design, additional memories containing sinusoidal signalswere created. These sinusoidal signals had the same length and amplitudeas the C vector but with more periods. See figure 19 for details regardinghow each harmonic is generated.To be able to change the amplitude of each harmonic, a gain is multipliedwith the current value from the extracted harmonic memory. Thus creat-ing a sinusoidal waveform with lower amplitude over time.These harmonic waveforms were added to the AD converted voltage signalto simulate the resulting harmonic distortion.

• To verify if the reference voltage signal and all three phases were correct,the NI 9264 DAC modules output channels were used and connect to anoscilloscope.

• For the spectrum of reference phase signal and the Kalman estimatedphase signal, the whole FIFO data collected during one second was used.

• For the following results, a sampling rate of 20 kHz was used.

• The initial values chosen for the states x1 = 0 and x2 = 0 similar to theMATLAB simulation.

• The initial error covariance matrix P (0 | 0) was chosen to be a identitymatrix.

• In the following figures,the red voltage signal represent the measured gridsignal and the corresponding Kalman filtered version is colored yellow.Blue and Green colored are the additional two phases, recreated based on(21-22). The spectrum figures will only contain the Kalman estimationand the reference voltage signal.

37

Page 38: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 19: FPGA Harmonics Generation

7.2 Results7.2.1 Simulation 1

Figure 20 shows the implemented Kalman filter during operation. The powergrid source representation is a low voltage source with a small frequency vari-ation during steady state. In this figure, the Kalman filtered signal is barelyvisible behind the reference grid measurement. The spectrum figure 21 onlycontain one phase estimate compared to the noisy grid voltage signal. With thetuning below, the third harmonic can not be removed completely.Figure 21 also contain additional even harmonics which were not generatedconsciously and have its origin in the voltage AC generator.

• The process noise related parameter Q =

[0.000488 0

0 0.000488

].

• The measurement noise related parameter R = 1.5

• Third harmonic 150 Hz at 5%.

38

Page 39: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 20: Steady state frequency variation of a low voltage source with asimulated harmonic in 150 Hz (red). The Kalman estimation (yellow) shouldfollow this low voltage signal and extrapolate additional phases (blue and green).

Figure 21: Spectrum for the steady state voltage signal and its Kalman estimatewith the goal to suppress the harmonic present.

7.2.2 Simulation 2

Figure 22 below shows an unreasonable high third harmonic at 40% of theoriginal. The Kalman filter follows the same parameters as previous except forthe Q where every diagonal element have replaced with the smallest fixed point

39

Page 40: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

value available 3.05 ∗ 10−6 for this FPGA application. The Kalman filter hasa hard time to attenuate this large harmonic completely and it can be seen inboth figure 22 and 23. By looking closely at the spectrum in figure 23 the evenharmonics are present.

• Q =

[3.05 ∗ 10−6 0

0 3.05 ∗ 10−6

].

• R = 1.5

• Third harmonic 150 Hz at 40%.

Figure 22: A Third harmonic at 40% is present in the measured low voltagesignal (red). The Kalman filtered version of the same signal with the goal tosuppress the harmonic is colored yellow.

40

Page 41: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 23: Spectrum of the measured signal and the Kalman estimate given asimulated large harmonic distortion at 40%.

7.2.3 Simulation 3

Simulation 3 repeats a similar simulation as previously done in MATLAB with alarger frequency deviation. Figure 24 shows decreasing phase of approximately47 Hz. Harmonic noise in the third harmonic has been reduced in this case. Tomake the Kalman estimate follow the reference grid voltage, the tuning for theQ matrix is much larger than before.Even harmonics are present the measured voltage signal as well.

• Q =

[0.01 0

0 0.01

].

• R = 1.5

• Third harmonic 150 Hz at 2.5%.

41

Page 42: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 24: Decreasing phase simulation showing the performance when thefrequency deviates with -3 Hz from 50 Hz.

Figure 25: Spectrum of the frequency deviating signal and the Kalman estima-tion

42

Page 43: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

7.2.4 Simulation 4

Simulation 4 shows the constant increased phase of approximately 53 Hz. Har-monic noise is the same for as in previous simulation. The tuning parametersare also the same for the resulting figures 26 and 27. Figure 27 contain the evenharmonics not consciously generated.

• Q =

[0.01 0

0 0.01

].

• R = 1.5

• Third harmonic 150 Hz at 2.5%.

Figure 26: Increasing phase simulation showing the performance when the fre-quency deviates with 3 Hz from 50 Hz.

43

Page 44: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 27: Spectrum of the frequency deviating signal and the Kalman estima-tion

7.2.5 Simulation 5

Simulation 5 shows the Kalman estimation for a grid representation signal withadditional noise in third, fifth and seventh harmonic. The following parameterswere used for a slightly deviating frequency at approximately -1 Hz. Suppressionof the harmonics can be seen in both figure 28 and 29. The even harmonics whichare present are also attenuated by the Kalman filter.

• Q =

[0.00396 0

0 0.00396

].

• R = 1.5.

• Third harmonic 150 Hz at 10%.

• Fifth harmonic 250 Hz at 5%.

• Seventh Harmonic 350 Hz at 2%.

44

Page 45: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 28: Simulation showing the performance with third, fifth and seventhharmonic present in the measured signal (red).

Figure 29: Spectrum showing the Kalmans ability to suppress the third, fifthand seventh harmonic in a noise corrupted measured signal.

45

Page 46: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

7.3 FPGA ConclusionFor the implemented FPGA simulations the performance showed harmonic noisereduction for all simulations. By looking at figure 22 a slightly higher amplitudefor the Kalman estimated voltage signal can be seen. For the large harmonicdistortion, the smallest tuning of Q can not attenuate the harmonic completely.

It is interesting to see that there are even harmonics present in the measuredsignal spectra, even if they were not (consciously) generated in the simulation.The reason could be the rectifiers within the low voltage AC generator.The implemented version of the Kalman filter manages to calculate 20 000estimates every second and can run continuously without problems.

46

Page 47: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

8 Evaluation and ConclusionThis chapter covers the evaluation of the simulations and where the discus-sion part evaluates both theoretical MATLAB simulation and hardware FPGAimplementation.

8.1 DiscussionThere are alternative ways of describing the system on a state space form de-pending on the goal of the application. If the goal of the estimation is to extractphase, frequency and amplitude a different state space will be required [11]. Thesystem described by these states tend to become non-linear and therefore an ex-tended Kalman approach is necessary. Extracting the amplitude, frequency andphase are not required in this application. This makes the states linear to sim-plify the model to data fitting instead of component extraction. Limits withinthe FPGA hardware are also parts of the reason to use the linear Kalman filter.Using a state space form for an extended Kalman will result in a [3x3] matrixinverse which is time and resource costly calculation for the FPGA. Further cal-culation reduction (23-24) based on the identity matrixA can not be obtainedin this case either.

When tuning theQ and R parameter, the frequency deviation and the noisepresent in the system both affect the recreated estimated signal. If the systemhas a large degree of harmonic distortion, the tuning becomes harder. The goalis to find a balance that allows both the adaptability to follow the small fre-quency change and ignoring noise. By selecting a small Q matrix, the systemfilters out harmonics to certain degree but might have a harder time to followthe frequency variation.

The theoretical implemented Kalman filter has no limits regarding amountdecimals representation. For the FPGA, the fixed point representation has tobe limited, otherwise LUTs and memories will overflow.

Since the space vector modulation to recreate a high current sinusoid, de-mands a small interval between data points, the sampling rate will becomelarge. This can have both advantages and disadvantages. Sampling rate limitsthe choice of the tuning parameters making the system more sensitive to har-monics due to their contribution of numerous incorrect values. This demandsthat the parameter Q approaches zero to ensure harmonics removal. If the THDis large, it might be wise to decrease sampling rate and instead interpolate valuesin between Kalman iterations. This will help the FPGAs fixed point represen-tation since the Q and R tuning becomes easier in respect to decimals. Fora small isolated systems with only a few generators, the bandwidth frequencythreshold of +/- 0.1 ,during steady state, might be exceeded since there are notenough regulation power to compensate for load changes. In this case, a higheradaptability to frequency changes is needed.

For an unbalanced three phase power grid, the phase recreation solution isnot an option. Using three Kalman filters that measures each phase in parallelwill work in this case, but consumes most of the resources on the FPGA. Thisis a large drawback in respect to the additional blocks, figure 1 project overviewintended to share the resources. A solution could be using an additional FPGAthat handles the SVM and Current Controller.

47

Page 48: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

8.2 ConclusionThis report covers grid synchronization with the help of a Kalman filter. Thegoals were to measure a power grid downscaled representation and estimatethe sinusoidal waveforms phase. The goal was also to reduce the harmonicdistortion on the measured grid signal. For this specific Kalman filter, a linearstate space form representing the amplitude and phase were used. The filter weretested and evaluated in MATLAB with satisfying results for a high degree ofharmonic distortion and frequency variation. Implementing the similar Kalmanfilter design within an embedded FPGA target were made possible with Labviewsoftware and compilation tools. The result was a time efficient, robust designwith fast accurate iteration with the ability to suppress harmonics and adaptto a +/-3 Hz changing frequency.One of the drawbacks with the solution is that the estimated phase information,will not appear correctly once the frequency starts to deviate.

8.3 Scope for future workThe individual Kalman filter should be implemented on the FPGA togetherwith the SVM design and Current Controller to see if the available resourcesare enough. If additional time is required between iterations, a solution tointerpolate data points between Kalman iterations might be required.

If the application should be implemented on a unbalanced power grid, per-forming Kalman filtering on each phase will be required. Investigating how eachphase could share the same Kalman filter would be achievable.

48

Page 49: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

References[1] Zheng-Guang Wang, Jian-Xun Jin, You-Guang Guo and Jian-Guo Zhu,

: SVPWM Techniques and Applications in HTS PMSM Machines Con-trol. JOURNAL OF ELECTRONIC SCIENCE AND TECHNOLOGY OFCHINA, Vol 6,NO. 2, June 2008

[2] Steven Tom, :Current Controller Based Grid Interface for NPC MultilevelInverter . Division of Electricity , Uppsala University , July 2009

[3] R. Sastry Vedam Mulukutla S.Sarma, :Power Quality VAR Compensationin Power Systems. Edition 2008 , Ch 1-6

[4] Svenska Kraftnät, :Tekniska riktlinjer för elkvalitet. TR6-01 rev B , 06-01-03

[5] Johan Bladh, :Frequency drop following a scheduled disconnection of Os-karshamn 3. Not published

[6] Torkel Glad, Lennart Ljung, :Reglerteknik Grundläggande teori. Upplaga 4, p 149-206

[7] Fredrik Gustafsson,Lennart Ljung Mille Millnert, :Signalbehandling. Up-plaga 2, p 289-340

[8] Robert A Adams, :Calculus A Complete Course. Fifth edition, Ch 1-2

[9] Torsten Söderström, :Discrete-Time Stochastic Systems Estimation & Con-trol. Prentice Hall International,Ch 9 , p 233-267

[10] Chu Peng P , :FPGA Prototyping by Verilog. Wiley,2008, Ch 1-2

[11] J Svensson, : Synchronization methods for grid connected voltage sourceconverters. IEE 2001

49

Page 50: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

A MATLAB CodeThe following MATLAB code were used to filter a noisy sinusoid with amplitude1 volt and approximately a frequency of 50 Hz.

function [filtered_sig]= kalmanfilter(signal,Q_in,R_in,simulation_time)%this Kalman filter has been modified to follow an input siusoidal%"signal" with approximatley 50 Hz.%Q_in and R_in are tuning parameters.%simulation_time is the total simulation time(match input-signal).%filtered_sig is the Kalman-filtered output of the signal.

time_vec=linspace(0,simulation_time,length(signal));

A=[1.00 0.0;0.0 1.00];w=2*pi*50;

%initilize valuesx0=[0;0];p0=1*eye(2);

Q=Q_in;R=R_in;

z1 = zeros(1,size(signal));z2 = zeros(1,size(signal));filtered_sig = zeros(1,size(signal));

for i=1:max(size(signal))xn_nm1=x0;c=[cos(w*time_vec(i)) -sin(w*time_vec(i))];%1 Corresponding to flowchart chapter 3pn_nm1=A*p0*A’+Q;

%2 Corresponding to flowchart 2kn=A*pn_nm1*c’*inv(c*pn_nm1*c’+R);

%3 Corresponding to flowchart chapter 3xnn=xn_nm1+kn*(signal(i)-c*xn_nm1);

%4 Corresponding to flowchart chapter 3pnn=pn_nm1-kn*c*pn_nm1;

z1(i)=xnn(1);z2(i)=xnn(2);

%recreating the sinusoidfiltered_sig(i)=c*[z1(i);z2(i)];x0=xnn;p0=pnn;endend

50

Page 51: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

B Labview DesignThe figure below shows the amount off blocks needed for element wise multipli-cation between (2× 2) matrices.

Figure 30: Element wise Matrix multiplication

Figure 31: Initialization Process

51

Page 52: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 32: First Kalman time step (FPGA)

52

Page 53: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 33: Second Kalman time step (FPGA)

53

Page 54: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 34: Third Kalman time step (FPGA)

54

Page 55: Power grid integration using Kalman filtering505488/FULLTEXT01.pdf · and valuable suggestions regarding labview, which gave me good intro-ductional knowledge. Many thanks to Tomas

Figure 35: Forth Kalman time step (FPGA)

55