An Iterative Hybrid Harmonics Detection Method Based on Discrete Wavelet Transform and Bartlett–Hann Window

The current signal harmonic detection method(s) cannot reduce the errors in the analysis and extraction of mixed harmonics in the power grid. This paper designs a harmonic detection method based on discrete Fourier transform (DFT) and discrete wavelet transform (DWT) using Bartlett–Hann window function. It improves the detection accuracy of the existing methods in the low frequency steady-state part. In addition, it also separates the steady harmonics from the attenuation harmonics of the high frequency part. Simulation results show that the proposed harmonic detection method improves the detection accuracy of the steady-state part by 1.5175% compared to the existing method. The average value of low frequency steady-state amplitude detection of the proposed method is about 95.3375%. At the same time, the individual harmonic components of the signal are accurately detected and recovered in the high frequency part, and separation of the steady-state harmonics and the attenuated harmonics is achieved. This method is beneficial to improve the ability of harmonic analysis in the power grid.


Introduction
In recent years, as the smart grid enters the comprehensive construction stage, more and more power electronic equipment is put into operation. Among these power electronic devices, there are devices with nonlinear impedance characteristics, such as rectifiers, inverters, and phase speed control and voltage regulation devices. The use of non-linear power electronic equipment generates a lot of harmonic pollution, which causes significant voltage and current distortions and severely affects power quality. Therefore, accurate harmonic detection is of great significance for improving power quality and ensuring the reliability and safety of a power system [1,2].
The accuracy and response speed of harmonic detection depends on the method of harmonic detection. At present, the commonly used harmonic detection methods are as follows: analog filter method, instantaneous reactive power harmonic detection method, neural network harmonic detection method, wavelet transform harmonic detection method and Fourier transform harmonic detection method. The earliest harmonic measurements were achieved by analog filtering methods, which are very sensitive to the parameters of circuit components. Therefore, it is difficult to obtain ideal amplitude frequency and phase frequency characteristics, with large errors and poor real-time performance [3]. The harmonic detection method based on instantaneous reactive power usually uses a digital low pass filter, which has a large delay and directly affects the accuracy and speed of detection [4]. Based on the neural network harmonic detection method, the adaptive linear neural network method needs to accurately obtain the fundamental frequency to accurately extract the harmonic information in the signal [5]. The back-propagation neural network method requires a large number of sample data for training, and will have the disadvantages of training failure or slow convergence speed [6]. The harmonic detection method based on wavelet transform is suitable for the study of non-stationary signals. It has good time-frequency characteristics and is sensitive to transient signals. The analysis of different frequencies through multi-resolution improves the analysis accuracy and preserves the time domain information of the signal. However, the analysis accuracy of the harmonics in the steady state is not as good as that of the FFT, and the frequency is aliased, which will reduce the accuracy of the detection results [7,8]. The use of FFT algorithm to perform DFT solves the problem of a larger amount of calculation. However, DFT has spectrum leakage and fence effects, which will cause large errors in the analysis frequency and amplitude. The large errors and defects in the detection of non-steady-state signals limit the application of DFT in harmonic detection of power systems [9,10]. The research on the harmonic detection method based on Fourier transform is mainly focused on finding a window function with concentrated energy and rapid side lobe attenuation and an interpolation algorithm with higher performance. By analyzing the current mainstream harmonic detection methods, the most widely used discrete Fourier transform based harmonic detection methods and discrete wavelet transform based harmonic detection methods are selected. By analyzing the advantages of the DFT and DWT, some scholars have proposed a hybrid harmonic detection strategy combining two methods [11,12]. First, the original signal is decomposed into a high frequency part and low frequency part by wavelet transform (the Mallat algorithm), and the separation and extraction of low frequency steady-state harmonics and high frequency non-steady-state harmonics are realized. Because most of the steadystate harmonics exist in the low frequency part, few of the steady-state harmonics exist in the high frequency part. The non-steady-state harmonics in the high frequency part are composed of steadystate harmonics and attenuated harmonics. After each decomposition of original signal, the low frequency part can be repeatedly decomposed again. Each layer of decomposition decomposes the input signal of this layer into a low frequency approximate component part and a high frequency detailed part. In addition, the out sampling frequency of each stage can be halved. The significance of halving the sampling frequency is that it will not cause information loss.
This paper designs an improved harmonic detection method based on DFT and DWT using the Bartlett-Hann window function. According to reference [13], the Bartlett-Hann window is a linear combination of the Bartlett and Hanning windows. Taking into account its main lobe width and side lobe attenuation, it is more effective for detecting steady-state harmonics. For the high frequency part, based on the Hanning window DFT and DWT hybrid harmonic detection method, only the attenuation harmonic component is analyzed, and no consideration is given to whether the high frequency part containing the steady-state signal component and the attenuation harmonic component coexist. The method designed in this article can be divided into three cases for processing by analyzing the high frequency part. The steady-state harmonics in the high frequency part are distinguished from the transient harmonics, and the error of the steady-state harmonic component extraction is less than 5%. The amplitude of the attenuated harmonic component at the beginning is basically consistent with the theoretical amplitude. It can improve the detection accuracy of the hybrid detection strategy in the low frequency part, and separate and extract the doped steady-state harmonics from the non-steady-state harmonics in the high frequency part. Simulation experiments show that the algorithm designed in this paper has good harmonic detection accuracy for harmonic detection, and can achieve separation and extraction of high frequency parts.
The rest of this article is organized as follows. Section 2 introduces the principle of the hybrid harmonic detection method based on the Bartlett window DFT and DWT. Section 3 introduces the design of an improved method based on the Bartlett-Hann window DFT and DWT hybrid harmonic detection. Section 4 provides simulation results of test signals and test data. Section 5 summarizes this study.

