New SOGI-FLL Grid Frequency Monitoring with a Finite State Machine Approach for Better Response in the Face of Voltage Sag and Swell Faults

: The SOGI-FLL (Second-Order Generalized Integrator –F requency-Locked Loop) is a well-known and simple adaptive filter that allows for estimating the parameters of grid voltage with a small computational burden. However, the SOGI-FLL has been shown to be especially sensitive to voltage sags and voltage swells, which deeply distort the estimated parameters, especially the frequency. This problem can be alleviated by simply using a saturation block at the F requency-Locked Loop (FLL) output to limit the impact of distortion on the estimated frequency. Improving upon this straightforward approach, in this paper we propose the use of a finite state machine (FSM) for the definition of the different states of the SOGI-FLL frequency response during a voltage sag or swell fault. The FSM approach allows for applying different gains during the fault, enhancing the SOGI-FLL transient response. The performance of the FSM-based SOGI-FLL is evaluated by using simulation results, which show a better and faster response to these kinds of faults.


Introduction
The phase, amplitude, and frequency of utility voltage are critical information for the operation of inverter-based distributed generators. Therefore, fast and accurate detection of these voltage parameters is essential to ensure good quality for the power supplied to the grid network. In this regard, the synchronization block of power converters should be able to quickly detect fault events in the grid, like voltage sags, to avoid the deep impact that they have on the estimated parameters of the grid voltage, which is especially strong for the case of the estimated frequency [1].
There are several methods reported in the literature [2][3][4] for obtaining the grid voltage parameters. Among them, the Second-Order Generalized Integrator-Frequency-Locked Loop (SOGI-FLL) is popular due to its simplicity of implementation and low computational requirements [5,6]. The SOGI-FLL behaves well under grid normal conditions and even with some amount of harmonic distortion. The behavior of the SOGI-FLL is well studied in the literature. In [7][8][9], the SOGI-FLL was presented as the coupling between its two main parts, the SOGI and the FLL, whose dynamics correspond to that of a second-order system. However, the behavior of the SOGI-FLL is deeply perturbed by voltage sags, which produce high distortion peaks in the FLL response [10][11][12].
A voltage sag, or dip, is defined by the IEEE 1159 as a short-time reduction in the grid voltage amplitude due to a fault in the line, which can be caused by a short circuit, overload, or starting of large motors [13][14][15][16]. A voltage sag can have a duration that can range from of 0.5 cycles to 1 minute and can go from 0.9 per-unit (pu) to 0.1 pu in voltage magnitude. According to their duration, voltage sags are classified into three categories: instantaneous sags lasting from 0.5 cycles to 30 cycles, momentary sags from 30 cycles to 3 s, and temporary sags from 3 s to 1 minute. If the sag lasts more than 1 minute, it is classified as an undervoltage. In the same way, a voltage swell is defined as a short-time increase in the grid voltage amplitude due to a single line-to-ground fault or by the deenergization of a very large load, among other causes. Voltage swells are classified also into the same three categories made for voltage sags. Voltage swells can be instantaneous, from 0.5 cycles to 30 cycles and for voltage magnitudes that range from 1.1 pu to 1.8 pu; momentary, from 30 cycles to 3 s and for voltage magnitudes that range from 1.1 pu to 1.4 pu; and temporary, from 3 s to 1 minute and for voltage magnitudes that range from 1.1 pu to 1.2 pu. The impact of strong voltage swells such as 1.8 pu in the SOGI-FLL estimated frequency is also high, as in the case of 0.2 pu voltage sags [17][18][19][20][21].
To the authors' knowledge, there are no papers in the literature dealing with the alleviation of the perturbations induced by voltage sags or swells in the SOGI-FLL estimated frequency. However, this distortion can be reduced by simply using a saturation block after the FLL, in order to restrict the output frequency between the grid boundaries where an unlimited time of operation is required, i.e., from 49 Hz to 51 Hz. So, once the frequency reaches one of the saturation bounds during a fault, it will return to normal operation after some recovering time from the fault disappearance.
As a first objective, we propose to further improve the SOGI-FLL response in the event of a voltage sag beyond the basic saturation approach described above. This is accomplished by modeling the system as a finite state machine (FSM) in which different states of the SOGI-FLL are identified. During the perturbation caused by the fault, the FSM algorithm moves through these different states, eventually returning to the normal operation state after the fault is gone. Then, different FLL gains are employed for each of the defined states, which are optimally tuned by a series of trial and error simulations and lead to a better and faster transient response after a voltage sag. The structure of the proposed FSM-based method is simple and only involves the addition of a small computational burden regarding the basic SOGI-FLL approach. Second, the same FSM algorithm is applied for voltage swells, due to the fact that they cause a perturbation in the frequency response that is symmetric and opposite to that of voltage sags. The response for a 1.8 pu voltage swell is like a mirror of the response to a 0.2 pu voltage sag [21][22][23][24][25][26][27]. Consequently, the same FSM is applied to voltage swells with a few additional considerations that make the algorithm more versatile.

