Multi-resonant Controller Design for a PV-Fed Multifunctional Grid-Connected Inverter in Presence of Unbalanced and Nonlinear Load

The use of Active Power Filters (APFs) in future power grids with high penetration of nonlinear loads is unavoidable. Voltage Source Inverters (VSIs) interfacing Photovoltaic (PV) generator could play the APF role in addition to power supply. In this paper, the control of a PV-fed multifunctional grid-connected three-phase VSI is addressed with nonlinear and unbalanced load. The control objective is threefold. The first one is to deliver the maximum available power from the PV source to the grid satisfying power quality standards. The second one is the Voltage Balancing Control for DC-link capacitors to guarantee correct operation of the VSI. The last one is shunt APF control to compensate for nonlinear and unbalanced load harmonics, reactive power, and unbalanced sequences. A quasi-Proportional-Resonant (PR) controller with harmonic compensators is proposed for the current control loop. The quasi-PR controller parameters are determined through optimization algorithms such as Particle Swarm Optimization (PSO), Genetic Algorithm (GA), and a combination of both PSO and GA. The aim of the objective function is to improve static and dynamic behavior. The different gains at the fundamental resonant frequency and the selected odd harmonics are obtained for the proposed quasi-PR controller. The dynamic characteristics of the optimized quasi-PR controllers show superiority against conventional ones in terms of gain margin, phase margin, overshoot, and robustness. With the proposed control scheme, the harmonics, reactive power, and unbalanced sequences are appropriately compensated. The performance of the PV-fed VSI shunt APF under irradiance change, load change, and distorted grid voltage conditions is validated through numerical simulations performed on PSIM©\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\hbox {PSIM}^{\copyright }$$\end{document} software. The results show that the grid currents Total Harmonic Distortion for irradiance change case study are 4.57%\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$4.57\%$$\end{document}, 4.57%\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$4.57\%$$\end{document}, and 3.22%\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$3.22\%$$\end{document} in phase a, b, and c with the proposed control method, while they are 9.25%\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$9.25\%$$\end{document}, 5.65%\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$5.65\%$$\end{document}, and 10.12%\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$10.12\%$$\end{document} with conventional instantaneous p-q\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$p-q$$\end{document} theory.


Introduction
Conventional power systems are experiencing serious challenges such as fossil fuel depletion, low energy efficiency, and environmental pollution. These problems are the main driving factors toward using renewable energy resources (Guerrero et al., 2011). These sources of energy are intermittent in nature; hence, interfacing power electronics converters Table 1 A comparative analysis of different shunt APF compensation methods problems are overheating of capacitors, voltage waveform distortion, voltage flicker, and interference with the communication system. Moreover, the IEEE standard limit is 5% total harmonic distortion (THD) at PCC (IEEE, 2014). To cope with the power quality problems, active power filters (APF) and passive power filters  have been extensively used in industrial applications. They can be utilized for harmonic current compensation and harmonic voltage suppression in both shunt and series modes of operation.
In a grid-connected voltage source inverter (VSI) with photovoltaic-fed (PV-fed) system, the connection to the three-phase power grid is realized through a DC-link and an inverter. This inverter could work with multifunctional capability, including APF and power supply (Valedsaravi et al., 2022b). As a consequence, the control of a grid-connected PV-fed VSI can realize different aims such as delivering maximum power to the main grid, guaranteeing grid current high power quality, satisfying IEEE standards, and compensating for the nonlinear local load harmonics, reactive power, and unbalanced sequences.
The most popular control strategies for shunt APF compensation are the instantaneous p −q power theory, based on abc to αβ0 Clarke transformation, and the abc power theory (Akagi et al., 2017). The performance from the p − q theory is poor under three-phase unbalanced load current and distorted grid voltage. The algorithm may produce some harmonics in the grid current, namely hidden currents, which are not present in the local load currents (Czarnecki, 2006). In addition, the algorithm suffers from extra calculation effort in case of multiple harmonic eliminations. In the abc power theory, the active and nonactive components of the currents are obtained through a minimization technique such as the Lagrange Multiplier method and the generalized Fryze currents (Aredes et al., 2003). In the first method, the constraint of the minimization problem is the three-phase instantaneous active power. This method results in poor performance for inconstant three-phase active power and in presence of zero-sequence components. Therefore, the compensation technique will draw undesirable zero-sequence current from the network (Czarnecki, 2004). In the second minimization method, the average value of three-phase instantaneous active power is used to obtain the active components of the currents. As a result, the algorithm is not an instantaneous theory and could have some malfunctions during transient periods (Bitoleanu & Popescu, 2013). To deal with these barriers, a control strategy is proposed in this paper for the shunt APF compensation. The proposed control strategy could have desirable performance in both three-phase three-wire and three-phase four-wire systems. Table 1 shows a comparative analysis of the different shunt APF compensation methods.
The proposed shunt APF control strategy is implemented in the abc reference frame. Therefore, the current control loop reference signal is a sinusoidal waveform with harmonic contents. The proportional-resonant (PR) controller with harmonic compensators is the most usable one in the current control loop. The PR controller design of a gridconnected VSI with an LCL output filter is a challenging task due to the LCL inherent resonance characteristic (Liserre et al., 2006). The control design is more challenging when harmonic compensators are added. The PR controller with harmonic compensators is usually limited to several low-order current harmonics since high-order harmonics can be out of control system bandwidth which can lead to instability problems. The stability analysis of PR-controlled grid-connected inverters with LCL filter is carried out in Liserre et al. (2006) which shows direct dependence on the controller parameters (Schiesser et al., 2018). To tune controller gains, the values of harmonic resonant coefficients are selected equally to the fundamental harmonic coefficient in Castilla et al. (2009) and in Chittora et al. (2017) and are selected inversely proportional to the value of the fundamental harmonic coefficient in Schiesser et al. (2018). However, these ways of coefficient selection are not optimum way as they don't consider the performance of the controller in terms of steady-state and stability criteria. Moreover, the selection of the same coefficients for the higher-order compensators may lead to system instability. Therefore, in this paper, the multi-resonant PR controller coefficients are determined through optimization algorithms which considerably reduces controller design complexity. Moreover, the system's static and dynamic behaviors are improved.
The rest of this paper is organized as follows. In Sect. 2, the system description and parameters are presented. In Sect. 3, the proposed control method with optimized multi-resonant controller are thoroughly presented. The theoretical results

