Grid impedance estimation based on improved firefly algorithm

Grid impedance has a great influence on the performance of grid-connected inverters in distributed power generation systems, so accurate grid impedance measurement is a key technique to achieve high-performance adaptive control of grid-connected inverters in weak grid situations. Firefly algorithm has the advantages of global search capability and fast convergence speed, and it has been widely used in the field of parameter estimation. In order to estimate grid impedance accurately and quickly, a grid impedance estimation algorithm based on the improved firefly algorithm is proposed. The grid impedance parameters are taken as the individual of the firefly algorithm, and the simulation model is built in the Simulink environment to compare and analyze the grid impedance estimation effect between the firefly algorithm and the successive iteration method. The simulation results show that the improved firefly algorithm has a higher accuracy for grid impedance estimation.


Introduction
With the large-scale grid-connected distributed power generation units, the power grid gradually shows the characteristics of weak grid, and the impedance of the power grid under weak grid is not negligible and time-varying [1]. A large grid impedance will cause the instability of the grid-connected system, in order to carry out adaptive control according to the size of the grid impedance to ensure the reliable and efficient operation of the system, the inverter needs to measure the grid impedance in real time [2].
With the rise of intelligent algorithms, intelligent algorithms are constantly being used in problems such as parameter estimation, parameter optimization and system identification. In this paper, we propose to improve the grid impedance estimation of firefly algorithm by taking the grid impedance parameters as firefly individuals and searching for Rg and Lg at the same time to eliminate the inherent error in estimation and improve the accuracy of estimation. This method does not introduce additional perturbations and only uses the inherent information of the system to estimate the grid impedance [3]. A grid-tie model is built in Simulink environment, and the simulation compares the effect of iterationby-iteration method and improved firefly algorithm on the grid impedance estimation, and the results show that the improved firefly algorithm estimates the grid impedance with higher accuracy.

Principle of grid impedance detection
As shown in Figure 1, the weak grid can be equated to the grid impedance Zg in series with the ideal grid voltage source Vg. Viewed from the common coupling point of the grid-connected inverter, the grid impedance is divided into three main components, namely, the internal grid impedance, the transmission line impedance and the transformer impedance. In the case of weak grids, the transmission line impedance accounts for the majority of the grid impedance. In order to facilitate analysis and research, the grid impedance needs to be modeled. A number of literature has proposed several grid impedance models, but they are complex and not conducive to impedance measurement analysis, so this paper uses the grid impedance model shown in Figure 1.

Distributed Power Supplies
Grid-connected inverter The grid model contains an equivalent voltage source Vg and an equivalent grid impedance Zg, with Rg and Lg representing the resistive and inductive components of the grid impedance, respectively, and a total impedance of Where ω is the corresponding angular frequency. The grid model gives the relationship between voltage and current at the PCC point Grid impedance measurements are performed on Rg and Lg. The established measurement methods of active measurement require injection of disturbance signals into the grid, which can affect the quality of the injected grid power. The iterative estimation method in the passive measurement method involves an iterative search for Rg and Lg, respectively, with inherent estimation errors.

Grid impedance estimation based on improved firefly algorithm
Firefly algorithm has the advantages of strong global search capability and fast convergence speed, which have been widely used in parameter identification and other fields. Firefly algorithm uses string set search, which can search for multiple parameters at the same time. Therefore, a grid impedance estimation method based on the improved firefly algorithm is proposed to use the grid impedance parameters as firefly individuals and search for Rg and Lg at the same time to eliminate the inherent error in the estimation and improve the accuracy of the estimation [4][5].

