Elektrotehniški vestnik 76(1-2): 1-6, 2009 Electrotechnical Review, Ljubljana, Slovenija A Polyphase DSP-based electricity measurement system a with network analyzer Rok Marolt, Andrej Zemva Iskraemeco, SavskaLoka 4, 4000 Kranj, Slovenia Abstract. This paper represents a three-phase precision measurement system for the electronic electricity meter based on a digital signal processor (DSP) in combination with a multichannel analog-to-digital converter. The measurement system capabilities include all the usual assessments of the energy, power, voltage and current, but functionality of this precision measurement system is extended into the domain of power network quality analyzers. Here the measuring part of a complex device is being discussed which embeds a highly accurate electricity meter and network analyzer in the same unit. Analyzer functions are implemented in compliance with the European EN5160 Standard, and they include detection of short- and long-term voltage sags, swells and outages, harmonic analysis of current and voltage signals with calculation of total harmonic distortion (THD) as well as assessment of voltage flicker severity. Key words: industrial electricity meter, three-phase measurement system, power network analyzer, power quality Trifazni DSP-merilni sistem za merjenje električne energije z analizatorjem omreZja Povzetek. (Članek se ukvarja s trifaznim precizijskim merilnim sistemom elektronskega števca električne energije, razvitim na podlagi signalnega procesorja v povezavi z večkanalnim pretvornikom AD. Merilni sistem omogoča vse ustaljene štirikvadrantne meritve energij, moči, napetosti in tokov, poleg tega pa opravlja tudi funkcije analizatorja kakovosti dobave električne energije. Gre torej za merilni del kombinirane naprave, ki v enem ohišju zdruzuje visoko zmogljiv preciz-ijski števec električne energije in analizator omrezja. Analiza-torske funkcije so implementirane tako, da ustrezajo merjenju kakovosti dobave elektricšne energije po evropskem standardu EN 5160, vključujejo pa detekcijo dolgotrajnih in kratkotrajnih izpadov, upadov in porastov elektricšne napetosti, harmon-sko analizo signala ter izracšun faktorja harmonskega popacšenja (THD) in intenziteto flickerja. Ključne besede: industrijski števec električne energije, trifazni merilni sistem, analizator omrezšja, kakovost dobave elektricšne energije 1 Introduction Induction electricity meters have become completely obsolete in the area of industrial electrical power measurement. Beside the standard features expected to be present in a digital industrial meter, incorporating measurement of the active, reactive and apparent power/energy, high accuracy class (0.2 or better), custom energy registration, programmable tariff switching device and a number of Received 13 October 2008 Accepted 17December 2008 communication protocols and media, it has become necessary for such a device to perform also power network quality analysis, thus integrating a full power network analyzer. Therefore, a highly specialized digital measurement system has had to be developed, ensuring the highest possible accuracy rate due to power losses caused by measurement inaccuracy on power transmission line which are far from being negligible. Such a system demands incorporation of the state-of-the-art analog and digital components as well as reliable and extensible firmware for data processing. As it can be clearly seen, raw data coming out of the analog-to-digital converter do not reveal anything about the energy and/or power network quality; thus the key component of such measuring device is implemented in software running on a floating-point DSP processor. Network analysis features implemented in this system incorporate evaluations required by the European EN50160 standard, thus including detection of long- and short-term voltage sags, swells and outages, spectral analysis, voltage unbalance factor and flicker severity. The first chapter deals with the basic measurements. The second, third and fourth chapter address assessment methods for period, true RMS values of the voltage and current, harmonic analysis and flicker severity, respectively. The last chapter describes software implementation. 2 Basic measured quantities The very basic measurements performed by the electricity meter are simply types of the electric energy - active, reactive and apparent [7]. The active energy is, by definition, time integral of the electric power consumed or produced. Ea(t) p(t)dt u(t)i(t)dt. (1) t-T t-T t t Er(t)= J q(t)dt = J û(t)i(t)dt. t-T t-T (2) t Qperiod(t) = 1 J Um(t)in (t)dt = 0 (3) HDi(z) = A 1 + z-1 - z- (4) HAi(s) = 1 1 + RCs ' (5) Bilinear transform of the above yields a digital transfer function A(1 + z-1) Hni(z) 1 - Bz (6) where A B 2 Ti-T RC and T = 1. If T+2^ ' 2 Ti+T' such filter is applied to the voltage signal, it gives a phase shift which is frequency-dependent; to compensate this, we introduce a similar filter on the current signal which is essentially a digital differentiator analogue to H Similarly, the reactive energy is defined as a time integral of reactive power, which is essentially the power loss on reactive components connected to the electrical network. When the voltage and current are completely out of phase (phase angle 90 °), there is no active energy flow into or out of the load; energy is lost within reactive loads. The reactive energy can be expressed as the active one with the voltage and current with a phase shift of 90 ° generated between them; it results in Ad TdS TdS + 1 (7) which results in the z-domain as H where C 2Td 2Td+T Dd D C(1 - z-1) 1 - Dz-1 2 Td-T 2 Td+T' The integrator and dif-ferentiatior are applied to the voltage and current signals, respectively, in order to produce apparent power with the right sign. If we, for that matter, state HAd(j^) = jHAij), this equation yields constants for filters The problem that is to be copped with is harmonic distortion of the voltage and current signals. IEC standards define the reactive energy as such at the fundamental component only; therefore a low-pass filter will have to be introduced at at least one of the values above, since harmonic components are orthogonal to each other which results in a zero scalar product; the power produced by multiplying and averaging two of the harmonics with different indices produces the zero power: Ti = Td = (9) (10) where m = n. The phase shift between the voltage and current is achieved by a pair of digital filters applied to the voltage and current signals. As it can be clearly seen, a digital integrator with transfer function given as generates a phase shift of exactly 90 ° which is precisely what we want in this situation. But the digital integrating filter also amplifies the DC-component of the signal which would make the filter saturate soon. To eliminate this problem, we have to use a digital filter with a similar phase characteristic but with a limited feedback gain. This is analogue to the 1st order lowpass RC-filter in the continuous-time domain: Filters with this coefficients generate phase offset of precisely 90 °, which is exactly what we are looking for; also, the integrator acts as a low-pass filter and cuts off harmonic values of the fundamental signal. The magnitude of the resulting signals is also frequency-dependent, thus requiring magnitude compensation; coefficients for magnitude compensation are listed in a lookup table with a step of 0.5 Hz; gain constants in between are interpolated using linear interpolation. Information about the signal fundamental, of course, needs to be updated every period. 3 Period and frequency measurement The fundamental period time is assessed by measuring the time between two adjacent zero-crossings; this is done, in the discrete time domain, by counting samples between the two. This, however, gives a maximum accuracy of T = 0.1ms@10kHz, which is inadequate; the actual zero-crossing position has to be interpolated. Linear interpolation is time-efficient and also accurate enough since the first derivative of the harmonic signal is approximately 1 around the first zero-crossing: sin(wt) ~ ivt,t ~ 0. (11) The measuring time between two adjacent zero-crossings looks simple at the first glance; but what if there are harmonics present inside the signal? This could easily lead to situation illustrated on Figure 2. 1 t 1 w t-T 1 1 ■ Gnuplot _n U.l ■v line 1 — 1 0.08 § \ \ „0.06 \ \ l0.04 Qi i_ m £.0.02 \ \ \ 0 -0.02 - 0 0.005 0,01 0.015 0.02 0, t(rns) 02E Figure 1. Period measurement error with use of linear interpolation Figure 2. Signal including false zero-crossings due to harmonic distortion The image displays a signal containing harmonic values with a magnitude large enough to cause two extra zero-crossings the around zero crossing of a half-period. Two methods are implemented to eliminate this problem: • setting frequency/period limits - potential zero-crossing is discarded if not within margins, and • filtering out harmonic values. The filter used in this application is a 4th order IIR-filter of the Chebyshev type 2 with transfer function (@fs = 3906Hz) H (z) 0.097z4 - 0.39z3 + 0.58z2 - 0.39z + 0.097 z4 - 3.92z3 + 5.8z2 - 3.8z + 0.93 Figure 3. Harmonics and DC-component removal filter response 4 Voltage and current measurement When speaking of voltages and currents in the AC-domain, we think of them as phasors - therefore we have to measure the magnitudes of these signals as well as their angles, which are • phase angles - angles between currents and voltages of a phase, and • interphase angles - angles between voltage phasors. All of the angles are assessed in the same manner - by measuring the time between starts of signal periods. Magnitudes of signals are usually expressed as RMS values. RMS calculated by measurement system are true RMSs, which means that DC components are also included. By definition, a true-RMS value is expressed as value of a DC signal with the same signal energy as the original signal: T Es(t) = (u(t),u(t)) = J u(t)2dt. (13) The RMS value of such a signal can be expressed as uRMS = T I '(t)dt (14) (12) In the discrete-time domain, this transforms into Coefficients of the filter were calculated using the Mat-lab's Filter Design Toolbox. The transfer function is graphically displayed in Figure 3. Response of the filter is flat on the frequency area where the period measurement is relevant, and it cuts off frequencies at around 100 Hz by 20 dB. It also eliminates the DC-component of the signal, the presence of which can also cause inaccurate frequency measurement due to the unequal lengths of two half-periods. uRMS N T y y t i (15) Time interval tj is equal to the sampling time on all samples except the first and the last one, where we have to interpolate the exact position of the zero-crossing, as already mentioned in the previous subsection. This yields a true RMS value of a signal, which may be refreshed 0 1 0 • every sample, which requires the whole sample history for a period to be stored and consumes much more CPU time since the square root needs to be evaluated for each sample, • every half a period, because at the time of zero crossing the RMS value may change due to frequency fluctuations; this method only requires the square root to be calculated once every half period. 5 Harmonic spectrum assessment Harmonic analysis of the voltage signal is also one of those demanded by the EN50160 [1]. The spectral image of the signal is revealed using very a conventional method - the discrete Fourier transform, calculated using a FFT algorithm with decimation in time [5]. The basic discrete Fourier transform of a signal is N-1 X [k] x[n]e 2nj x\n\e N kn n = 0, ...,N - 1 (16) n=0 Twiddle factors Wkn = e ~NLkn are pre-calculated and stored in flash memory. Furthermore, if we make use of the periodic nature of the DFT: X [k + N ] N-1 E _ 2nj(k+N)n x[n]e N n=0 N-1 Y^x[n]e e _2 njn n=0 N-1 Er -. _ 2njkn x[n]e N n=0 = X [k], (17) (18) (19) (20) we can capture exactly one period of data, and, according to the equation above, resample the period to exactly match the number of FFT bins. Figure 4 displays the captured and re-sampled signal. FFT used is complex a DIT radix 2; we can also evaluate current harmonic image using no more system resources [5]; the same method is used as in audio applications when doing FFT on stereo signals; when resampling data, we process the current and voltage of the same phase at the same time, placing the voltage into a real and current into an imaginary component of the input floatingpoint array for FFT. After calculation we make use of symmetry of FFT again and restore the measured value arrays by doing U[n] = [n +1])+ [N - n - 1]) + (21) j[n +1]) [N - n - 1])) (22) and I[n] = [n +1]) + [N - n - 1]) + (23) [n + 1]) [N - n - 1])) (24) to produce the voltage and current spectrum, respectively. Figure 5 displays the spectral image of the signal on figure 4. ■ Cinuplot 1=121 XI 100 90 80 70 60 50 40 30 20 10 0 1 ; i r * 0 2 4 6 8 10 12 14 16 18 20 | Figure 4. Original and re-sampled signal before FFT Figure 5. Resulting harmonic histogram 6 Flicker severity The quantity that requires the special algorithm to be performed directly on a stream of samples is flicker severity assessment. Flicker is voltage amplitude fluctuation caused by pulsating loads such as electric welders; it is an issue of psychological effect caused by pulsating lamps and torque fluctuation on electric motors; it is caused by envelope with the frequency from 0.5 Hz to 35 Hz modulated on the fundamental network AC signal.Figure 6 displays a fluctuating voltage signal. The IEC 61000-4-15 [2] standard defines a model for simulation of the lamp-eye-brain chain, used to assess flicker severity coefficient to be passed for further statistical analysis [9]. 2 nifcn N Figure 6. Voltage signal with flicker present First stage is the squaring demodulator and envelope detector. It separates the flicker signal from its carrier. Second stage incorporates a pair of filters: • A bandpass filter which stops frequencies below 0.05Hz and above 35 Hz with 3 dB attenuation at both of the stop frequencies; the 6th order Butterworth IIR filter is used, as suggested in the IEC 61000-4-15 standard and [3]. • A weighting filter which simulates human perception; its characteristic was obtained by tests on a population; its transfer function is displayed on figure 7 and it presents a lower margin of perception at 50 % of the population tested. Third stage is the Rashbass simulation model of brain reaction; it consists of a squaring multiplier and a low-pass filter with a stop frequency at 0.53 Hz. Figure 7. Weighting filter transfer function 7 Software implementation All of the algorithms described in the previous chapters are implemented entirely in software. The DSP processor platform chosen for the task consists of the Texas Instruments TMS320C6726 floating-point DSP processor in combination with the Cirrus Logic CS5451A 6-channel AD converter. All the algorithms are written in floating-point arithmetic and are designed as hardware-independent as possible. The sample rate currently used in this system is 3906 Hz [8], but a higher sampling frequency will be introduced with a new AD converter in order to achieve the sample rate of 10 kHz. The TMS320C6726 processor also includes a built-in ROM library of math routines and lots of DSP algorithms. It also contains hand-optimized implementation of FFT which is widely used in this application [7]. DSP and AD converter communicate using a version of the SPI bus; SPI communication is used to communicate with the tariff device as well. A simple protocol is used to receive requests from the tariff device and send back results. All of the results measured are transferred in a decimal fixed-point format in the network byte order, thus enabling embedding the same system into more than one electricity metering device. Calibration of the system is based on the RMS values of the voltage and current. They are measured in one (or even more) points and passed to the system by SPI; calibration algorithm then calculates coefficients for transforming raw input data into floating-point samples. The current sensors are compensated current transformers; but the potential danger of the DC component presence still remains on voltage signals, thus forcing a software offset compensation. This is done by a lossy 1st order integrating filter which averages the signal; the resulting signal is then subtracted from the original one. 8 Conclusion This paper presents a theoretical background of the measurements performed by a DSP-based electricity measurement system as well as basic concepts of the implementation which is done entirely in software. The system collects samples and returns the measured data which can be registered in a tariff device of a precision electricity meter. All of the algorithms are written as separate software modules which can be easily replaced, modified or used in another application. Hardware configuration as such can achieve the accuracy class 0.2 for the active energy. Further work will be focused on improving the accuracy class for the active and reactive energy into 0.1/0.2, which will require a new AD-converter with 24 bits and higher a sample rate; however, the existing algorithms will mostly remain unchanged, but some new algorithmic modules will be added as well, e. g. for assessment of the tone-frequency line communication signals magnitude. 9 References [1] EN Standard 50150, "Voltage characteristics of electricity supplied by public distribution systems", European Standard, 1994 [2] IEC Standard 6100-4-15, "Flickermeter Functional and Design Specifications", International Electrotechnical Commision, 1998 [3] B. P. Alencar, J. I. Gomes Filho, R. A. Melo, R. P. S. Leo, "A Flickermeter Design on LabVIEW Based on IEC61000-4-15", 12th International Conference on Harmonics and Quality of Power - ICHQP, 2006 [4] A. Bateman, I. Paterson-Stephens, "The DSP Handbook", Prentice Hall 2002 [5] W. H. Press, S. A. Teukolsky, W. T. Vetterling, B. P. Flan-nery, "Numerical Recipes in C, Second Edition", Cambridge University Press, 1992 [6] Roger C. Dugan, Mark F. McGranaghan, H. Wayne Beaty, "Electrical power systems quality", McGraw-Hill, 1996 [7] Texas Instruments TMS320C6720 datasheet, 2008 [8] Cirrus Logic CS5451A Datasheet, 2008 [9] Emmanuel De Jaeger, "Measurement and Evaluation of the Flicker Emission Level From A Particular Fluctuating Load", Laborelec, 2000 Rok Marolt received his B.Sc. and M.Sc. degrees in electrical engineering from the University of Ljubljana in 2005 and 2008, respectively. He is currently employed with the Iskraemeco's Research and Development Dept., Kranj. Andrej Zemva received his B.Sc., M.Sc. and Ph.D. degrees in electrical engineering from the University of Ljubljana in 1989, 1993 and 1996, respectively. He is Associate Professor at the Faculty of Electrical Engineering. His current research interests include logic synthesis and optimization, test generation and hardware-software codesign.