Fig. 1
The schematic circuit diagram of the studied PV-fed system interfacing TLB converter and grid-connected three-phase inverter with shunt APF capability are validated through numerical simulations performed on PSIM © software in Sect. 4. Finally, the concluding remarks are stated in the last section. Figure 1 shows the scheme of the studied system in this paper. It consists of a PV source, a three-level boost (TLB) converter, and a three-phase four-wire grid-connected VSI with an LCL filter. It is worth mentioning that a three-phase network with more than one point grounded can also be classified as a three-phase four-wire system. In this system, the TLB converter performs maximum power point tracking (MPPT) control and DC-link voltage balancing control (VBC). The TLB is used to deliver maximum available power from the PV source to the main grid. A three-phase inverter is interfacing with the main grid and local load through an LCL filter to decrease switching harmonics injection. The nonlinear and unbalanced load involving full-wave bridge rectifiers, series resistor and inductor is located in parallel at PCC. The whole system is connected to the main grid through the PCC. Different components of load current such as harmonics, reactive power, and unbalanced sequences are separated through mathematical equations. Using these components, the reference of grid-side inverter current i * 2 is obtained and then used in the current control loop. The three-phase grid voltages v ga , v gb , and v gc are considered sinusoidal as follows:

System Description
where V ga , V gb , and V gc are the RMS values of grid voltages and ω g is the grid angular frequency. Table 2 shows the system parameters.
The DC-link consists of two identical capacitors each with a voltage V DC /2 grounded at the midpoint. The LCL filter is used to limit current harmonic pollution at the PCC which should be below 5% according to the IEEE (2014) standard. The resistive and inductive value of the main grid at the PCC can be neglected (Wu et al., 2017). Furthermore, the filter Fig. 2 The control diagram of the PV-fed VSI shunt APF resistances representing parasitic losses slightly change the dynamics of the ideal LCL filter and can also be neglected.

