Least Mean Squares and Recursive Least Squares Algorithms for Total Harmonic Distortion Reduction Using Shunt Active Power Filter Control

This paper deals with the use of least mean squares (LMS, NLMS) and recursive least squares (RLS) algorithms for total harmonic distortion (THD) reduction using shunt active power filter (SAPF) control. The article presents a pilot study necessary for the construction of our own controlled adaptive modular inverter. The objective of the study is to find an optimal algorithm for the implementation. The introduction contains a survey of the literature and summarizes contemporary methods. According to this research, only adaptive filtration fulfills our requirements (adaptability, real-time processing, etc.). The primary benefit of the paper is the study of the efficiency of two basic approaches to adaptation ((N)LMS and RLS) in the application area of SAPF control. The study examines the impact of parameter settings (filter length, convergence constant, forgetting factor) on THD, signal-to-noise ratio (SNR), root mean square error (RMSE), percentage root mean square difference (PRD), speed, and stability. The experiments are realized with real current and voltage recordings (consumer electronics such as PC source without power factor correction (PFC), HI-FI amplifier, etc.), which contain fast dynamic transient phenomena. The realized model takes into account a delay caused by digital signal processing (DSP) (the implementation of algorithms on field programmable gate array (FPGA), approximately 1–5 μs) and a delay caused by the reaction time of the proper inverter (approximately 100 μs). The pilot study clearly showed that the RLS algorithm is the most suitable for the implementation of an adaptive modular inverter because it achieved the best results for all analyzed parameters.


Introduction
This paper deals with the topic of shunt active power filter (SAPF) control [1][2][3][4].The aim of the study is to present a review of the methods of SAPF control used in practice.SAPFs are specially controlled voltage or current inverters, and they have to contain a very powerful computing unit that is able to react to the presence of higher harmonics immediately and reliably compensate these higher harmonics and reactive powers in the network.
Contemporary industrial enterprises usually have several types of electric equipment and loads, which can be separated into linear (heating, lamps, active loads, AC machine) and nonlinear (inverters, uninterruptible power supply (UPS) or LED lighting systems).Semiconductor inverters are the main source of negative effects on voltage quality in electricity distribution systems.These effects include the strain on the electric network from higher harmonics and reactive power.
Nowadays, two types of power filters are commonly used: passive [5] and active [6].A passive power filter (PPF) consists of inductors and capacitors, and its circuit design is simple, but it has the following disadvantages [7]: An individual PPF is suitable only for a specific harmonic component since the harmonics are high or low enough to be eliminated.Designing a group of PPFs for various harmonics is uneconomical.

•
Improving the power factor is less effective using a PPF, and in the case of change in the system architecture, the original design is not applicable.

•
PPF implementation can lead to equipment damage due to the production of series of resonance parallel with the circuit impedance.

•
The source impedance substantially affects PPF filtering properties.

•
If a low-resistance circuit generates additional current harmonics, PPF becomes ineffective.