Improved Grid Impedance Estimation for Firefly Algorithm
The schematic block diagram of the grid impedance estimation method based on the improved firefly algorithm algorithm is shown in Figure 2. The parameters to be estimated are the grid resistance Rg and the inductance Lg.  Figure 2. Grid impedance estimation based on improved firefly algorithm The module � is a parametric model that defines the grid impedance equivalent model using the transfer function expressed in Eq. (3). Its output is the corresponding estimated parameters � and � to obtain the estimated current i. ∆ is the voltage drop across the grid impedance, i.e., the PCC voltage minus the grid voltage, assuming that the grid voltage is equal to the PCC voltage when the current is zero. The integral of the error squared between the estimated current of the parametric model and the actual model output current is used as an objective function to evaluate the performance of the solution, as shown in Eq. (4). The parameter estimates are obtained by improving the firefly algorithm by changing the estimation parameters to reduce the estimation error and continuously decreasing the objective function value until certain conditions are met.
The process of grid impedance estimation based on the improved firefly algorithm consists of the following steps.
(1) Initialize the population of firefly algorithm, the position coordinates of each firefly individual in the population is the two-dimensional data including the resistive parameter of grid impedance and inductive parameter, the resistive parameter of grid impedance is taken between 0-2Ω, and the inductive parameter is taken between 0-2mH when initializing the position coordinates of firefly individual. The resistive and inductive parameters of the grid impedance were obtained by linear interpolation when initializing the firefly individual position coordinates.
(2) Determine the current estimation model, the current estimation model to grid impedance voltage at both ends, firefly individual position coordinates for the input, the output grid estimated current. As described in Figure 2, � for the model parameters, using its transfer function to define the grid impedance equivalent model, its output is corresponding to the estimated current ̂obtained by estimating parameters � and � , estimating parameters � and � corresponds to the position coordinates of each individual firefly in each generation of the population, ∆v is the voltage drop on the grid impedance, using the estimation of the parametric model. The integral of the error squared between the current and the actual model output current is used as an objective function to evaluate the performance of the solution.
(3) Determine the firefly brightness model which determines the brightness of individual fireflies in a population based on the estimated and actual current of the grid. There are two key elements in the firefly algorithm, namely brightness and attractiveness. Brightness reflects the merits of the firefly's position and determines the direction of movement, with brighter fireflies being able to attract less bright fireflies to move towards them, and also affects the degree of attraction, with the brighter the firefly the greater the degree of attraction; the degree of attraction determines the distance the firefly moves. By continually updating the brightness and attraction of each individual, all individuals eventually converge to the position of the brightest firefly, thus optimizing the parameters. In this paper, the reciprocal of the integral of the estimated current of the current estimation model and the squared error of the actual current is taken as the luminosity of the firefly. Specifically: the firefly luminance model is specified as.
Where is the brightness of the i-th firefly individual, ( ) is the real-time error between the estimated grid current and the actual grid current estimated from the position coordinates of the i-th firefly individual, ̂( ) is the estimated grid current estimated from the position coordinates of the ith firefly individual, ( ) is the actual grid current, and T denotes the iteration period.
(4) Determine the firefly movement model, which updates the position coordinates of firefly individuals based on dynamic step size.
The firefly movement model is specified as.
where ( ) is the position coordinates of the i-th firefly individual in the contemporary population, ( + 1) is the updated position coordinates of the i-th firefly individual in the contemporary population, ( ) is the position coordinates of the j-th firefly individual in the contemporary population, is the Cartesian distance between the position coordinates of the i-th firefly individual and the j-th firefly individual, 0 is the firefly between the maximum attraction, 0 is a constant, γ is a loss factor constant, α(J) is a step factor for contemporary populations, and ∈[-0.5,0.5] is usually a vector of random numbers generated from Gaussian, uniform, or other distributions.
The Cartesian distance is obtained by the following equation. In this paper, the value of 0 is 0.4, i.e., with the evolutionary iteration of the algorithm, the attractive part will rapidly approach 0.4 instead of 1. The result is that firefly individuals will no longer move rapidly towards more optimal individuals. Instead, they tend to be more optimal individuals in a certain proportion.
(5) The firefly algorithm is executed. During the execution of the algorithm, the firefly luminance model is used to determine the luminance of firefly individuals, and each firefly individual searches for other fireflies based on their attractiveness, and moves to individuals whose luminance is greater than their own.
(6) Iterative search until the end of the iteration conditions are met, the output of the contemporary population of the best firefly individual position coordinates to get the grid impedance estimate.
The evolution of the algorithm in the iterative step should have both the ability to develop the uncontained region and the ability to converge and strengthen the region to explore. The development of uncontained regions requires a relatively large step size, while convergence requires a relatively small step size to strengthen the region exploration capability and avoid wasting evaluation times. In this paper, the step factor is updated dynamically during the iterative search in the following manner.
( + 1) = 0.8 ( ) Where α(J) is the step factor of the contemporary population and α(J+1) is the step factor of the updated obtained next generation population.