System Control
The whole control diagram of the PV-fed VSI shunt APF is shown in Fig. 2. The grid-side inverter current reference i * 2 generation is an important task of the control system. The proposed control method is based on extracting harmonics, negative, and zero sequences of the local load current. First, the harmonic content of the three-phase load current is separated from its fundamental value by subtraction from the measured load current. The load current fundamental components enter the inverse Fortescue transformation to realize the unbalanced sequences of the local load current. The negative and zero sequence of grid-side inverter current references i − 2 ref and i 0 2 ref are set to the load current negative and zero sequences. Thereafter, the positive sequence of grid-side inverter current i + 2 ref is obtained according to the PV power, local load reactive power, RMS value of the grid voltage, and grid synchronization term. Then, Fortescue transformation is used to determine compensated currents i 2a com , i 2b com , and i 2c com for each phase. The load current harmonic contents i La H , i Lb H , and i Lc H are all added to the compensated currents to obtain the grid-side inverter current references i * 2a , i * 2b , and i * 2c . A multi-resonant controller is used for the current control loop. It has 3rd, 5th, 7th, 9th, 11th and 13th harmonic compensators to accurately track the references.

MPPT Control of the PV Source with TLB Converter
The output power of a PV generator is dependent on solar irradiation and ambient temperature. The power-voltage curve of a PV source has a maximum power point (MPP) value. In order to make the system to operate at MPP, different techniques have been proposed such as perturbation and  (Liu et al., 2008). In this paper, the most popular algorithm, P&O, is used for MPPT control of the PV source through the TLB converter. The control diagram of the TLB converter is illustrated in Fig. 3. The output voltage V PV and output current I PV of the PV generator are sensed and then applied as inputs to the MPPT block. The current value of the PV power compares with the past value and a step change is applied to the desired voltage reference V ref in the control loop. Proportional integral (PI) controllers are employed to regulate the input voltage of the TLB converter to its reference value. As shown in Fig. 3, the VBC is another important task of the TLB converter control to guarantee stable operation of the VSI. It can be performed by a PI controller with the input of DC-link voltages subtraction. The PI controller of VBC is designed in such a way that it should be faster than the MPPT control. The switching patterns of the TLB converter are realized through the pulse-width modulation (PWM) method. The phase difference of sawtooth carrier waveforms in the TLB switches is set to 180 • .

Grid Synchronization
In the grid-connected application of VSI, the generated output voltage should be synchronized with the grid voltage. The injected current to the grid should have high power quality. The phase-locked loop (PLL), zero-crossing detection, artificial neural network, and adaptive linear neuron are some of the synchronization techniques proposed in the literature (Hoon et al., 2019). In this paper, the PLL approach is used which has three basic functional blocks known as phase detector, loop filter, and voltage-controlled oscillator as shown in Fig. 4. The loop filter cutoff frequency ω c f is selected as 30Hz. In the proposed PLL technique, the synchronization terms of the three-phase grid voltage, sin(ω g t), sin(ω g t − 2π 3 ), and sin(ω g t + 2π 3 ) are obtained. Table 3 illustrates the selected PI controllers' parameters for the MPPT, VBC, and PLL determined through Ziegler-Nichols tuning method.

Shunt APF Control of VSI
In order to add the shunt APF capability to the three-phase VSI, the harmonic current and positive sequence of grid-side inverter current reference must be determined. The fundamental harmonic detection block is used for the load current harmonic detection. In addition, the PV power, the load reactive power, and the grid voltage are considered for obtaining the positive sequence of the grid-side inverter current reference.

Load Current Harmonic Detection
In order to improve power quality in grid-connected VSIs with nonlinear loads, the detection of harmonic components is needed. These components are part of the compensation signal in the control of grid-connected VSI (Asiminoael et al., 2007). A wide range of harmonic detection methods have been used in both time and frequency domains (Asiminoael et al., 2007). The fast Fourier transform (FFT), discrete Fourier transform, and recursive discrete Fourier transform are the examples of frequency-domain algorithms. In addition, the synchronous reference frame theory, the stationary frame filters, and the notch filters are some examples of the timedomain algorithms. Here in this paper, the FFT is used to detect load current harmonic content. Figure 5 illustrates the block diagram of the fundamental harmonic detection block in phase a. The Fourier transform is utilized in each phase to extract the fundamental harmonic magnitudes and phases. Then, the fundamental harmonic signals are built in each phase. They are subtracted from the load currents to create the load current harmonic reference for the current controller. In each phase, the synchronization terms sin(ω g t), cos( 3 ), and cos(ω g t + 2π 3 ) are applied to the fundamental harmonic detection block. Therefore, the harmonic currents references in phases a, b, and c are extracted independently and imported to the proposed control diagram. The three-phase load current consists of fundamental components i La F , i Lb F , i La F and their harmonic terms i La H , i Lb H , i Lc H which can be expressed as follows: where i La , i Lb , and i Lc are the three-phase load current. Therefore, the load current harmonic references are obtained as follows