Principles of Improved Harmonic Detection Methods
The Mallat algorithm uses the characteristics of multi-frequency analysis to decompose the signal and divides the signal into low frequency and high frequency parts. Add Bartlett-Hann window function interpolation DFT algorithm to realize the steady-state signal restoration and the existence of steady-state signals at high frequency. The DWT algorithm implements the reconstruction of non-steady signals. The principles of the DFT algorithm and the DWT algorithm are relatively common. The following mainly introduces the principles of the Mallat algorithm and the Bartlett-Hann window algorithm.

Mallat Algorithm
Wavelet transform can perform time-frequency analysis on signals because it has the ability of multi-resolution analysis [14,15]. According to the idea of multi-frequency analysis, the wavelet transform expansion formula: is a wavelet function, orthogonal to each other, and together constitute the basis function of the wavelet transform. are the reverse order of the decomposition process. The Mallat algorithm implements the decomposition and reconstruction of the three-layer discrete wavelet transform, as shown in Figure   1, where

Bartlett-Hann Algorithm Principle
At present, research on harmonic detection methods based on discrete Fourier transform is mainly focused on finding window functions for fast decay of side lobes, and interpolation algorithms with higher performance. The Bartlett window is very similar to a triangular window as returned by the triang function-both are convolutions of two rectangles. However, the Bartlett window always has zeros at the first and last samples, while the triangular window is nonzero at those points. For odd values of n, the center n−2 points of bartlett (n) are equivalent to triang (n−2) [16]. The formula for the triangular window is shown in Equation (2), and the formula for the Bartlett window is shown in Equation (3).
: : n is anodd number nis aneven number k n k n k k n n w k w k n k n n k n k n k n n n : : n is an odd number nis an even number The Bartlett-Hann window is like the Bartlett, Hanning, and Hamming windows. This window has a main lobe at the origin and side edges that are gradually decaying on both sides. In fact, it is a linear combination of weighted Bartlett and Hanning windows [13,17]. Its near side lobes are lower than the Bartlett and Hanning windows, and its far side lobes are lower than the Bartlett and Hamming windows. Bartlett-Hann windows do not increase the width of the main lobe of the window compared to Bartlett or Hanning windows. According to reference [17], the time-domain expression used to calculate the Bartlett-Hann window is shown in Equation (4): where 0 n N   , the length of the window is 1 L N   . Its frequency domain expression is as shown in Equation (5): where b ( ) X  is the spectrum of the Bartlett window, and its expression is as shown in Equation (6): X  is the spectrum of a rectangular window, and its expression is as shown in Equation (7): Compared with other windows, considering its main lobe width and side lobe attenuation speed, it is suitable for the window interpolation DFT algorithm, has better characteristics of suppressing spectral leakage, can reduce interference between harmonics, and improves the accuracy of signal analysis degree.