•
The PPF takes more space.
Active filters can be classified as series active filters, shunt active filters, or a combination of these types.A series active filter solves problems related to voltage harmonics, such as voltage flicker, balancing, or sag.Conversely, a shunt active filter is used for solving current-related issues and reactive power compensation.For active power filter (APF) implementation, power switches, inductors, capacitors, and a control circuit are used.The control circuit calculates the compensation current necessary to prevent resonance by the elimination of current harmonics.The disadvantage of the APF is its greater switching loss than in the case of the passive filter.In addition, the complicated design of the APF controller results in low reliability.However, it is easy to develop microprocessors of power electronic components used in APF implementation, thanks to the modern level of technological advancement, so that these disadvantages can be overcome.The effectiveness of APFs is mainly influenced by determining the current harmonic, which can be obtained from either the frequency or time domain.The frequency domain calculation is based on Fourier analysis, and the time domain approach requires the use of instantaneous reactive power theory [7,8].Using APFs, which are able not only to compensate harmonics but also improve the power factor and voltage regulation under different loads and unbalanced supply conditions, is the most effective solution.This fact has led researchers to develop and implement cost-effective control methods.Today, techniques such as instantaneous reactive power theory (d-q [9,10], p-q [11], modified d-q [12], p-q-r [13], vector [12]) are implemented to compensate current in the electrical grid [14].
The primary objective of the authors is to develop a controlled adaptive modular inverter, which will reflect the advantages of the adaptive systems.In the SAPF control area, these are new, still unused approaches.The adaptive systems are characterized by the ability to change their parameters according to information about the controlled system or processed signal.The real-time identification (adaptive) algorithm is the core of the adaptive system.Modern adaptive systems have already succeeded in many areas and industries (e.g., biological signal processing [15][16][17][18][19]; speech signal processing [20][21][22][23][24]; control and regulation area [25][26][27][28]; etc.), and current practice suggests that the same trend will continue in the future.For the practical use of these methods in real applications, theoretical and practical research of both new and current methods is needed.The application areas of these new approaches to digital signal processing are not very developed yet and are missing in some areas.This can also be said of the area of SAPF control.For this reason, there is a wide scope for further research and development.This paper presents a pilot study in this area.
The idea of adaptation is based on the properties of a living mass, so that we can talk about the so-called bio-inspired approach.It refers to inspiration from the ability of living organisms to adapt their behavior to changes in the environment, even though these changes are unfavorable.This phenomenon is called learning.Among systems that are capable of adaptation (learning), in addition to natural systems, we can now also include technical systems.Learning ability is sometimes considered as a definition of intelligence.It is natural that great effort is dedicated to equipping technical systems with this feature.Technical adaptive systems are characterized by the ability to adjust their parameters to current information about the controlled system or processed signal.
Currently, it is possible to observe a fast development of the methods of adaptive signal processing, e.g., various modifications of the basic adaptive algorithms with stochastic gradient [29][30][31] and recursive optimal adaptation [32][33][34], artificial neural networks [35,36], fuzzy systems [37,38], and their combination, known as fuzzy-neuro systems [38,39].The area of adaptive signal processing is one of the fastest developing scientific/technical subjects.With the development of this area, there is often, and especially in technical practice, a question of how these new methods can be used to solve established goals in real applications.This paper focuses on the application of these methods in SAPF control.
In this study, currently used control methods for SAPF are analyzed in detail.The experimental part of the paper is focused primarily on adaptive methods for SAPF control.This progressive method of control has been increasingly applied over the last few years.Several basic approaches have evolved:
This study deals with the implementation of LMS, NLMS, and RLS algorithms.The goal is to improve their behaviour for dynamically changing currents, where the nonlinear loads are quickly connected and disconnected.The experimental results are evaluated by total harmonic distortion (THD), signal-to-noise ratio (SNR), root mean square error (RMSE), and percentage root mean square difference (PRD).

Shunt Active Power Filter
The parallel active filter forms the controlled current generator connected in parallel to a load.It can remove the unwanted higher harmonic components by generating the same components with the inverse phase and introducing them into the network.Thus, the current carried from the network is filtered and the deformations of the voltage, caused by non-sinusoidal voltage drops on power network impedance, are corrected.In this way, the compensation of the harmonic components can be carried out without the danger of unwanted resonance.Due to the generation of phase-shifted fundamental current harmonics, the filter is able to compensate the reactive power very quickly, eventually altering the asymmetric load to a symmetric one.The parallel filter is connected to the network via a coupling passive filter since the inverter of the active filter itself is the source of higher harmonics.The passive filter is a low-pass LC filter [6].
The current or voltage generator can consist of a bridge connection of semiconductor switches (insulated gate bipolar transistor (IGBT)).This generator in the three-phase system contains six switches and the current or voltage source.In practice, a solution with a voltage-source variant was proved.The desired shape of the current flowing to the filter can be obtained by the appropriate switching of transistors on the bridge.Figure 1

Control Methods for SAPF
Nowadays, SAPF control algorithms can be divided into two basic types of control: control in the time domain [1,49,50] and control in the frequency domain [49,51].The control can be used both for one-phase [52] and three-phase connections [49,50,53] of SAPFs.
The control methods in the time domain can be separated according to a calculation of the compensation quantities (voltages or currents) using techniques working with the instantaneous powers in the power grid: p-q, unity power factor (UPF), perfect harmonic cancellation (PHC), and the synchronous detection method (SDM), or with the components of the instantaneous current values: synchronous reference frame (SRF), Id-Iq [49].
The control algorithm in the frequency domain uses a Fourier analysis, such as discrete Fourier transform (DFT), fast Fourier transform (FFT), or recursive discrete Fourier transform (RDFT), to obtain the reference values.This has the disadvantage of a long computing time and the generation of a time delay.One period of the signal is needed for the computation of FFT.Some publications compute FFT only from a half or a quarter of a period.This is suitable when the signal shape is symmetric over these stages [49].