Positive Sequence of Grid-Side Inverter Current Reference
In order to obtain the positive sequence of the grid-side inverter current reference, the fundamental components of load current are used. The positive i + L , negative i − L , and zero sequence i 0 L of the fundamental load current can be obtained using the inverse Fortescue transform (Akagi et al., 2017) where a = e j 2π 3 and i + L can be rewritten as follows where I + L and φ i + L are the magnitude and phase of the fundamental load current positive sequence, respectively. The magnitude of the grid-side inverter current reference positive sequence I + 2 ref is dependent on the PV power P PV which can be obtained as follows: The phase of the grid-side inverter current reference positive sequence φ I + 2 re f is obtained through the PV power and the load reactive power Q L . By neglecting the TLB power losses, the inverter active power P i can be considered equal to P PV . The load reactive power is defined as follows: Therefore, the phase of grid-side inverter current reference positive sequence can be found as follows: As a result, the positive sequence of the grid-side inverter current reference i + 2 ref is given by The block diagram of the grid-side inverter current reference positive sequence determination is illustrated in Fig. 6. It could be equivalently expressed in the extended form as follows: At last, the compensated currents i 2a com , i 2b com , and i 2c com in each phase can be found as follows By the summation of the compensated current reference and harmonic current reference, the references of the grid-side inverter currents i * 2a , i * 2b , and i * 2c for shunt APF control of the VSI are given by

Current Control Loop with AD
Different types of controllers have been used for the current control of grid-connected VSIs such as PI, PR (Zmood & Holmes, 2003), predictive (Maccari et al., 2020), hysteresis, and sliding mode control (Hollweg et al., 2021). The PI control strategy in the dq reference frame is the widely used one (Twining & Holmes, 2003). It has a desirable performance in balanced systems. However, it has poor performance in unbalanced and nonlinear systems (Timbus et al., 2009). In this paper, since all the reference signals are sinusoidal, the PR controller is utilized. This controller has less steadystate error and selective harmonics compensation capability (Bojoi et al., 2005).
Furthermore, the high peaking at LCL filter resonant frequency may lead to instability issues. To solve this problem, different damping techniques such as passive damping (PD) and active damping (AD) have been proposed. The PD consists of adding a resistor to one of the filter elements. The use of a resistor as a damper leads to extra losses and less efficiency. Another damping method is the AD method which consists of adding a feedback path to the control system. The advantage of this technique is the removal of power loss. However, it needs an extra sensor and adds complexity to the control system (Dannehl et al., 2010). The damping technique used in this paper is an AD based on the capacitor current feedback loop as illustrated in Fig. 2.

Quasi Multi-resonant Controller Design
The transfer function of the LCL output filter with the additional AD feedback from the inverter output voltage v * ia to the grid-side inverter current i * 2a is In the current control loop, a multi-resonant PR controller is used. The transfer function of the proposed multi-resonant PR controller with odd harmonic compensators up to 13th can be expressed as follows: where K P is the proportional gain, K i(2h−1) | h=1...7 are the resonant gains at the fundamental and selected odd harmonics, ω c is the cutoff frequency, and ω 2h−1 is the frequency of the 2h −1-th odd harmonics. Therefore, the transfer function of open-loop system G c (s).G sys (s) is where a 1 , · · · , a 15 are the nominator and b 1 , · · · , b 18 are the dominator coefficients of open-loop system. As shown in (15), the system loop is 17th order. Therefore, tuning the multi-resonant PR controller parameters is a challenging task. To select the controller parameters, different contradictory constraints should be considered. The first one is the requirement of steady-state error for the grid current. It is related to the magnitude of the loop gain at the fundamental frequency f g . The second and the last constraints are the gain margin and the phase margin, respectively. Hence, a satisfactory region detection for the controller parameters is complex (Henz Mossmann et al., 2021). It is worth mentioning that if the steady-state error, phase margin, and gain margin specifications are excessively strict, the parametric region may be very small or perhaps non-existent. Therefore, in the literature, a simple PR controller is designed for the fundamental component and then its gain is used for all harmonic compensators.
The nine parameters ω c , K P , K i1 , K i3 , K i5 , K i7 , K i9 , K i11 , and K i13 need to be selected for the proposed quasi-PR current controller. The first one is ω c which is related to the grid frequency by 2π f g f g (Ye et al., 2016). To design ω c , the standard limit of grid frequency variation f n is considered ±1%, thereby leading to ω c ≈ 3. This value can satisfy a desirable bandwidth around the resonant frequencies. The application of optimization theories is vastly adopted in modern power systems (Abazari et al., 2019a, b). Also in this paper, to determine the next eight quasi-PR controller parameters, particle swarm optimization (PSO), genetic algorithm (GA), and a combination of PSO and GA named PSO-GA are employed. The objectives of the optimization algorithm are to improve dynamic behavior, stability margins, and reduce the steady-state error at selected odd harmonics. In the rest of this subsection, firstly, the PSO, GA, and PSO-GA algorithms are briefly reviewed and then an optimum quasi-PR current controller is designed.