SOGI-FLL Response to Voltage Sags
The structure of the SOGI-FLL is shown in Figure 1, where v is the input grid voltage, ω is the center frequency of the SOGI filter, v and v are its in-phase and quadrature-phase outputs, and ω is the FLL estimated grid frequency acting as the center frequency of the SOGI filter.  The SOGI has band-pass filter (BPF) behavior for v and low-pass filter (LPF) behavior for v , with their transfer functions defined as [6] The linearized model of the SOGI-FLL at a quasi-locked operating point has second-order dynamic behavior to a frequency change, described in [2] as where ω is the grid frequency and ω is its nominal value. As seen in (3), the transient response of the estimated frequency to a change in the grid frequency is determined by the system parameters, i.e., the SOGI filter damping factor ξ and the FLL gain λ. These same parameters are responsible for the estimated frequency behavior under whatever input voltage condition, either nominal or perturbed. In particular, the frequency response is greatly distorted in the case of voltage sag faults, exhibiting high nonlinear oscillating peaks.
For SOGI-FLL normal operation, these parameters are designed according to an inherent tradeoff between the rejection of harmonic distortion at the SOGI outputs (1)-(2) and the transient response to frequency step perturbation in the grid voltage (3). An optimal value for the rejection of harmonics was used in [2] and [3] by choosing ξ = 0.707 for the SOGI gain. Also, an optimal damping factor of 1/√2 was recommended in [2] for the transient response to a frequency step perturbation. According to (3), this damping factor leads to FLL gain λ = 0.28 • ω , with ω = 2π · 50 rad/s. The response of the SOGI-FLL to a voltage sag depends on the moment when the fault happens. When the faults take place at non-zero input voltage, they first induce in the estimated frequency a transient peak above the 50Hz nominal level, followed by a second transient peak below 50Hz (see Figure 2a). Conversely, when the faults happen only at zero crossing input voltage, they first produce a peak below 50Hz, followed by another peak above 50Hz (see Figure 2b).  In the following, the responses in Figure 2a,b will be referenced as type-a and type-b, respectively. Figure 2 shows the responses to different voltage sag depths, namely, 20%, 40%, 60%, 80%, and 90%. Type-a sags happen at 0.195 s, when the grid voltage amplitude is negative, and typeb sags happen at 0.2 s, when the grid voltage is at zero crossing. A type-a sag response is also produced for positive values of grid voltage. The SOGI-FLL parameters are ξ = 0.707 and λ = 0.28 • ω (rad/s 2 ). As seen in Figure 2, type-a and -b voltage sags have a high impact on the estimated frequency that increases with the sag depth. Figure 3 shows the evolution of the peak-to-peak amplitude of the estimated frequency distortion with the depth of type-a (upper subplot) and type-b (lower subplot) sags. Note that in both cases the perturbation trend is nonlinear but increases with the sag depth. Also, it is worth mentioning that although type-b voltage sags induce higher distortion in the estimated frequency, their likelihood of occurrence is much lower than that of type-a faults.
In view of Figure 2, the SOGI-FLL performance could be improved by limiting the estimated frequency distortion, which would allow faster system recovery after the fault. A straightforward solution to achieve this could simply be to saturate the estimated frequency at the boundaries where continuous or unlimited time of operation is required in the grid network (49 Hz and 51 Hz, respectively, for European grid codes), which is explained next.