Control in the Time Domain
Methods using an instant value of the current or powers of the load are often used for this purpose.Some techniques employ suitable algebraic transformations (Clarke transform [9], transformation 3/2).The axis coordinates for these methods are shown in Figure 2.

Instantaneous Inactive Filter Control (p-q Theory)
The p-q method works with instant values in the three-wire or four-wire three-phase power system.It is suitable for the steady-state signals but also for a transition state.This theory is based on the Clarke transformation [9] of the three-phase voltages and currents in coordinates a-b-c into the coordinates α-β-0, with a successive calculation of the instantaneous power components of p-q theory.After transformation, the following voltages and currents in coordinates α-β-0 [11] are obtained: The power components p and q are related to the same α-β voltages and currents, and they can be written down together: For detailed information, see [54,55].

Synchronous Reference Frame Method
Within the SRF method, the source currents (i a , i b , i c ) are first detected and transformed into two-axis stationary coordinates α-β-0 from the three-axis stationary coordinate a-b-c according to Equation (6) [10].
Two direct Park transformations [9] are used there.They enable the evaluation of the specific harmonic component of the input signals and low-pass filter.Next, the two-axis current quantities i α and i β of the stationary axis α-β are transformed into a two-axis synchronous (rotating) coordinate d-q according to Equation (7), where cosΦ and sinΦ represent a synchronous unit of the vectors, which can be generated using a phase locked loop (PLL) [10].
The currents i d and i q contain both AC and DC components.The primary component of the current is the fixed DC part, and the AC component represents a harmonic part.This harmonic component can be easily extracted using the high-pass filter.The current i d is the combination of the fundamental active current (i d_DC ) and the harmonic current of the load (i dh ).The primary component of the current rotates synchronously with the rotating axis, and it can be considered as the direct current.By the filtering of i d , the current representing the fundamental component of the current of the load in the synchronous axis is gained.Thus, the AC component i dh can be obtained by subtracting i d_DC from the total current i d , which leaves behind the harmonic component present in the current of the load.In the rotating axis, the current of axis q (i q ) represents a sum of the fundamental reactive current and of the harmonic currents of the load.The current in axis q can be used for the calculation of the reference compensation current.The inverse transformation is made for the transformation of the currents from the two-axis synchronous axis d-q into a two-axis stationary axis α-β according to Equation (8) [10].
In the end, the current transformed from the two-axis stationary axis α-β-0 back into the three-axis stationary axis a-b-c according to Equation ( 9) and the compensation reference currents i * ca , i * cb , and i * cc are obtained [10].

Control of Instant Values of Current Components (ID-IQ Method)
This method uses the same system of coordinates as SRF, but unlike SRF, there is no need for a phase-locked loop (PLL) and synchronization.The currents i d and i q can be obtained from Equation (10) [50]. where where u α and u β are from p-q theory.This method is also suitable for three-phase systems [50].
The conversion from coordinates d-q to coordinates a-b-c is the same as in the case of SRF.For detailed information see [56].

Control of Instantaneous Inactive Power in Coordinates p-q-r
This theory is characterized by a double transformation process: a first conversion of the voltages and currents from the coordinates a-b-c into coordinates α-β-0 and a second conversion from the coordinates α-β-0 to coordinates p-q-r according to the following equations [13]: The physical importance of the coordinate transformation of the equations mentioned above is shown in Figure 3.The vertical angles from the plane α-β into coordinates a-b-c are the same, namely , and axis a is located above axis α [13].As shown in Figure 4a, the new coordinate α -β -0 is made by rotating axis 0 of the coordinate α-β-0 using angle Φ 1 , which results in the alignment of axis α with a vector of the instantaneous spatial voltage (e αβ ) into the plane α-β.The current of the spatial vector in coordinate α -β -0 can be expressed as [13]  where Similarly, the coordinates p-q-r can occur by the rotation of axis β of the coordinate α -β -0 using angle Φ 2 , as shown in Figure 4b.This results in the alignment of axis α with a vector of the instantaneous spatial voltage (e αβ0 ).The current of the spatial vector in the coordinate p-q-r is expressed as [13] where The axes β and q are identical.By the combination of Equations ( 16) and ( 18), the transformation from coordinate α-β-0 into coordinate p-q-r occurs [13]:

Unity Power Factor
The UPF method requires that the load and active power filter are considered as a linear load.If this is fulfilled, the source current after compensation is expressed as where K according to Equation ( 20) is the conductivity of the nonlinear load and the power active filter.After compensation, the source current is sinusoidal with the same shape as the source voltage, and they are in phase.No higher harmonics are present in the current source, and the power factor is equal to one [1,52].
The power delivered by the source is The reference current of the source is defined as

Perfect Harmonic Cancellation
The result of these methods is the compensation of all of the harmonic currents and the fundamental reactive power taken by the load.The current of the source is in phase with a fundamental component of the voltage of the source at the point of common coupling (PCC) [1].The reference source current is defined as where u + 1 is the spatial vector of voltage with a fundamental harmonic of the source at the PCC.The power delivered by the source is expressed as where In the end, the reference current of the source is defined:

Synchronous Detection Method
This theory can work effectively in symmetric or asymmetric systems because the compensation currents are calculated by taking into account the voltages of individual phases.This theory is used to calculate the compensation currents, while the three-phase source powers a highly nonlinear load.The method of the uniform distribution of the SDM current is used in this study to compute three-phase compensation currents that are supplied by the active filter [53].
When calculating three-phase compensation currents using the method of equal distribution of SDM current, the following assumptions are taken into account: the voltage is not distorted and the loss in the neutral wire is negligible [53].
Assume that the maximal values of source currents are symmetric after compensation: The maximal values of the active curents in each phase after compensation are where P a , P b , and P c are the real powers of each phase, and U am , U bm , and U cm are the maximal values of the voltages of each phase.
Overall average power is defined as By adjusting, we get The currents of the reference active source are calculated as where the compensation currents are defined as

Selection of the Optimal Method
Revuelta et al. [12] analyzed the strategies gained from five formulations of the instantaneous power theory (d-q [9,10], p-q [11], modified d-q [12], p-q-r [13], and vector [12]) applied on symmetrical, asymmetrical, and non-sinusoidal symmetrical nonlinear systems.They compare the performance of the compensation using two quantities measured in the source currents after compensation: the value of THD and the effective value of the current in the neutral wire in a three-phase four-wire system.
The methods p-q, p-q-r, d-q, and vector obtained a zero current through the neutral wire, but the modified p-q methods did not obtain these results.
The vector and d-q methods only gained zero THD after compensation.The p-q and p-q-r techniques reached distortion below 10%.The modified p-q method exceeds this value in both cases.
The effective value of the current through the neutral wire is zero in the case of the symmetric system.Thus, when Equation ( 38) is valid, Since we work with a modular inverter that can work in both single-phase and three-phase systems, there is a requirement that an algorithm also works in both systems.Neither of the above-mentioned three-phase algorithms satisfies this requirement.Of course, there are different variants for single-phase systems, e.g., p-q theory [57,58], but this requires modification of the algorithm for each system.The next requirement is the real-time operating of the algorithms.Neither of the former methods met both conditions, which led us to the idea of using adaptive filtration, with which the authors have extensive experience in other areas.The advantage of the proposed concept is that the adaptive algorithms could effectively work in non-symmetric system, thus a zero current could be reached in the neutral wire.Its next benefit is the possibility of optimal settings of the adaptive filters for the individual phases.It can be expected that these settings will be different for each phase, resulting in better results than in the case of existing methods.