Optimization Algorithms Definition
The most popular optimization method is the PSO algorithm. The PSO evolutionary algorithm imitates the social interaction of flocks of birds. It makes sufficient use of probabilistic transition rules to do parallel searches of the huge solution space. The feasibility and simplicity of the PSO algorithm make it a popular method for many optimization problems. The PSO algorithm utilizes a swarm of particles, which seek out a multidimensional search space to find the best solution. Each particle has the potential to be the best solution and is affected by the neighbor's experiences. In each iteration of PSO algorithm, i−th particle have a present position x i (t), previous position x i (t − 1), and moving velocity v i (t) in the t−th iteration. The position and velocity of the particle are updated as follows: where W is the PSO inertia weight, c 1 and c 2 are acceleration factors, and ρ is a uniformly distributed random number between 0 and 1. The variables pbest and gbest are the personal best experience and global best experience, respectively. From equation (16), it is obvious that each particle velocity contains three parts. The first one introduces the searching ability of the PSO. The second one is related to the personal experience of the particle, called private thinking, and the last one is related to the global experience of all particles, named collaboration thinking. The PSO coefficients c 1 , c 2 determine the movement speed of particles to pbest and gbest locations. Particles may become away from target zones with small values of c 1 , c 2 . However, large values of these coefficients may result in fast movement in the searching zone. Many research works proved that the acceleration constants c 1 and c 2 should be selected between 1 and 2 (Shi & Eberhart, 1998). The inertia weight W is chosen to make a balance between global and local exploration which results in less number of iterations to find a relatively optimal solution (Bratton & Kennedy, 2007). Figure 7 shows the flowchart of the proposed PSO algorithm.
Another popular optimization algorithm is the GA method. This algorithm is based on a natural selection process mimicking biological evolution. First, a random population of individual solutions is considered. Then, crossover and mutation are applied to the current population in order to create new children. The best solutions for the current population and the created children are considered for the next generation. The algorithm will stop searching when a certain criterion is achieved. The flowchart of the proposed GA algorithm is shown in Fig. 8.
The last optimization technique used in this paper is the combination of the two previous optimization algorithms, called as PSO-GA. In the PSO-GA, both abilities of PSO and GA coexist in one optimization algorithm (Valedsaravi et al., 2022a). In this method, both operators of PSO and GA, including personal experience, global experience,  The PSO-GA algorithm flowchart crossover, mutation, and selection, are applied in each iteration. Figure 9 shows the flowchart of the proposed PSO-GA algorithm.