SOGI-FLL with a Saturation Approach
The first approach to face the fault is simply the insertion of a saturation block at the output of the FLL in order to bound the frequency estimation to the 49-51 Hz band, see Figure 4.  Figure 5 shows the response to an 80% depth voltage sag for ξ = 0.707 and λ = 0.28 • ω (rad/s 2 ). Note in Figure 5 that the perturbation is limited by the saturation block and that the time involved in the transient response has also been reduced. Figure 5. SOGI-FLL response to an 80% depth type-a voltage sag. In blue: without a saturation block. In red: with a saturation block.

SOGI-FLL with an FSM approach
The SOGI-FLL response can be further improved by adopting a finite state machine (FSM) for identifying different stages in the frequency response of the system. This approach allows for defining better parameters for each stage of the response, in order to reduce the distortion impact and improve the transient response. A total of five stages in the operation of the SOGI-FLL during the fault are identified for the definition of the FSM.
An FSM is normally used in the definition of automatic control actions for the control of a wide variety of systems. It is defined according to the states identified in the operative steps needed to perform a given process. The FSM evolves from one state to another according to the value of its inputs and outputs in a given moment [14,15].
Proper tuning of the SOGI-FLL parameters is the key point to optimize its response through each one of the possible stages in the face of a fault. The optimization objective consists of retained the system to normal conditions as soon as possible.
In this work, the operation of the SOGI-FLL during a fault is depicted in the FSM of Figure 6, in which the following five stages are defined.

State S1. Normal Operation
The FLL frequency is between the maximum (51 Hz) and minimum (49 Hz) bounds. The SOGI-FLL operates with nominal parameters, designed for obtaining a given estimated frequency behavior. In this work the nominal parameters are = 0.707 and = 0.28 • (rad/s 2 ). In this state, the system is waiting for a fault event, and the FSM will not perform any action until a saturation bound is reached.
The FLL frequency is reduced below 49 Hz due to a fault event, and the FSM keeps the output frequency saturated to 49 Hz. Here, the ξ and λ parameters are changed to different values designed by a trial and error procedure, in order to minimize the duration of the SOGI-FLL time response.

State S3. Up-Saturation
The FLL frequency goes beyond 51 Hz due to a fault, and the FSM holds the output frequency as saturated to 51 Hz. The ξ and λ parameters are optimized in order to achieve a better transient response.

State S4. Up to Down Transient
The FSM moves from state S3 (up-saturation) to S4 when the FLL frequency is lower than or equal to 51 Hz. Once in S4, the FSM can transition to three different states: either to S2 (downsaturation) if the FLL frequency is reduced below 49 Hz, or to S3 (up-saturation) if the FLL frequency again exceeds 51 Hz, or to S1 (normal operation). The transition from S4 to S1 is decided by a counter T which is activated whenever the FLL frequency enters a narrow ±0.02% band, named ∆, around 50 Hz, i.e., between 50.1 Hz and 49.9 Hz. The counter Tc is reset if the FLL frequency leaves that band. Therefore, a return to normal state S1 is only produced if Tc reaches a given maximum value T .

