## 5 Harmonic Compensation Principle  
The harmonic compensation principle is illustrated in Figure 7, demonstrating the operation of the GFMC APF at the PCC when a nonlinear load is connected to the system. When the GFMC APF is inactive in the initial stage, the nonlinear load generates harmonic currents \(i_{1}\), which flow through the grid inductor \(L_{\mathrm{s}}\). These harmonic currents lead to significant harmonic voltage distortions at the PCC, as the grid inductor creates a reactive impedance that amplifies the effect of the harmonics. At this point, the harmonic distortions remain unmitigated because the GFMC APF is not active to counterbalance the effects of the nonlinear load, resulting in poor voltage quality at the PCC. When the GFMC APF is activated, harmonic voltages at the PCC begin to be injected to counteract the harmonic distortions caused by the harmonic currents generated by the nonlinear load. During the transient stage, the harmonic voltage at the PCC is represented as \(v_{\mathrm{gh}}\angle 0^{\circ}\), corresponding to the phase and magnitude of the harmonic disturbances present in the system. To mitigate these distortions effectively, the GFMC APF generates a harmonic voltage command with a phase opposite to the harmonic voltage, specifically \(K_{\mathrm{sc}}\times v_{\mathrm{gh}}\angle 180^{\circ}\), where \(K_{\mathrm{sc}}\) is the scaling factor determining the amplitude of the injected compensation voltage. The tuning of \(K_{\mathrm{sc}}\) is crucial for practical implementation. It is determined through a stability analysis, as outlined in Section 4, where the parameter is adjusted to optimize harmonic suppression while ensuring system stability. In practical systems, \(K_{\mathrm{sc}}\) is constrained by the need to avoid excessive compensation that could lead to instability due to interactions with grid impedance; typically, it is limited to a range where the gain margin remains positive, with an upper bound set to prevent oscillations, as validated by simulations showing stable operation with \(K_{\mathrm{sc}}\) values up to 0.3. The optimal \(K_{\mathrm{sc}}\) value of 0.1, as  
Figure 6: Bode plots of the system with and without RC. \begin{table}
\begin{tabular}{c c c} \hline \hline
**RC Gain** & **Effect with Qz = 1** & **Effect with Qz \textless{} 1** \\ \hline \multirow{2}{*}{\(K_{\mathrm{r}}=0.1\)} & Moderate harmonic suppression, high-frequency peaks present & Smooth high-frequency response, high gain margin, stable system \\ \hline \multirow{2}{*}{\(K_{\mathrm{r}}=0.3\)} & Effective harmonic suppression, prominent harmonic peaks & Reduced high-frequency instability, moderate gain margin, reduced stability \\ \hline \multirow{2}{*}{\(K_{\mathrm{r}}=0.5\)} & Strong harmonic suppression, very prominent harmonic peaks & Mitigated high-frequency peaks, low gain margins, unstable system \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Effects of \(K_{\mathrm{r}}\) and \(Q_{\mathrm{z}}\) on system stability and harmonic suppression. selected in this study (refer to Table 2), balances these factors, ensuring effective harmonic mitigation without compromising grid stability. This harmonic voltage injection cancels the existing harmonic voltage by creating a constructive destructive interference effect. This injection reduces the effective line impedance from \(L_{\text{gg}}\) to a lower value of \(L_{\text{gg}}/(1+K_{\text{sc}})\), effectively creating a low-impedance path for the harmonic currents. This low-impedance path enables the harmonic currents to flow through the GFMC APF rather than through the grid, greatly reducing the harmonic distortions at the PCC. As a result, the GFMC APF successfully suppresses the harmonic distortions, while the fundamental component of the voltage remains unaffected, preserving the stability of the grid's operation.