Comparison of Bartlett-Hann Windows and Common Windows
In order to verify the advantages of the Bartlett-Hann window, and compared with several common windows, common window functions include rectangular windows, triangular windows, Hanning windows, Heming windows, and Blackman windows. Different window functions have different effects on the frequency spectrum. The main reason is that different window functions produce different frequency spectrum leaks and different frequency resolution capabilities. The use of the DFT algorithm to calculate the frequency spectrum has a fence effect [18].
Both of the above defects cannot be eliminated. In this paper, we can choose different window functions to suppress their effects. The spectral leakage is related to the side lobes on both sides of the window function spectrum. If the height of the side lobes on both sides approaches 0 and the energy is relatively concentrated in the main lobe, closer to the true spectrum can be obtained. For the selection of the window function, the maximum effect of maintaining the maximum information and eliminating the side lobe should be to make the width of the main lobe in the window function spectrum as narrow as possible and the side lobe attenuation as large as possible [19]. The spectral comparison of Bartlett-Hann window and several common windows is shown in Figure 2. It can be seen from the figure that the main lobe of the rectangular window is the most concentrated, but has the largest side lobe peak, and the side lobe attenuation speed is slow, the frequency recognition accuracy is high, and the amplitude recognition accuracy is low. The width of the main lobe of a triangular window is large, about twice that of a rectangular window, and the side lobes are small. The side lobe decays faster than a rectangular window. The width of the main lobe of a Hamming window is similar to that of a triangular window, but the side lobes are smaller and the side fading speed is fast. Both the Hamming window and the Hanning window are cosine windows. The Hamming window is an improved raised cosine window. The width of the main lobe is similar to that of the Hamming window. The decay speed is not as fast as the Hamming window. The main lobe width of the Blackman window is the largest of these common window functions, the side lobe is the smallest, and the side lobe decay rate is the fastest. Based on the comprehensive effect of windowing, the ratio of the Bartlett-Hann window to the rectangular window, Bartlett window, and Hanning window has the maximum side lobe minimum, and the maximum side lobe is −36 dB; compared with Bartlett and Hamming, the Bartlett-Hann window decays faster at farther side; Blackman has the widest main lobe. Although the side lobe decays fastest, its calculation is too large. In general, Bartlett-Hann windows have excellent performance in many aspects and are suitable for window interpolation DFT algorithms.

Comparison of Bartlett-Hann Windows and Common Windows
According to the actual situation of the power grid, the ideal fundamental frequency is 50 Hz, and the maximum amplitude of the fundamental wave is 1. According to the literature [20], a list of some harmonic parameters of the grid except the fundamental wave is shown in Table 1. Table 1. Some harmonic parameters except the fundamental wave in the power grid. 2  3  4  5  6  7  8  9 10

Number of Harmonic
According to Table 1, select the length of the sampling window in twelve signal cycles, set the number of sampling points to 1024, the sampling frequency to 2000 Hz, and the standard grid frequency of 50 Hz as the standard. A comparison has been made between the ordinary DFT algorithm and the interpolation DFT algorithm of Bartlett-Hann window function. The method of calculating relative error is used to reflect the deviation of the measured data from the actual value of the two methods, reflecting the credibility of the method. The calculation formula of absolute error and relative error is as follows: where,  is a relative error,  is an absolute error,  is the measured value and  is a theoretical value. The data are shown in Table 2. As can be seen from Table 2, the accuracy of the ordinary DFT algorithm is weaker than the Bartlett-Hann window function interpolation DFT algorithm. The relative error of the frequency detection of the ordinary DFT algorithm is less than 2.34%, while the relative error of the amplitude detection can reach 254.05%, which does not meet the national power quality standards. However, the interpolation DFT algorithm based on Bartlett-Hann window function has a relative error of less than 1.86% in frequency detection, and a relative error of less than 4.3% in amplitude detection. Therefore, the Bartlett-Hann window interpolation DFT algorithm is relatively accurate for detecting harmonics.