Adaptive Filtration
Adaptive filters are in practice used in an unknown environment, where the preliminary identification is challenging, or in a time-variant environment, which is unpredictable.In these cases, the digital finite impulse response (FIR) or infinite impulse response (IIR) filters with adaptive coefficients, which vary in time, are used.These filters are named adaptive filters [59][60][61][62][63].
Figure 5 shows the general structure of an adaptive filter, where n is the number of iterations, x(n) is the reference signal, d(n) is the input signal, e(n) is the output error signal, and y(n) is the output desired signal.The error signal e(n) is defined as e(n) = d(n) − y(n) and is used to create a purpose function ξ(n), which is needed in the adaptive algorithm to determine the appropriate optimal adaptive filter coefficient.The result of the process is the gradual reduction of the purpose function value to its minimum [59].The purpose function for the LMS algorithm is defined as and the purpose function for the RLS algorithm is expressed as where k = 1, 2, 3, . . .n and parameter λ is denoted as a factor for forgetting in the range of 0 to 1, but it is recommended to use values ranging from 0.95 to 1.
The block diagram of the adaptive filter is shown in Figure 6, where w i represents the coefficients of the scale vector of the transversal FIR filter and Z −1 represents the delay.This block diagram is valid both for LMS and RLS algorithms.In this study, the input signal is in the form of a column vector defined by the following equation: The scale vector of the transversal filter is The output signal of the adaptive filter is expressed as More information about the adaptive filtration is provided in [62][63][64][65][66][67].The algorithms used in this study are further described from the point of view of proper implementation.In [68][69][70][71], the algorithms are explained in detail.It is essential to state that all algorithms were implemented based on virtual instrumentation in the LabVIEW development environment [72][73][74].

Least Mean Squares Algorithm
The LMS algorithm is the main performer in the class of stochastic gradient algorithms based on the theory of Wiener filtration, stochastic averaging, and the least squares method [48].
Each iteration of the LMS algorithm requires three different steps, in this order: 1. Filter output y(n) is calculated according to Equation (43).
2. The value of the estimated error is calculated as e 3. The weights of the filter vector are updated according Equation ( 44) [48].
The parameter µ is called the convergence constant or the step size of the LMS algorithm.It is a low positive constant that influences the properties of algorithm adaptation (the speed of convergence, filter stability, etc.) [48].

Normalized Least Mean Squares Algorithm
If the input signal x(n) gets relatively high values, the use of the LMS algorithm results in amplification of the noise.The normalized LMS (NLMS) algorithm employs a variable convergence constant for each iteration, which is calculated using the input signal power [75][76][77]. where (46)

Discussion of the Choice of Coefficient µ Value
A quantity µ represents a step size.This constant has a significant influence on the speed and stability of the adaptive algorithm convergence.Substitution of the correct value (typically a small positive constant) for µ is necessary for the proper operation of the LMS algorithm:

•
If the selected value of µ is too small, the time required to find the optimal solution by an adaptive filter is too long.

•
If the chosen value of µ is too high, the adaptive filter becomes unstable, and the output brings deviations.
In Figure 7 , the red line shows the optimal trajectory corresponding to the steepest process.Black (LMS algorithm) and green lines (RLS algorithm) represents a way for the coefficients estimation to get closer to the right (optimal) value.It takes several number of iterations n to get to optimal value.Also, it is evident that the given optimization process has its beginning provided by the initial estimation and its ending given by the terminal (optimized) estimation, i.e., P = [w (opt,0) , w (opt,1) ].

Recursive Least Squares Algorithm
The RLS algorithm is a primary performer in the class of recursive algorithms, which are based on the theory of Kalman filtration, time averaging, and the least squares method.In contrast to the LMS algorithm, the RLS algorithm has its own statistic conception.It works with average values of quantities, which are calculated from time outputs [48].
For RLS algorithm implementation, the following steps have to be taken in this order: 1.The filter output is calculated using filter weights from the previous iteration and the present input vector: 2. The vector of the mean gain is estimated using the following equation: 3. The value of the estimated error is calculated according to following equation: 4. The filter weights vector is updated using Equation ( 49) and the vector of the gain is calculated from Equation ( 47): 5. The inverse matrix is computed according to following equation:

Discussion of the Choice of Coefficient λ Value
In [78], the coefficient λ is labeled as the so-called forgetting coefficient, taking values λ ∈ (0, 1 .If λ = 1, then we talk about the estimation without forgetting.Due to the form λ n−i , we can speak of weighting.The input values of the individual signal before i = 1 are considered as zero; the values from the last n sets of values are significant.So, the previous autocorrelation matrix or correlation vector tends to be weighted, adding a correction for the actual values of the autocorrelation matrix or the correlation vector.
During practical implementation, we usually take into account values from λ = 0.98 to λ = 1.For small values of the coefficient λ, a small contribution of the previous samples into the covariance matrix exists.The filter is more sensitive to the actual samples.When i − n, i.e., λ n−n = λ 0 = 1, the mathematical description of the RLS algorithm is reduced to the description of LMS algorithm

Comparison of Mathematical Requirements
From the point of view of the implementation of the adaptive algorithms into digital signal processing (DSP), the computational cost and the memory requirements are especially important.These parameters are shown in Table 1, where M is the filter order.By comparing the mathematical requirements, we can conclude that the RLS algorithm, which obtains better results than the LMS algorithm, has a high computational cost, which has an impact on the hardware requirements (processor and memory) the algorithm works on.

Experiments
Figure 8 shows the block diagram of the experiments, which were made with measured data (PFC is power factor correctio).During the experiments, both voltage and current on one-phase load were measured using National Instruments data acquisition hardware.The voltage was measured by an NI 9225 voltage input module and the current was measured by an NI 9227 current input module.Both NI 9225 and NI 9227 modules were plugged into a cDAQ 9185 chassis, and the chassis was connected to a PC by Ethernet.Voltage and current modules were configured to measure instant voltage and current values using simultaneous sampling with a sampling rate of 50 kSamples/s per channel.The software uses a time window Tw of 10 periods of the fundamental frequency (200 ms for a 50 Hz frequency) according to the IEC 61000-4-30 Ed.2.0.The amplitude of the fundamental harmonic, which serves as the amplitude of the reference sinus waveform, is settled using FFT.
The compensating current is obtained based on the sinusoidal reference current, the nonlinear current of the load, and the settings of the adaptive filter.The compensating current, which is obtained by the adaptive filter, is sent to the inverter, where the compensating current is generated, and then it is sent in the opposite phase to the PCC.However, we did not use the inverter, and were working in simulation mode when the delay of 100 µs was implemented.A 100 µs delay value was chosen because this value will also be performed in our modular inverter.After injecting compensation current, the sinusoidal waveform of the current in the electrical network should occur.Then, the parameters evaluating the filtration quality are computed.Loading of loads from the recorded data was made as if the loads were plugged into a socket.We did not work with the voltage because we are not able to observe a reverse effect of the current after compensation, when a deformation adjustment would occur, without the inverter.
x(n-N-1) Figure 9 shows the one-phase waveform of the current with a substantial distortion of six nonlinear loads when each load has a time window length 100 ms.These loads were immediately changed for the verification of the robustness of the adaptive algorithm.The THD of the signal shown in Figure 9 is 63.27%.Figure 10 shows the FFT and THD for each load, in lengths of 100 ms.Voltage input module NI 9225 has three direct voltage inputs.The incoming analog signal on each channel was conditioned, buffered, and then sampled by a 24-bit Delta-Sigma AD converter.The operating input range of NI 9225 is 850 Vpp (peak-peak).Loads were connected to a low-level distribution system with a nominal voltage of 230 V, 50 Hz, and this voltage was measured.
Current input module NI 9227 has four direct current inputs using a 12 mΩ shunt resistor as a current sensor.The incoming analog signal on each channel was conditioned, buffered, and then sampled by a 24-bit Delta-Sigma AD converter.The operating input range of NI 9227 is 28 App(peak-peak).Thanks to the enormous dynamic range of the 24-bit AD converter, the typical scaling coefficient (SC) was 1.785 µA/LSB.
From the set of loads presented in Figure 9, the smallest currents were measured for the following two loads: (d) HI-FI amplifier in standby mode had a peak-peak current of 30 mA and (f) the audio-tape recorderhad the peak-peak current of 80 mA.From the information above can be calculated the number of AD converter levels used to represent the smallest measured current, 30 mA pp : To calculate the AD converter output word width from the known number of AD converter levels, the following formula can be used: From this formula, it is evident that even the measured current peak-to-peak value (30 mA pp ) is very small in comparison with the input range of the current module (28 A).Thanks to the huge dynamic range of the 24-bit AD converter used, the small signal is theoretically divided into 16806 levels and this corresponds to 14-bit AD converter.
For the measurement equipment, the effective number of bits (ENOB) has to be considered to respect the whole signal-chain and the real AD converter parameters.In the documentation for NI 9227, the ENOB cannot be found, but even subtracting 4 bits because of noise, the smallest measured signal was converted into digital form using a 14−4 = 10 bit AD converter.Regular oscilloscopes use 8 bit AD converters, the high-end oscilloscopes use 10 bit AD converters, and only the best oscilloscopes use 12 bit AD converters [79].

Results
For the purpose of simulation, a delay of 100 µs was added, which corresponds to the delay of the inverter, on which we will apply the algorithms.This delay resulted in the current after compensation not having the clearly sinusoidal waveform that was obtained in the case of adaptive algorithms without delay.However, from the view of the THD, this is a substantial improvement, namely from 63.27 % to 12.51 % when using LMS; to 14.3 % when applying NLMS, and to 6.43 % when utilizing the RLS algorithm.show the waveform of the reference (green) and input (red) signals after filtration.The overshoots in the first 100 ms are caused by the delay of the inverter and by the type of compensated load.The overshoots are not so evident in the case of other types of load.
In Figure 14, the frequency spectras of the signal before and after filtration are shown.Before filtration, there exists a significant level of the third and fifth harmonics in the spectra.Those harmonics are suppressed by filtration using all three adaptive algorithms.Frequency (Hz) Figure 14.FFT of input signal from 0 to 600 ms; (a) before filtration, (b) after applying the LMS algorithm with a filter length of 10 and a step size of 0.005, (c) after applying the NLMS algorithm with a filter length of 100 and a step size of 0.005, (d) after applying the RLS algorithm with a filter length of 2 and a forgetting factor of 0.999.
In Figure 15, you can see that the effect of the inverter delay on the THD was tested as part of adaptive filtration testing when the RLS algorithm was used.It was found that with a filter length of 2 and forgetting factor of 0.999, the delay set from 50 µs to 200 µs had an effect on the THD in the range of ± 8 %.This range varies depending on the filter settings, so the correct adaptive algorithm settings will be crucial for our application.

Total Harmonic Distortion
The THD defines the distortion of the sinus signal, indicated as a percentage.It is defined as a ratio of the sum of all powers of harmonic components and the power of the fundamental harmonic [80,81].
where P 1 is the power of the fundamental harmonic, and P 2 , . . ., P n are the powers of higher harmonics.

Signal-to-Noise Ratio
The SNR is defined as the useful signal standoff from the noise, and it is indicated in decibels (dB).If the SNR is higher than 0 dB, the useful signal is greater than the noise.For the calculation, there is a need to know the ideal (reference) signal [82].

Root Mean Square Error
The RMSE is defined as the mean quadratic error.It settles the difference between real and ideal values.The unit is established according the measured quantity [83].

Percentage Root Mean Square Difference
The PRD is defined as the percent difference of the mean quadratic error [84,85].
The filtration quality can be evaluated using the parameters THD, RMSE, and PRD when the values should be as low as possible and the parameter SNR when the values should be as high as possible.
The LMS and NLMS algorithms have a time of convergence under 100 ms with suitable settings and the RLS algorithm takes approximately 10 ms to stabilize the initial overcoming oscillation.Thus, we examined this time and the steady time separately.
From Tables 2 and 3, it can be seen that during the application of the LMS and NLMS algorithms, the THD is lower with a smaller step size.However, there is a longer time of convergence.For this reason, it is suitable to also compare the signal based on other parameters, such as SNR, RMSE, or PRD.Therefore, the most suitable settings of the LMS algorithm are a filter length of 10 and a step size of 0.001, and for the NLMS algorithm, a filter length of 100 and a step size of 0.001.
Tables 2 and 3 lead to the conclusion that in the case of the RLS algorithm, it is not appropriate to set the value of the forgetting factor under 0.999 because these settings are non-stable or the parameters of the electrical network get worse.The best results were obtained using a forgetting factor of 0.999.The size of the filter length has an impact primarily in transitions where the amplitude changes, and in the case of a large filter length, the overcoming oscillations, which can reach up to multiple of the desired amplitude, occur.µ is the step size; λ is the forgetting factor.

Discussion
The designed conception, "least mean squares and recursive least squares algorithms for total harmonic distortion reduction using shunt active power filters control", can also be used in a three-phase system.It is obvious that the proposal of three independent adaptive systems is needed for the three-phase design.The authors have solved the problematics in [40][41][42]46,48].
The next objective of the research, which will continue on from this study, will be the construction of a proper adaptive modular inverter.Different methods of SAPF control will be tested based on this system.The authors will focus on the development of a current generator designed to inject harmonics into the power grid and a set of nonlinear loads.The system will contain three independent one-phase generators and a module with a separate chokefor the possibility of inserting a defined impedance in the power grid.The generators can be used individually in a one-phase power grid or as a common assembly in a three-phase power grid.It will then be possible to test on this system.
In the authors' opinion, a comparative study of all methods mentioned above (traditional and modern) should be the object of subsequent research (see Figure 16), where ANN is artificial neural network, SRF is synchronous reference frame, SDFT is sliding discrete Fourier transform, and RDFT is recursive discrete Fourier transform.Currently, only a limited amount of comparative studies have been conducted, e.g., [86,87].It is evident that the advanced techniques of signal processing are beginning to be applied in the SAPF control area, where they are still new.Nowadays, no comparative studies, which would compare the individual methods from the view of dynamic properties, THD improvement, implementation complexity, etc., exist.Current trends in the domain of advanced methods of signal processing show that it would be possible to use some of the soft-computing methods for SAPF control [86,88], namely

