A Frequency Measurement Algorithm for Power Quality Monitoring Terminal

With the continuous access of high-power electronic equipment, electric vehicles and other loads in the user side, the frequency of power grid fluctuates. As one of the power quality parameters, higher or lower frequency has a negative impact on power system and users. Therefore, the accurate measurement of frequency is of great significance to the State Grid and users. In order to measure the frequency accurately, this paper proposes a frequency measurement method according to power quality monitoring technical specifications issued by the State Grid in 2017. Through the design of band-pass filter to filter out DC (Direct Current) component and high-frequency harmonic interference, along with the improved zero-crossing detection process, aim to judge the whole cycle wave number and its occupation time in ten-second time interval. Matlab is used to simulate the accuracy of the algorithm under different conditions. The results show that the error range measurement of frequency is far less than the accuracy level of class A and S power quality testing equipment. Therefore, this algorithm is feasible in the application of power quality monitoring terminal.


Introduction
In recent years, with the rapid development of economy and the continuous improvement of people's living standards, the society has higher and higher requirements for power supply reliability and power quality. Due to the influence of external interference and various faults, the ideal constant frequency and sinusoidal waveform voltage do not exist, which results in the unstable changes of voltage waveform and frequency at the public power supply point, thus causing various power quality problems in the process of power supply and consumption. As one of the power quality parameters and the unified parameters of power system operation, higher or lower frequency has a negative impact on power system and users. Therefore, the accurate measurement of frequency is of great significance to the State Grid and users. In order to standardize the power quality monitoring work and promote the development and application of its monitoring technology, the State Grid Corporation of China issued the technical specification for power quality monitoring in 2017 [1]. At present, the domestic and foreign digital algorithms to calculate the grid frequency mainly include frequency measurement method based on Fourier algorithm, recursive least square method, Kalman filter and other algorithms [3][4][5]. The accuracy of these methods is very high when calculating the instantaneous frequency of the system. Discrete Fourier transform (DFT) algorithm has a small amount of calculation and a certain ability to suppress harmonics and noise, but it needs a large data window [2]. In reference [3], a method is proposed to fit the sinusoidal curve of the original signal with the least square nonlinear curve fitting method of Levenberg Marquardt, then resample the fitted curve and get the frequency through DFT algorithm. Although the accuracy is high, its calculation is time-consuming. In reference [4], an algorithm based on the time interval of voltage zero crossing is proposed to calculate the frequency. The principle is simple and real-time, but the measurement accuracy is greatly affected by the quantization error. In reference [5], a method of power grid frequency measurement based on Kalman filter algorithm is proposed. The purpose of power grid frequency detection and prediction is achieved by constructing power system state space model. But this method is to seek the optimal covariance in the continuous recursive process, and the response to the mutation of state variables is slow. Based on the above reasons, and in order to meet the need of power quality monitoring technical specifications developed in 2017. In this paper, a frequency measurement method for power quality monitoring terminal is proposed. This method does not need to use complex filter, the principle is simple and the accuracy can meet the accuracy requirements of the class A and S power quality monitoring devices.

The Digital Filter
Generally, the actual signal of power system is not a standard sinusoidal signal, it is a complex signal containing various sub-harmonic components, inter-harmonic components, tributary components and a large number of noises [3]. Under normal circumstances, the fundamental frequency fluctuates slightly near the power frequency of 50Hz, and the frequency of each harmonic component changes with it, which brings great error to frequency measurement. Digital filter has been widely used in the field of signal processing because it owns several advantages compared to analog filter [6]. A digital filter is a device that transforms a group of input digital sequences into another group of output digital sequences by performing certain operations. The system function of a digital filter can be expressed as [7]: Following this, the constant coefficient linear difference equation of the input-output relationship is obtained as follows: are not all zero, the filter is Infinite Impulse Response (IIR) digital filter. Compared with FIR digital filter, IIR digital filter can use lower order to obtain high selectivity, and with less memory units and signal delay. And IIR digital filter can be realized by many software, which simplifies the design process.

The Design of Digital Filter
Based on the above reasons, this paper designs a direct IIR filter. The direct IIR filter is based on the second-order biquad cascade. Each biquad consists of a second-order filter, and each stage requires five coefficients. The high order IIR filter is realized by cascading several second-order biquads. Here, the target filter is of order four, the structure of the fourth-order IIR filter is shown in figure 1. In this paper, an IIR Butterworth type band-pass filter is designed. According to the technical specifications for power quality monitoring, the frequency input range of analog signal is set as 42.5Hz ~ 57.5Hz. In order to eliminate the influence of harmonic, high-frequency noise and other interference signals, the filter parameters are set as follows: the upper limit of passband is 60Hz, the lower limit of passband is 40Hz, and the sampling frequency is 16KHz. Through MATLAB simulation, the frequency response characteristics of the filter is shown in figure 2. It can be seen that only the components in the small range of 40~ 60Hz in the band-pass range can pass through the filter, the attenuation in other frequency ranges is very large. The attenuation of DC