Hybrid Harmonic Detection Method Based on Bartlett-Hann Window DFT and DWT
This paper designs an improved method based on DFT and DWT using Bartlett-Hann window function hybrid detection. The detection accuracy is improved, and the high frequency part harmonics are separated and extracted. The harmonic signal is decomposed into high frequency part and low frequency part by wavelet multi-resolution analysis. The steady-state part exists in the low frequency part, and the non-steady-state part exists in the high frequency part. According to the frequency band situation, the high frequency part may be doped with steady-state harmonic components, resulting in deviations in detection accuracy. For the low frequency steady-state part, we use a Bartlett-Hann window with better side lobe properties to implement windowed interpolation DFT processing to obtain low frequency steady-state components.
For the low frequency part, windowed interpolation is used to obtain the spectral information of the steady-state harmonic components. According to reference [17], assuming a harmonic signal ( ) f t containing the I th harmonic, and a uniform sampling frequency s F , and according to the sampling theorem , a discrete-time signal is obtained as in Equation (9): to obtain Equation (10): When estimating the i th harmonic, if the influence of other component leakage on the i th harmonic is ignored, discretize the formula to obtain Equation (11): (11) where in the discrete frequency interval For the high frequency part, considering whether it is doped with a steady-state signal, a Fourier transform is performed on the reconstructed high frequency part first, and three cases that may exist after the transformation are processed differently. Assume that the high frequency part after wavelet reconstruction is ( ) S n , the average value of all peaks in the first half of ( ) S n is 1 S , the average value of all peaks in the second half is 2 S , and 2 1 2 ( ) / S S S  is the attenuation rate. The degree is considered as a function of decay. The discrete Fourier transform of ( ) S n is ( ) F n . After extracting the parameters of ( ) F n , each harmonic is reduced to ( ) k f n . The three possible situations are handled as follows: (1) Analysis of the reconstructed waveform from the wavelet transform shows that there is no attenuating signal in the high frequency part, but only the steady-state signal. In view of this situation, the parameters extracted from the data obtained by windowed interpolation DFT are used to restore the high frequency harmonics. The ( ) k f n obtained is the result of harmonic analysis. The flowchart of the improved harmonic detection method is shown in Figure 3.

Modeling and Analysis of Power Signals
According to the power signal data, the common steady-state harmonics are the 3, 5, 7, 11, and 13 harmonics, which are also accompanied by some sudden changes, noise, and transient interference. Therefore, the signal model in this paper contains a 50 Hz fundamental wave component of 3,5,7,11,13,19 harmonics, 23 and 33 harmonic attenuation components, and random noise ( ) t  .
Due to the main research on the separation and extraction of each harmonic in the signal, the relative delay in the transmission process of the power grid is not considered temporarily. The signal model can include the three cases mentioned in Section 3 in the case of decomposing three layers, so that conclusion is better proved. The complex harmonic signal model is shown in Equation (12). 20 20 ( ) 220sin(100π ) 21sin(300π ) 15sin(500π ) 13sin (700 ) 8sin(1100π ) 5sin(1300 ) In addition to the common steady-state harmonics, the signal ( ) S t also contains an exponentially decaying harmonic at the beginning, and a random noise ( ) t  with random interference. The signal ( ) S t waveform is shown in Figure 4. According to the national standard power quality public network harmonics requirements for harmonic detection, the actual sampling frequency is 6400 Hz, and the number of sampling points is 1024 [12]. According to the characteristics of the harmonic model, the number of decomposition layers does not need to be too large, so the number of decomposition layers selected by this method is three layers, and multi-resolution analysis is performed on the signal ( ) S t . Taking into account the orthogonality and symmetry of the wavelet base, in order to make the band division effect better, the analysis wavelet used is db10. The decomposition and reconstruction calculation formula using the Mallat algorithm is as follows: The wavelet transform decomposition formula is shown in Equation (13): The reconstruction formula is shown in Equation (14): where, scale 1, 2,..... k N  , the maximum value of k decomposition in this paper is 3. ,  In order to verify the algorithm proposed in this paper, the layers of the signal model are analyzed. The A3 layer is the low frequency steady-state component part, the D3 layer is the high frequency steady-state part, the D2 layer is the high frequency steady-state and attenuation component coexisting part, and the D1 layer is the high frequency attenuation component. The frequency of layer A1 is 1~1600 Hz, the frequency of layer D1 is 1600~3200 Hz; the frequency of layer A2 is 1~800 Hz, and the frequency of layer D2 is 800~1600 Hz; the frequency of layer A3 is 1~400 Hz, and the frequency of layer D3 is 400~800 Hz. The wavelet decomposition coefficients are shown in Figure 5.

