## 3 Study on Real-Time Testing of an Isolated Microgrid
### Practical Implementation of the Proposal  
The pseudo-code in Algorithm 1 illustrates a ramp rate control process in a power system using fuzzy logic, incorporating generator frequency as an input. Initially, devices are connected via Modbus to read initial values. A Fuzzy Inference System (FIS) is then defined with three input variables: state of charge of the supercapacitor (\(SC_{SOC}\)), photovoltaic power (\(P_{PV}\)), and generator frequency (\(Frequency\)). An output variable for the desired time window size (WS) is established, and triangular membership functions (trimf) are configured for these variables. Subsequently, fuzzy rules are added to the FIS to determine the data window size (Algorithm 2) based on the inputs. During real-time processing, a continuous loop at regular intervals of 100 ms reads current values from the Modbus devices, applies the FIS to determine the desired data window size (WS), and uses a moving average method to smooth the power output. Finally, the compensated power values (\(P_{PVC}\)) are written back to the Modbus device, and the \(SC_{SOC}\) state of charge is monitored, repeating this process indefinitely to ensure efficient and real-time power control.  
Figure 5: Test bench implemented in the laboratory. Reproduced with permission from [33].  
```
0:\(SC_{SOC}\), \(P_{PV}\), Frequency  Membership functions for \(SC_{SOC}\), \(P_{PV}\), Frequency  Fuzzy rules  Sampling time \(t\)  Initial window: WindowSize \((WS)\) Output: window: WindowSize \((WS)\) Process: Initialization:  Conrect to Modbus devices at IP and port.  Read initial values from \(SC_{SOC}\), \(P_{PV}\) and Frequency system. Define Fuzzy Logic System:  input variables \((P_{PV})\) with ranges [0-15].  input variables \((SC_{SOC}\)) with ranges [0-100].  input variables \((Frequency)\) with ranges [59.1-60.9].  output variable output variable \((WS)\) with range [100-1000].  membership functions for \(P_{PV}\), \(SC_{SOC}\), Frequency  fuzzy rules for decision-making [\(P_{PV}\), \(SC_{SOC}\), Frequency]. Real-time Data Processing (loop indefinitely):  Measure elapsed time (\(t=100\) [ms])  Read current \(SC_{SOC}\), \(P_{PV}\) and Frequency from Modbus.  Inputs = [\(SC_{SOC}\), \(P_{PV}\), Frequency] \(WS\) = evalis(inputs, fis)  window = \(WS\) \(P_{PV}\)= \(PS(P_{PV}\), \(WS)\)  Update Modbus with new power values (\(P_{PVC}\)). End End
```  
**Algorithm 1**Pseudo-code for implementing the V2 GSUN method  
The main flowchart (see Figure 6) describes the implementation of the proposed method. This algorithm begins by connecting to the Modbus system via TCP/IP. Initial data, including \(P_{PV}\), \(Frequency\), \(SoC\), and \(WS\), are input. These data are read and processed in a loop, with an index (\(i\)) incrementing in each iteration.  
In each cycle, the algorithm applies a power smoothing (\(PS\)) technique to the input data to obtain compensated photovoltaic power (\(P_{PVC}\)). This smoothing technique considers the moving window size (\(WS\)), allowing the system's response to adjust according to the PV production and demand variability. The loop continues iterating until a specific stop condition is met, indicated by a decision block with the instruction \"break\".  
The flowchart breaks down the subroutine \(PS(P_{PV}\), \(ma\), \(WS)\), which calculates the moving average of the PV power data (\(ma\)). If the current length of the moving average exceeds the window size (\(WS\)), the moving average is adjusted by removing the oldest data and adding the new PV power data (\(P_{PV}\)). Finally, the average of the compensated PV power (\(P_{PVC}\)) is calculated to smooth the power output and enhance system stability.  
Figure 6: Flowchart for the implementation of the V2 GSUN power smoothing method.