Designing Multi-resonant PR Parameters by Optimization Algorithms
In this section, the proposed design approach of multiresonant controllers' coefficients is presented. The design approach is formulated as an optimization problem. The optimum values for the control system coefficients K P , K i1 , K i3 , K i5 , K i7 , K i9 , K i11 , and K i13 are obtained through different optimization techniques including PSO, GA, and PSO-GA. The objective function is selected to improve the system dynamic behavior, stability region, and steady-state response, and it is expressed as follows where Gm, Pm, and Mag 2h−1 are the gain margin, phase margin, and harmonic magnitudes in the open-loop system, respectively. It should be noticed that the more magnitude at the selected frequencies, the least steady-state error at that harmonics. The factor α is added to the objective function  in order to make a trade-off between stability and steadystate error at selected frequencies. This factor is set to 0.3 based on the authors' experience in the optimization running. The optimization techniques parameters are shown in Table  4.
The optimum values of the control system coefficients obtained through different optimization techniques are given in Table 5. Figure 10 shows the evolution of the objective function in terms of the iteration number with the proposed PSO, GA, and PSO-GA algorithms. The figure shows that the objective Controller robustness against variation of system parameters function convergence is very close to its optimum value with less than 40 iterations. Table 6 shows the comparative analysis among the PSOtuned, GA-tuned, and PSO-GA-tuned quasi-PR controllers and conventional PR controller (Conv.) with fixed gains at harmonic compensators. It can be seen that the gain margin, phase margin, and overshoot of the control system designed with optimization algorithms are more desirable than the conventionally designed controller. The phase margin, gain margin, and minimum magnitude at selected frequencies for the proposed quasi-PR controller with optimized parameters are obtained as 8.11dB, 31.8 • , and 29.8dB, respectively. These values are appropriate for the practical control systems (Bolton, 2004). With these values, the control system has satisfactory performance in terms of asymptotic stability and steady-state error at selected odd harmonics.
The comparative bode plot of the open-loop system with optimized quasi-PR controllers and the conventional controller is shown in Fig. 11 where the previous values of gain margin and phase margin can be appreciated. It is noteworthy that such stable margins cannot be obtained without the necessary damping which had been applied to the system. In Fig. 12, the step response of the closed-loop system with optimized quasi-PR controllers has been compared with the conventional PR controller. Moreover, the robustness of the optimized controllers against system parameter changes is shown in Fig. 13. The filter inductances and capacitance increase 50% which leads to instability in the system with conventional controller. However, the systems with optimized controllers are still stable. From these figures, it can be seen that the stability and robustness of system has improved with optimized quasi-PR controllers.

Inverter Modulation Technique
The last step is to obtain switching patterns of the VSI. There are different modulation techniques for three-phase inverters. The sinusoidal PWM (SPWM) and space vector PWM (SVPWM) are the widely used ones. In this paper, the SPWM technique is used. In this method, the same amplitude triangular carriers between −1 and 1 are applied for each phase. The switching pattern of VSI is determined as previously shown in Fig. 2.   Fig. 11 The bode-diagram of the open-loop system with different controllers Fig. 12 The step response of the closed-loop system with different controllers Fig. 13 The bode-diagram of the open-loop system when LCL filter parameters increase by 50%

Simulation Results
In this section, the effectiveness of the proposed control approach using optimized controller is validated through numerical simulation performed on PSIM © software. The performance of the system is thoroughly analyzed under PV irradiation step change, nonlinear and unbalanced load step change, and distorted grid voltage. Moreover, the performance of proposed control method is compared with the conventional instantaneous p − q theory. The nonlinear and unbalanced load parameters are given by Table 7.

PV Irradiation Step Change
In the first case study, in order to analyze the PV-fed VSI shunt APF performance, an irradiation step change for the PV is applied at t = 0.2 s from 1000 to 700 W/m 2 . The three-phase grid current, load current, and grid-side inverter current are illustrated in Fig. 14. The grid currents THD are 4.57%, 4.57%, and 3.22% in phase a, b, and c. The harmonic content of nonlinear and unbalanced load three-phase currents i La H , i Lb H , and i Lc H are shown in Fig. 15. The performance of MPPT and VBC control is illustrated in Fig. 16. As shown in this figure, the PV output voltage is appropriately tracking the reference voltage provided by the Fig. 15 The harmonic content of nonlinear and unbalanced load threephase current The grid current and voltage are shown in Fig. 17a. It can be seen in this figure that the grid current and voltage are in phase. It means that the reactive power is effectively compensated. Figure 17b and c illustrates the active and reactive power of the inverter, grid, and load. It can be seen that the injected grid power decreases when the PV output power reduces.
The results from the instantaneous p − q theory and from the proposed method are shown in Fig. 18. As shown in this figure, the THD and the current unbalance factor (CUF) of the three-phase grid current for the proposed shunt APF control method are better than instantaneous p − q theory. Namely, the CUF of negative and zero sequences of the grid current are 5% and 1.4% for the proposed shunt APF control method. However, they are 15% and 1.7% for the conventional instantaneous p − q theory.