Simulation Results of Low Frequency Part of Power Data
Decomposed by the Mallat algorithm, the frequency of the A3 layer is 1~400 Hz, including the fundamental wave and the 3, 5 and 7 low frequency steady-state harmonics. Therefore, the A3 layer is used as the low frequency part, and the A3 layer is reconstructed. The low frequency steady-state part of the A3 layer is shown in Figure 6. The original method is based on the Hanning window function interpolation DFT and DWT mixed harmonic detection method, and the improved method is based on the DFT and DWT using the Bartlett-Hann window function mixed harmonic detection method. In order to compare the accuracy of low frequency part detection between the two, the low frequency steady state portion of the A2 layer after reconstruction is analyzed by the Hanning window function interpolation DFT algorithm and Bartlett-Hann window function interpolation DFT algorithm, respectively. The corresponding frequency spectrum is shown in Figure 7. According to the proposed Bartlett-Hann window interpolation optimization and the literature [21], Hanning window interpolation optimization is compared with the theoretical value. Combining the spectrum analysis result in Figure 7, the DFT analysis frequency and amplitude of the low frequency steady state harmonic component fundamental wave, 3rd, 5th and 7th harmonics are obtained. The comparison is shown in Table 3 and the data obtained in the table are the average of three sets of data.  Table 3 presents the comparison between the proposed low frequency part using the Bartlett-Hann window interpolation DFT and the original method Hanning window interpolation with theoretical values. The steady-state harmonic component results obtained by the two detection methods are very close to the theoretical values. In order to make the test results more intuitive, amplitude accuracy and relative error are used to illustrate the accuracy of the two methods, as shown in Table 4. As can be seen from Table 4, the amplitude accuracy of the interpolation DFT algorithm of the Bartlett-Hann window function is about 95.3375%, and the relative error of the amplitude is less than 5%. The amplitude accuracy of the interpolation DFT algorithm of the Hanning window function is about 93.82%, and the relative error of the amplitude is less than 6%. It can be seen from the accuracy and relative errors that the Bartlett-Hann window function's interpolation DFT algorithm has higher accuracy in detecting harmonics in the low frequency part, which is improved by about 1.5175%. Compared with the data in Table 2, the data in Table 2 directly analyzed the original signal, and the data in Table 4 analyze the data after hierarchical reconstruction, so the relative errors and accuracy are different.

Simulation Results of High frequency Part of Power Data
There are steady-state harmonics and attenuation harmonics in the high frequency portion of the signal. The interpolation DFT and DWT mixed harmonic detection methods based on the Hanning window function can also restore the attenuated harmonic components through layering. If the signal in this frequency band are superimposed, this method cannot subdivide the frequency band. Therefore, the specific parameters of each harmonic cannot be distinguished, and the specific waveform of each harmonic cannot be reconstructed. The method proposed in this paper is based on the original method. It analyzes the harmonics in each frequency band to determine whether there are steady-state harmonics. Using the parameters extracted from the data obtained after windowed interpolation DFT, the harmonics at high frequencies perform the restore. According to the method in Section 3.1, the steady state component and the attenuation component of the high frequency part are separated and extracted. The following three sections will perform harmonic analysis on the three layers in turn.