Zero-crossing Detection
After the original sampling data passes through IIR band-pass filter, a series of discrete data sequences are obtained. The zero-crossing time can be obtained by judging the zero crossing of discrete adjacent data points [4]. The curve between two points is approximately a straight line, and the zero-crossing time is calculated by solving the linear equation of two points, thus the frequency value is obtained. Because of the application of two-point straight-line fitting, the frequency accuracy will be affected by quantization error. Based on this, this paper judges the number of zero-crossing points by looking for the rising edge of the waveform. If the voltage sign of the adjacent data points is the same, it is considered that there is no zero-crossing point between them.
The key of this method is to introduce a forward phase flag, which is the earliest sampling point in a data series, and its initial value is set to zero. Whether the vertical coordinate value of the sampling point is greater than zero or not is set as the standard of rising edge determination. If the condition is satisfied, the forward waveform of the first sampling point has a rising edge, then the number of zerocrossing points plus one; if the condition is not satisfied, the process continues until the next rising edge is found.

Frequency Calculation
The technical specification in 2017 specifies the measurement method of fundamental frequency for power grid. Which is the ratio of integral period calculated in ten-second interval to integral period cumulative time (the single period overlapped within ten second should be discarded), and the measurement interval cannot be overlapped. The flow chart of the algorithm implementation process is shown in figure 3, and the steps are described as follows:   (2) Each N-point sequence waveform is obtained through IIR filter process, then the zero-detection method is used to count the zero-crossing point within this N point. After the zero-detection method, there are two cases of the result. If the number of zero-crossing point is zero, it means the phase loss may occur, the original signal sampling may be wrong or lost. If the number of zero-crossing points is not zero, it will be counted.
(3) In order to measure the zero-crossing points accurately within ten seconds, the zero-crossing position of the first rising edge and the last rising edge is marked. The difference between the two is the number of integral periods calculated in ten seconds. The cumulative time of integral cycle is ten seconds minus the non-integral cycle cumulative time, which means ten minus the start time of the first rising edge zero-crossing point and the end time of the last rising edge zero-crossing point. As the sampling frequency is known, the non-integral cycle cumulative time can be calculated.

Simulation Results and Analysis of the Algorithm
In order to verify the frequency measurement effect of the algorithm proposed in this paper, the performance of the algorithm under different input signals is simulated. The sampling frequency of IIR band-pass filter is set to 16KHz.

Measurement without Harmonics
When the signal is a standard sine wave which is x(t) [8]: its frequency range f is 42.5Hz ~ 57.5Hz, and the initial phase angle is selected randomly. The measurement results of the algorithm are shown in table 1. The result shows that the measurement frequency errors are all 0, thus this algorithm is applicable in the case of standard sine wave, and there is no error of the algorithm itself.

Influence of Harmonics on Frequency Measurement
In order to investigate the effectiveness of the algorithm, the input signal is set as [8]: (2 ) The amplitude of the fundamental wave is 220, the phase angle is 0. The third, seventh and eleventh harmonics are applied at the same time and their harmonic voltage content is 10%. The content of 15 th harmonic voltage is 4%, the 19 th and 23 rd harmonic voltage content is 5%. Figure 4 shows the signal waveform with specific harmonics and waveform after applying IIR filter. It can be seen that the harmonic interference affects the zero-crossing points of the waveform, causing the number of zerocrossing point uncertain. After the signal passes through the filter, the waveform recovers the sinusoidal characteristic, so the IIR band-pass filter filters out the harmonics outside the band-pass frequency effectively. In order to further verify the performance of IIR filter, adding more harmonic interference from the 2 nd -order to 50 th -order to the signal [8], the signal waveforms are shown in figure  5. It can be seen that the zero-crossing points are affected severely compared to that of in figure 4, but the signal recovers the sine shape after filtering process.
The frequency measurement results of harmonic interference signals based on equation (4) are shown in table 2, and the frequency range is 42.5Hz ~ 57.5Hz. It can be seen that in the case of harmonics, the absolute error of frequency measurement can reach 0.00001Hz due to the effectiveness of filter. The absolute error is zero when the frequency measuring points are 49.95Hz, 50.00Hz and 50.05Hz.   Figure 5. Harmonic interference (2nd-50th order) waveform(blue) and filtered waveform(red).

Conclusions
Aiming at the problem of power quality frequency deviation, this paper puts forward a frequency measurement method suitable for power quality monitoring terminal according to the technical specification for power quality monitoring. In this paper, an IIR band-pass filter is designed and the simulation results show that it can filter out the DC component and harmonic component in the signal, which can recover the waveform under the 2 nd -50 th harmonic interference to sinusoid shape. Therefore, IIR filter offers strong basis for obtaining zero-crossing point through zero-detection method. The frequency then can be calculated through counting the zero-crossing point within ten seconds. The absolute error of the frequency measurement algorithm can reach to 0.00001 Hz under the influence of harmonics, which is far less than the error standard 0.01Hz. The algorithm is simple, not timeconsuming and efficient, which further shows the applicability of the algorithm. As DFT is still the key method to suppress harmonics and noise but has large data window, how to take advantage of it with the algorithm in this paper but avoid the drawback is a key point for the future analysis of frequency measurement.