State S5. Down to Up Transient
S5 is reached from S2 (down-saturation) when the FLL frequency is greater than or equal to 49 Hz. Once in S5, the FSM can either go to S3 (up-saturation), or return back to S2 (down-saturation), or go to S1 (normal operation). The return mechanism to the S1 state is the same as that defined previously for S4. If T > T , then the FSM returns to S1.  Figure 7 depicts an example of a usual response of the SOGI-FLL during a voltage sag. Note in this figure how the FSM goes from S1 to S3 when the voltage sag begins, and then transitions from S3 to S4, then to S2, then to S5, and finally returns to S1. It can be seen how at S5 the estimated frequency enters the boundary labeled as 2∆. From this moment, the counter T is started, and the FSM returns to normal state S1 when the maximum count is reached, i.e., when T > T . Note that the checking of the return condition illustrated for a response entering the S5 state also applies to responses entering the S4 state; see the FSM diagram in Figure 6.   During the fault, the FSM-based SOGI-FLL was operated with different ξ and λ gains for each state. The SOGI gain was optimized by a series of trial and error simulations for 90%, 80%, 60%, and 40% sag depths, and the parameter values are shown in the upper section of Table 1 (note that λ is expressed as a fraction of ). The same procedure was carried out for voltage sags of type-b. The ξ and λ values are shown in the lower section of Table 1. Figure 9 shows the transient responses to a 90% sag of the SOGI-FLL (in blue), the saturated (in red) SOGI-FLL, and the FSM-based SOGI-FLL (in green) for this case. As shown in Figure 8, the FSM-based transient response returned to normal operation faster. Figure 9. Transient response to a 90% depth type-b voltage sag. In blue: unsaturated SOGI-FLL. In red: SOGI-FLL with saturation. In green: FSM-based SOGI-FLL.
As can be seen in Table 1, for each state and each depth percentage of voltage sag, there is a progression in the values of ξ and λ. In general, there is an increase in the value of λ as the voltage sag depth decreases, and ξ decreases as the sag depth decreases. This behavior allows for determining the sustained progression trend of the parameters with the several sag depths. To do that, the sag depth is determined as where A is the estimated peak voltage amplitude in pu (i.e., A = A/A , where A = √2 · 230V is the nominal grid voltage amplitude) and x is the voltage sag depth in pu. A is obtained by means of the quadrature outputs of the SOGI as (see Figure 1) Now, with (4) and (5), the equations presented in Table 2 can be used for obtaining the λ values for the cases of type-a and -b sags and for any depth ranging from 40% to 90%. In the case of ξ, the relationship is simpler and only two equations are needed, one for type-a and another for type-b (see Table 3).  Table 3. Equations expressing as a function of the sag depth x for each of the FSM states and sag types.

 = f(x) equation
Type-a = 0.5 +0.35 Type-b = 0.5 +0.3 Figures 10 and 11 show the results of using the equations of Tables 2 and 3 to obtain ξ and λ parameters for type-a and -b sags and for 70% and 50% sag depths, respectively. Observe in Figures  10 and 11 that the FSM-based SOGI-FLL response is less oscillatory and faster than the others, guaranteeing a smooth return to a normal state of operation. Figure 10. Transient responses to a 70% sag depth using the equations of Tables 2 and 3 to obtain and . In blue: SOGI-FLL. In red: SOGI-FLL with saturation. In green: FSM-based SOGI-FLL Upper: type-a sag. Lower: type-b sag. Figure 11. Transient responses to a 50% sag depth using the equations of Tables 2 and 3 to obtain and . In blue: unsaturated SOGI-FLL. In red: SOGI-FLL with saturation. In green: FSM-based SOGI-FLL Upper: type-a sag. Down: type-b sag.
The recovery times of the three SOGI-FLL schemes were obtained for different sag depths, as shown in Table 4. The percentage time reduction of the FSM scheme regarding the SOGI-FLL was also evaluated. Notice that the FSM-based method achieved better results for the deeper voltage sags.