High Frequency Steady-state Component Simulation Results
Decomposed by the Mallat algorithm, the frequency of the D3 layer is 400~800 Hz. According to the signal model, it can be seen that there are only the 11th and 13th harmonic components. The D3 layer reconstruction is shown in Figure 8. Using the method designed in this paper, each peak is extracted and divided into two parts. After the average value is obtained, the two parts are subtracted to obtain the attenuation rate. The average value of the first half of the peak is equal to the average value of the latter part of the peak, so the attenuation rate is 0. It can be judged that the D3 layer only contains steady-state components, and parameters are extracted from the data after windowing DFT after the reconstructed signal, and the high frequency harmonic signals are restored. The waveform diagram is shown in Figure 9. Based on the Hanning window function interpolation DFT and DWT mixed harmonic detection methods, the steady state components in the high frequency part cannot be restored, so the two methods cannot be compared. It can be seen from Figure 10 that the simulation result is very close to the theoretical value, and its specific data are shown in Table 5. The data obtained in the table are the average of three sets of data.

High Frequency Steady-state and Attenuation Component Simulation Results
The frequency of the D2 layer is 800~1600 Hz, including the 19th and 23rd harmonics. The reconstruction of the D2 layer is shown in Figure 10. In Figure 10, the attenuation trend of the waveform is not obvious. It can be known from the calculation of the attenuation rate that the second half is smaller than the first half, so there is an attenuation harmonic component in the D2 layer. To continue to determine whether it contains a steady-state component, perform DFT processing on the D2 layer, as shown in Figure 11. Amplitude/V Figure 11. D2 layer DFT spectrum.
In Figure 11, there are 19th and 23thharmonic components in the D2 layer, and the amplitude of the 19th harmonic component is 2.84 V. It can be determined that a steady-state harmonic component exists in the D2 layer. Because the DFT can only restore the waveform of the exponentially attenuated harmonic signal as a steady-state harmonic signal, and the amplitude is less than 50% of the actual amplitude; the amplitude of the 23th attenuation harmonic component is 0.77 V. For the steady-state components, the windowed interpolation DFT algorithm can better measure its key parameters, and the restored signal is basically consistent with the actual signal. For the attenuation component, the improved method uses the D2 layer data to subtract the steady-state component windowed and interpolated DFT data, leaving only the remaining attenuation component data as the reconstruction data for the attenuation harmonics. The reconstructed attenuation component is shown in Figure 12. Using the reconstruction attenuation component and data of each harmonic extracted from the D2 layer, the recovered D2 layer waveform is compared with the original data. As shown in Figure  13, the error between the recovered data and the original data may be due to some sample values not being collected.

High Frequency Attenuation Component Simulation Results
The frequency of the D1 layer is 1600~3200 Hz, including the 33th harmonic. The reconstruction of the D1 layer is shown in Figure 14. Only the attenuation component exists in the high frequency part, and the 33th harmonic component can be directly restored by reconstructing the D1 layer. The maximum amplitude at the initial moment is about 10 V, and the waveform is attenuated approximately exponentially.

Conclusions
This paper designs a mixed harmonic detection method based on DFT and DWT using the Bartlett-Hann window function. The improved method realizes the separation and extraction of steady-state harmonics and attenuation harmonics in the high frequency part, which makes up for the shortcomings of the original method. The detection accuracy of the high frequency steady-state is about 95.9%. At the same time, the accuracy of the steady state harmonic detection in the low frequency part is guaranteed. The relative error between the detection accuracy and the theoretical value is less than 5%, and the accuracy is 95.3375%, which is 1.5175% higher than the existing method. Simulation results show that the harmonic detection method designed in this paper not only improves the detection accuracy, but also can more effectively detect and restore each harmonic component in the harmonic signal, which is helpful to improve the ability of harmonic analysis in the power grid. The method proposed in this paper can separate the steady-state harmonics from the high frequency nonsteady-state part and can be applied to the analysis of complex harmonics in the power grid.
The data in this article illustrate the effectiveness and feasibility of the proposed method, not an absolute value. Applying the Monte Carlo simulation algorithm to improve and perfect the proposed method will give us a future research direction.
Author Contributions: G.W. was responsible for theoretical development; C.Z. was responsible for simulation and verification; X.W. helped to collect data as required; G.W. drafted the manuscript and responsible for paper revision; and X.W. was responsible for submission. Each author has contributed to the research approach development. All authors have read and agreed to the published version of the manuscript.

Funding:
The research received no external funding.