Nonlinear and Unbalanced Load Step Change
In the second case study of analyzing the PV-fed shunt APF inverter, a load step change is applied at t = 0.2 s. The resistances of R Lc , R L 1 , and R L 2 reduce to their half values and R La changes to 8 at t = 0.2 s. The three-phase grid current, load current, and grid-side inverter current are illustrated in Fig. 19. The nonlinear and unbalanced load three-phase current and its harmonic content are shown in Fig. 20. The performance of MPPT and VBC control under load step change is depicted in Fig. 21. As shown in this figure, the MPPT and VBC are properly tracking the references.
In Fig. 22a, the grid current and voltage are illustrated. As shown in this figure, the grid current and grid voltage are in phase. Therefore, the load reactive power is totally compensated through the VSI. The active and reactive power of the inverter, the grid, and the load are illustrated in Fig. 22b and c. The PV power is fixed at 10 kW. Therefore, when the     The comparison of three-phase grid current between instantaneous p − q theory and the proposed control method under load step change load power undergoes a step change, the main grid's active power decreases.
The three-phase grid current is shown in Fig. 23 for both when the instantaneous p − q theory used and the proposed control method. From this figure, the THD of i ga , the THD of i gb , the THD of i gc , negative-sequence CUF, and zerosequence CUF are 5.34%, 5.79%, 3.8%, 8.2%, and 2.34% for the proposed shunt APF control method, respectively. These values validate the more satisfactory performance of the proposed method in comparison with conventional instantaneous p − q theory.

Distorted Grid Voltage
The performance of the proposed PV-fed shunt APF inverter is also analyzed under distorted grid voltages. The third harmonic with a magnitude of 60V is added to the grid voltage v ga . The three-phase distorted grid voltage is   Fig. 24. The three-phase grid current, load current, and grid-side inverter current are illustrated in Fig. 25. The grid currents THD with the proposed control method are 5.87%, 5.12%, and 3.73%, while they are 10.33%, 7.97%, and 8% with instantaneous p − q theory. In addition, the three-phase grid current negative and zero CUF with the proposed control method are 8.2% and 2%, respectively. However, they are 24.2% and 3% with instantaneous p − q theory.
The performance of MPPT and VBC control under distorted grid voltage is illustrated in Fig. 26. It can be seen from this figure that the MPPT control and VBC have the desirable performances.
The grid current and voltage are illustrated in Fig. 27a. As shown in this figure, there is no any reactive power consumption from the main grid. Figure 27b and c illustrates the active and reactive power of the inverter, the grid, and the load. The PV power is fixed at P max , 10 kW.
The instantaneous p − q theory and the proposed control method are compared in Fig. 28. It can be observed that the three-phase grid current with the proposed shunt APF control  The grid current and voltage, active power, and reactive power under distorted grid voltage: a grid current and voltage; b active power; c reactive power method is balanced and has less harmonic pollution than the conventional instantaneous p − q theory. The comparative analysis of the proposed control method and the conventional instantaneous p−q theory for different case studies are given by Table 8. Fig. 28 The comparison of three-phase grid current between instantaneous p − q theory and the proposed control method under distorted grid voltage

Conclusions
In this paper, the control of a PV-fed multifunctional gridconnected inverter has been addressed. The studied system consists of a TLB, a three-phase VSI, an LCL output filter, and a nonlinear and unbalanced load. The shunt APF control strategy has been presented to control the grid-side threephase inverter current. A quasi-PR controller was employed to track the sinusoidal references properly due to the presence of nonlinear local load, containing harmonic pollution. To determine controller parameters, optimization algorithms with novel objective function have been used. The parameters of the objective function have been chosen based on static and dynamic performances. Each harmonic compensator of the quasi-PR controller has its own resonant gain with zero steady-state error at that particular harmonic. By virtue of the proposed control method, the PV-fed VSI can act as a shunt APF, capable of compensating harmonic currents, reactive power, and load unbalanced sequences. The proposed method with an optimized controller shows superiority against the conventional control technique. Its effectiveness has been verified by detailed simulations performed on the switched model of the system implemented in PSIM © software. Its advantages can be summarized as follows: • Injecting the PV power adaptively in grid-connected application with low grid current THD; • Desirable performance under irradiation step change, load step change, and distorted grid voltage; • Operating of the VSI as a shunt APF and a reactive power compensator; • Removing zero and negative sequences from the main grid current and desirable CUF; • Optimized quasi-PR controller for grid-side inverter current control; • Desirable dynamic stability and reference tracking for the control system.
Funding Open access funding provided by Universitat Rovira i Virgili. This work has been sponsored by la Diputación de Tarragona under grant Martí i Franquès 2019PMF-PIPF-93 and by the Spanish Ministerio de Ciencia e Innovación under Grants PID2020-120151RB-I00 and PID2019-111443RB-100.

Conflict of interest
The authors declare no conflict of interest.
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecomm ons.org/licenses/by/4.0/.