## 2 Principles of the Compensation Methods
### Harmonic Compensation Method  
The first compensation objective considered here is the mitigation of the harmonic distortion of the load current. It is well known that the waveform of a distorted current can be represented by the sum of different sinusoidal components with frequencies that are a multiple of a fundamental frequency. Equation (2) shows the expression for a generic phase current of a nonlinear load.  
\[i_{L,j}(t)=\sqrt{2}\,I_{1,j}\,\cos(\omega\,t-\varphi_{1,j})+\sqrt{2}\sum_{ \forall\,h\geq 2}\,I_{h,i}\,\cos(h\,\omega\,t-\varphi_{h,i}) \tag{2}\]  
\[i_{c,i}(t)=i_{L,i}(t)-i_{s,i}(t)=\sqrt{2}\sum_{\forall\,h\geq 2}\,I_{h,i}\,\cos(h \,\omega\,t-\varphi_{h,i}) \tag{3}\]  
Equation (3) consists of all the distortion components of the load current. The compensation current (3) allows obtaining a set of sinusoidal currents; thus, after compensation, the source currents are given by (4):  
\[i_{s,i}(t)=\,i_{L1,i}=\sqrt{2}\,I_{1,i}\,\cos(\omega\,t-\varphi_{1,i}) \tag{4}\]  
The currents (4) can be expressed through their rectangular components, (5):  
\[\begin{array}{c}i_{s,i}(t)=\sqrt{2}\,I_{1,i}\,\cos(\omega\,t-\varphi_{1,i}) =\sqrt{2}\,I_{1,i}\,\cos\varphi_{1,i}\cos\omega\,t+\sqrt{2}\,I_{1,i}\,\sin \varphi_{1,i}\sin\omega\,t=\\ A_{L,i}\cos\omega\,t+B_{I,i}\sin\omega\,t\end{array} \tag{5}\]  
where \(A_{I,i}\) and \(B_{I,i}\) are real numbers that represent the rectangular coefficients of the fundamental harmonic of the phase current. It follows that the obtaining of each fundamental harmonic rectangular component of the phase currents determines the currents given by (5), and therefore, the compensation currents (3), which are finally expressed according to (6):  
\[i_{c,i}(t)=i_{L,i}(t)-(A_{I,i}\cos\omega\,t+B_{I,i}\sin\omega\,t) \tag{6}\]  
Three ANNs can estimate the pairs of rectangular coefficients, \(A_{I,i}\), \(B_{I,i}\). They constitute the core calculation of the reference currents for the APF control (Figure 2).  
If a balanced three-phase system is assumed, the rectangular coefficients of the phase quantities are equal; in this case the second subscript \(i\) becomes unnecessary, with the coefficients becoming \(A_{I}\), \(B_{I}\). A single ANN would allow estimating the rectangular coefficients \(A_{I}\), \(B_{I}\), and hence the compensation currents (6), that can now be expressed according to (7):  
\[\begin{array}{c}i_{c,a}(t)=i_{L,a}(t)-(A_{I}\cos\omega\,t+B_{I}\sin\omega\,t )\\ i_{c,b}(t)=i_{L,b}(t)-(A_{I}\cos(\omega\,t-2\pi/3)+B_{I}\sin(\omega\,t-2\pi/3 ))\\ i_{c,c}(t)=i_{L,c}(t)-(A_{I}\cos(\omega\,t+2\pi/3)+B_{I}\sin(\omega\,t+2\pi/3 ))\end{array} \tag{7}\]  
Figure 2 shows the block diagram for the calculation of compensation currents; these are the reference signals in the APF control for HC. The sampling of the phase currents  
Figure 2: Harmonic compensation: generation of the APF reference currents based on the Fourier coefficients provided by the ANNs.  
makes up the set of the neural network inputs. Its outputs are the rectangular coefficients that allow us to build the fundamental harmonic of each phase current. The subtraction with respect to the load currents provides the compensation currents. For a balanced nonlinear load, from (7) it follows that only a neural network is necessary, and therefore, it would only be necessary to sample a load current signal.