FSM Modification for Grid Frequency Tracking and Response to Grid Harmonics
The FSM was initially designed and simulated working at a constant 50 Hz grid nominal frequency, with fixed saturation bounds at ±1 Hz relative to the nominal value (or ±2 rad/s). Therefore, the FSM could not work properly when the grid frequency is outside these boundaries. The FSM scheme was then modified to be able to track the grid frequency changes. The modification can be seen in Figure 12 and consists of including an LPF in the path supplying the estimated grid frequency  to the FSM. The LPF is first-order and has the following transfer function: where is the LPF output and = 2 is its cutoff frequency (rad/s). The LPF was designed to have a low cutoff frequency with the purpose of achieving the average of the estimated frequency, i.e., where <-> denotes the average. Then, the LPF transient response is slow and serves as an analog memory of the value that the estimated grid frequency  had just before the fault event.
The ω signal was introduced as a new input to the FSM and is used for defining the saturation bound levels, which are now variable. The saturation bounds are determined during normal operation of the FSM, at state S1, and are defined as where ω and ω are the FSM upper and lower saturation bounds (rad/s).
The functioning of (8), (9) can be well understood using the time response depicted in Figure 13, which shows the FSM and ω transient responses to an 80% depth voltage sag happening at t = 0.195 s. The LPF had a cutoff frequency of ω = 10π rad/s. In Figure 13, it can be seen how ω very quickly reaches the upper saturation bound ω at the end of the time interval from 0.1950 s to 0.1964 s, during which the FSM is in the S1 normal operation state. At this point (t=0.1964 s), ω = ω and the FSM state changes from S1 to S3. It is also at this moment that the value of ω is stored in an inner memory variable named ω for later use. Then, ω is defined as According to Figure 13, ω = 2π · 50.019 rad/s and ω = ω + 2π = 2π · 51.019 rad/s. Note that ω is slightly away from the nominal 2π · 50 rad/s value, which supposes that ω is a little bit displaced from the ideal value of 2π·51 rad/s. However, the effect over the behavior of ω is negligible. Consequently, the fixed upper 51 Hz and lower 49 Hz saturation bounds employed in Figure 6 are replaced by the new saturation variables SAT and SAT determined by (8) and (9), respectively, which are stored in inner variables.
Moreover, the return of the FSM to the normal operating conditions state S1, defined in Figure  6 for the transitions from S4 to S1 and from S5 to S1, has also changed. Now, ω is used instead of ω as center of the ±∆= ±0.02% narrow band, i.e., Then, when ω is confined within these bounds, the T counter is started and the return to S1 is decided if T ≥ T . The counter T is reset when ω leaves the band, which can happen due to unexpected interference or to the presence of huge levels of harmonic distortion in the grid. Otherwise, in normal conditions, ω progressively stabilizes, the counter T starts to count when condition (11) is met, and the FSM returns to state S1 when T ≥ T . The value of T can be set to adjust the time needed to return to the normal operation state once the band 2 has been reached. Upon return to state S1, the integrator of the LPF is initialized to the actual grid frequency, i.e., ω = ω (see Figure 13c), which supposes that the system is ready again to face a new fault.
Finally, Figure 14 depicts the results obtained when considering three different scenarios which have in common the occurrence of an 80% depth voltage sag at = 0.22 . In the first scenario, the grid frequency goes from 50 Hz to 50.5 Hz at = 0.15 (blue line), while it remains at 50Hz in the second scenario (red line) and goes down to 49.5 Hz also at = 0.22 in the third scenario (green line). It can be seen how the FSM algorithm is able to follow the step frequency changes and the voltage sags properly. Also, the FSM keeps a saturation band of ±1 Hz on the grid frequency. The same modification explained in this section for tracking the grid frequency changes allows the system to respond to faults happening in grid networks distorted by harmonics. Figure 15 shows the behavior of ω and ω when an 80% depth voltage sag takes place at t = 0.195 s in a grid distorted by a 5th harmonic with 3% amplitude. It can be seen in Figure 15 how the FSM can work properly with the distorted grid voltage. The condition for being able to handle harmonic distortion is that the peak-to-peak amplitude ∆ of the distortion in the grid frequency should be less than the boundary width, i.e., Then, the setting of the value for the boundary 2∆ should take into consideration the maximum harmonic distortion that the FSM has to face. Also, a proper value for T should be chosen to determine a reasonable time for returning the state of the FSM to S1. Figure 16 depicts the response of the SOGI-FLL to voltage swell perturbations ranging from 1.1 pu to 1.8 pu, with optimal parameters ξ = 0.707 and λ = 0.28 • ω rad/s 2 . This figure shows that swell perturbations have a different distortion impact than voltage sags on the SOGI-FLL estimated frequency. Notice in Figure 16 that for swells happening at non-zero input voltage moments (type-a), the perturbations almost do not reach the ± 1 Hz saturation bounds in almost all cases. So, for type-a swells, the FSM will not act. However, for swells happening at zero voltage (type-b), the perturbations surpass the established ± 1 Hz bounds for fault levels ranging from 1.3 pu to 1.8 pu, and the FSM can be applied to these cases to improve the response.