Simulation & Analysis
In order to validate the grid impedance estimation method based on the improved firefly algorithm, the method is simulated in comparison with the iteration-by-iteration method for estimating line impedance. The single-phase LCL grid-connected inverter simulation model was built in Matlab/Simulink environment, as shown in Figure 3. The improved firefly algorithm and the iteration-by-iteration algorithm were implemented using m-files.

Figure 3. Single-phase LCL grid-connected inverter
The initial value of grid resistance Rg is set to 0.5218Ω and grid inductance Lg is set to 0.3252mH. In the simulation process, the grid resistance is abruptly abated by 1Ω and the grid inductance is abruptly abated by 0.7mH to verify the dynamic performance of the impedance estimation method. Figure 4 is a flow diagram of the grid impedance estimation flow of the improved firefly algorithm, first of all, the grid resistance Rg and grid inductance Lg to be estimated in the impedance range of linear interpolation initialization, and then calculate the objective function Ierr to firefly individual evaluation, Ierr the smaller the estimated current closer to the actual current, that is, the estimated grid impedance closer to the actual impedance. The size of the objective function reflects the accuracy of the grid impedance estimate. The stopping rule is that the objective function value is less than 10 -2 and no longer decreases, when this rule is met, the algorithm outputs the result, otherwise the firefly moves to generate a new individual to evaluate again, and the cycle iterates accordingly.

Start
The initialized Rg is linearly interpolated between 0 and 2 Ω and Lg between 0 and 2 mH.  Figure 5 shows the grid impedance estimation curve for the iteration-by-iteration method, and it can be seen that the objective function value is less than 10 -2 , which can estimate the grid impedance value more accurately. However, the iterative method of estimating grid impedance cannot be used to estimate both the resistance Rg and the inductance Lg at the same time, and this method can lead to estimation errors that cannot be eliminated. Therefore, the objective function value, that is, the minimum estimation error is 10 -4 level. Figure 6 is the improved firefly algorithm grid impedance estimation curve, from the figure can be seen, the objective function value is less than 10 -4 , can accurately estimate the value of grid impedance. The impedance estimation method based on the improved firefly algorithm can simultaneously estimate the resistance Rg and inductance Lg, which eliminates the inherent error caused by the iteration-byiteration method that cannot be estimated simultaneously. At the same time, the firefly moves in space in steps is changing, so it can get more accurate estimation results than the iterative method, the target function value, that is, the estimation error is minimum 10 -6 level.
Comparative analysis of Figure 5 and Figure 6 shows that throughout the simulation process, from the beginning of the estimate to the estimated value stabilized near the actual value, the iteration-byiteration method was carried out about 700 iterations, each iteration to calculate the objective function once, a total of 700 calculations. The improved firefly algorithm was carried out about 30 iterations, with each iteration calculating the objective function once per individual, for a total of 600 calculations. Under the same level of iteration times, comparing the optimal individual objective function values, the improved firefly algorithm is two orders of magnitude smaller than the successive iteration method, so the improved firefly algorithm has a higher accuracy in estimating grid impedance.

Summary
In this paper, a grid impedance estimation method based on an improved firefly algorithm is proposed. Compared with the active grid impedance detection method, this method does not inject harmonic signals into the grid and thus does not affect the power quality. Compared to the iteration-by-iteration method, the impedance estimation method based on the improved firefly algorithm is able to simultaneously estimate the grid resistance and inductance, which eliminates the inherent error in the iteration-by-iteration method and results in a higher estimation accuracy. The simulation model of single-phase LCL grid-connected inverter is built in Simulink environment for grid impedance estimation, and the simulation results prove the correctness of this method.