Conclusions
Within the experiments conducted, the simulation of an adaptive system, which was used to test the representatives of both basic families of adaptive algorithms, LMS and RLS, was undertaken.This system was used for the suppression of higher harmonic components.The practical use may rest in the suppression of higher harmonics and reactive power in an electrical network, primarily in an industry where nonlinear loads are abundantly represented.
The system was tested using real data, which were measured on consumer electronics.In the case of the LMS algorithm, the impact of the filter length and size of the convergence constant on the properties of the examined system was evaluated, specifically the signal distortion and the convergence time.It was shown that the requirements for these two properties are contradictory.By setting the filter length and the convergence constant, we can get either a system with fast adaptation but with a high distortion value, or the converse.In the case of the RLS algorithm, the impact of the filter length and the forgetting factor, which determines how many samples the system remembers, were examined.With an increasing filter length, higher overcoming oscillations occurred with changes in amplitude.

)Figure 3 .
Figure 3.The physical importance of the coordinate transformation between a-b-c and α-β-0.

2 Figure 4 .
Figure 4.The physical importance of the coordinates p-q-r; (a) the relation between coordinates α -β -0 and α-β-0 (a view from the top of axis 0); and (b) the relation between coordinates α -β -0 and p-q-r (a bottom view of axis 0).

Figure 5 .
Figure 5.The structure of the adaptive filter.

Figure 6 .
Figure 6.Block diagram of the adaptive filter.

Figure 8 .
Figure 8. Block diagram of the experiment.

9 .Figure 10 .
Figure 10.FFT of the individual loads; (a) PC source without PFC, (b) HI-FI amplifier on, (c) PC source with passive PFC, (d) HI-FI amplifier in standby mode, (e) PC source with active PFC, (f) audio-tape recorder.

Figure 15 .
Figure15.Influence of inverter delay on shape and THD after applying the RLS algorithm with a filter length of 2 and a forgetting factor of 0.999.(a) after applying a 50 µs delay, (b) after applying a 150 µs delay, (c) after applying a 200 µs delay, (d) FFT after applying a 50 µs delay, (e) FFT after applying a 150 µs delay, and (f) FFT after applying a 200 µs delay.

Figure 16 .
Figure 16.Schematic diagram of current estimation methods.

Table 1 .
Computational cost of the least mean squares (LMS) and recursive least mean squares (RLS) algorithms.

Table 2 .
Results of the experiment using adaptive algorithms for the initial stage (from 0 to 100 ms).
µ is the step size; λ is the forgetting factor.

Table 3 .
Results of the experiment using adaptive algorithms for a settled filter (from 100 to 600 ms).