Swell Fault and Short Transient Response Capability
In conclusion, for type-b swells ranging from 1.3 pu to 1.8 pu, ω will reach SAT and the FSM can be applied in the same way that it was applied for voltage sags, provided that the variable x defined in (4) is appropriately modified. For instance, a 1.3 pu swell can be treated by the FSM like a voltage sag of 30% depth if the variable x is set to x = 0.3 pu. In the same way, a 1.8 pu swell can be treated by the FSM as a sag having x = 0.8, or 80% depth. Therefore, the FSM can be applied to voltage sags and swells in the same way by using the following relation instead of (4): where A = 0 holds for voltage sags and A = 2 for voltage swells, and abs(-) represents the absolute value function. The block diagram depicted in Figure 17 clarifies this issue well and is used in the algorithm to differentiate a voltage sag from a voltage swell.  The FSM from here on incorporates the algorithm of Figure 17 and uses equation (13) to respond in the same way to voltage sags or swells. Figure 18 illustrates the response of the SOGI-FLL-FSM to several voltage swells (Figures 18a  and 18b) and sags (Figures 18c and 18d) with different durations. Fault events in Figures 18.a and  18.c extend for four cycles, while those in Figures 18.b and 18.d do so for two cycles, which correspond to the shorter event duration that does not result in overlapped transients at the beginning and at the end of the faults. As fault transients, we consider here the event of a voltage swell or sag and recovery to nominal grid voltage in a short time.
In Figures 18a and 18b, the swells rise to 1.8 pu and then return to 1 pu. In Figures 18c and 18d, the sags go down to 0.2 pu and then return to 1 pu. Notice in these figures that the FSM can respond well to both type of faults, which can improve the capability to respond to short-time-duration transients. Finally, the SOGI-FLL-FSM response to the same voltage sag as that in Figure 18d is shown in Figure 19 when the grid voltage is affected by a 5th harmonic distortion with 4% amplitude. Notice in this figure that the response is similar to that achieved in Figure 18d, but in this case the harmonic distortion is reflected in the estimated frequency response.

Discussion
In this paper we aimed to improve the response of the SOGI-FLL to voltage sags since it is highly sensitive to this kind of fault. We first showed the scope of this problem for a given set of gain parameters. Then, we proposed a simple solution by using a saturation block placed after the FLL integrator to limit the frequency response to the grid operating bounds of 51 Hz and 49 Hz. After that, we proposed an FSM as a way to operate with different SOGI-FLL gains through the pattern developed by the system frequency response to the fault. A set of five stages was identified in the frequency response of the SOGI-FLL to a voltage sag fault. These stages were used to construct an FSM algorithm. The FSM was designed to work on two types of patterns that were identified in the frequency response: type-a and type-b patterns, caused by faults happening at no zero crossing and at zero crossing of the grid voltage, respectively. The FSM allows for defining different SOGI-FLL gains for the different FSM states, according to the fault pattern. The response of the SOGI-FLL was then optimized by a series of trial and error simulations in order to achieve the best responses to given voltage sags with depths ranging from 40% to 90%. Analytical functions relating the system parameters to the sag depths were fitted to the gains obtained by this procedure, facilitating operation with any voltage sag depth. Finally, simulations proved the feasibility of this method that improves the response of the SOGI-FLL to voltage sags and reduces the recovery time involved in the transient perturbation. Moreover, an LPF was incorporated into the defined FSM in order to track the grid frequency changes, including harmonic distortion. Finally, the FSM was also applied to voltage swells, showing that it is able to handle both kind of faults: sags and swells. More research should be performed in order to reduce the number of stages of the FSM and simplify the overall structure. Further research should be performed regarding several aspects, such as applying more elaborate tuning methods for the SOGI-FLL-FSM, which is a nontrivial task due to the increased nonlinearity introduced by the saturation and the highly transient nature of the analyzed sag and swell perturbations. Research should also be performed regarding the introduction of the error signal of the SOGI structure into the FSM algorithm in order to accelerate the response to a fault and reduce the time response. Moreover, the FSM idea can be applied to other grid monitoring approaches and its performance assessed compared with the actual approach.