## 2 System Modeling
### Obtaining of the Transfer Function  
To implement optimization processes in frequency control of an SG using PSO, the transfer function of the system must first be identified. This research selected offline optimization to ensure robust and efficient controller tuning before real-time implementation. Given the complexity of the system and the need for stability in industrial applications, obtaining the transfer function allows for precise parameter tuning and performance validation under various operating conditions. This approach minimizes computational overhead during real-time execution and enhances the adaptability of the controller to dynamic changes.  
The system's transfer function was obtained employing the input (normalized frequency converter signal from 0 to 2000 as the required speed) and output data (actual speed of synchronous generator). The System Identification Toolbox in MATLAB/Simulink R2021a was employed to derive the transfer function. System identification is the process of determining a dynamic system model using input-output measurements from real systems. Identifying such a dynamic system involves several steps: designing experiments, estimating unknown system characteristics from experimental data, collecting data, creating models, and validating the discovered model. Ensuring a high-performance controller design requires key facilities, which are provided through the formulation of the system model and its attributes.  
By employing offline optimization, the controller is optimized under controlled conditions before real-time operation, reducing uncertainties and enhancing system performance in real industrial environments.  
To obtain the transfer function that defines the nonlinear dynamic behavior of the system, the voltage signal from the frequency converter was used as the input variable, while the actual speed of the SG, taken from the encoder, was used as the output variable. Both input and output data were measured and saved in an Excel file using the data logging function of the SCADA system. For this purpose, 126 measurements were used during the experiment, with a sampling time of 1 s (Ts) for both input and output data. Figure 3 illustrates the data collected from the test, showing the time (in seconds) on the x-axis, the input signal as voltage (V) on the y-axis, and the system output as speed (in rpm) on the y-axis.  
Figure 2: Components of the system.  
As depicted in Figure 4, the measured value of the system is represented by the black line, while the green line corresponds to the output of the simulation model. The best fit of the model, determined using the System Identification Toolbox, is 93.86%. Since the model meets the stability criterion--having all poles and zeros within the unit circle, as illustrated in Figure 5--it is considered valid. This confirms that the model is both stable and performs satisfactorily. The transfer function, identified through system identification (SI), is presented in Equation (1) below.  
\[G_{s}=\frac{10.09s+0.3434}{s^{3}+4.772s^{2}+10.22s+0.3205} \tag{1}\]  
Figure 4: The measured and simulated model output.  
Figure 5: (**a**) Poles and zeroes; (**b**) frequency response.  
Figure 3: (**a**) Input data and (**b**) output data.