# IoT-Driven Resilience Monitoring: Case Study of a Cyber-Physical System
## 5 Cyber-Physical System
### Energy Digital Twin: Virtual World Interactive Model
#### 5.3.3 Ideal State Service  
The ISS provides anomaly detection functionality within the SPVS. Anomalies are characterized by a number of factors such as soiling, shading, CP attacks, and component malfunctions, which require fast and accurate detection in order to optimize the performance of the system and guarantee the service continuity. The ISS is meant to estimate the ideal production parameters for a given set of real-time factors, including temperature, solar irradiation, and energy demand. Such an estimate can be carried out either analytically, i.e., using a mathematical model of the SPVS equivalent circuit [87], illustrated in Figure 11, or using a ML model trained on real-world data. The ISS compares the estimated values of current (I), voltage (V), and power (P) with the measured set of corresponding parameters provided by the OS. If a gap between the two sets of parameters crosses certain defined tolerance thresholds, an anomaly is detected. The event diagram illustrated in Figure 12 illustrates the process of estimation and comparison implemented by the present service. Figure 10: Interactive Platform Interface [82]. In particular, the estimation of production values involves numerical models based on the solution of the set of differential equations reported below (note: In Equation (5), \(I_{pv}\) is the output current of the PV cell, \(I_{g}\) is the actual photocurrent, \(I_{d}\) is the current of the diode, and \(I_{sh}\) is the current of the shunt resistor, \(K_{i}\) is a parameter provided in the datasheet or technical documentation of a specific photovoltaic device or solar cell, \(I_{gu}\) is photocurrent STC (Standard Test Condition), G is the actual irradiance, \(G_{n}=1000\) [\(W\)/m\({}^{2}\)], the irradiance at STC, \(K_{i}\) is the temperature coefficient, and \(T\) is the actual temperature in Kelvin. \(T_{0}\) is the temperature STC (typically 298 Kelvin), \(V_{T}\) is the thermal voltage, calculated as \((K*T)/q\), \(K\) is the Boltzmann constant = \(1.3806503\times 10^{-23}\), \(J\)/K, \(T\) is the actual temperature of the p-n junction in Kelvin, and q is the elementary charge = \(1.60217646\times 10^{-19}\), C). \[ \begin{split} I_{pv}&=I_{g}-I_{d}-I_{sh}\\ I_{\text{d}}&=I_{0}\bigg{(}e^{\frac{V}{nkT}}-1 \bigg{)}\\ I_{\text{g}}&=I_{\text{gn}}\bigg{(}\frac{G}{G_{n}} \bigg{)}(1+K_{i}(T-T_{0}))\\ I_{\text{sh}}&=\frac{V_{\text{oc}}}{R_{\text{sh}}} \bigg{(}1-\exp\bigg{(}\frac{qV}{nKT}\bigg{)}\bigg{)}\end{split}  \tag{5}\]  
By solving these equations, it is possible to assess the data for the system functioning in totally ideal conditions. However, real-world data are inherently dynamic and non-linear. Data collected from real-world systems inevitably contains noise, introducing uncertainty around the signal value. To enhance the robustness of the estimation process, a real-world-similar synthetic data generation approach is employed, based on the methodology introduced and described in [88; 89]. This approach helps with ensuring  
Figure 11: The equivalent circuit of the PV module with the load. Figure 12: The block diagram of Kalman filter method that is used in current approach. that there is a more reliable estimation of production values, simulating the impact of noise in data acquisition systems into data. In particular, the process involves a Rolling Window Regression algorithm that is initially trained with noise-free synthetic data. Noise is then introduced to the estimated data using various distributions and, subsequently, a Kalman filter is applied to filter the noisy data, as illustrated in the flowchart in Figure 12. Finally, the optimal distribution is selected based on the best Mean Squared Error of the AI algorithm, recognizing that different distributions may better suit each parameter. As a result, a dataset that contains I, V, and P values for different temperatures and irradiation is built.