## 3 Adaptive Ensemble Square Root Kalman Filter
### Sage-Husa Algorithm  
In 1969, [PERSON] and [PERSON] presented an improved noise filtering algorithm. The algorithm can compute both matrices of process noise variance \(Q\) and measurement noise variance \(R\)[25; 26] online and in real time when the system noise mean and covariance are unknown. Comparing with the adaptive filtering algorithm based on maximum likelihood criterion, this algorithm adds a forgetting factor, which strengthens the influence of newer observations on filtering and weakens the influence of older observations on the results. This algorithm effectively reduces the influence of model error on filtering, restrains filter divergence, and improves estimation accuracy [27].  
The steps of Sage-Husa algorithm are given as:  
1. Filtering equation: \[\hat{X}_{k+1|k}=F_{k}\hat{X}_{k|k}+\hat{q}_{k}\] (31) \[P_{k+1|k}=F_{k}P_{k|k}F_{k}^{T}+\hat{Q}_{k}\] (32) \[K_{k+1}=P_{k+1|k}H_{k+1}^{T}\left(H_{k+1}P_{k+1|k}H_{k+1}^{T}+\hat{R}_{k+1} \right)^{-1}\] (33) \[e_{k+1}=Z_{k+1}-H_{k+1}\hat{X}_{k+1|k}-\hat{r}_{k+1}\] (34) \[\hat{X}_{k+1|k+1}=\hat{X}_{k+1|k}+K_{k+1}e_{k+1}\] (35) \[P_{k+1|k+1}=(I-K_{k+1}H_{k+1})P_{k+1|k}\] (36)
2. Time-varying noise estimator: \[\hat{r}_{k+1}=(1-d_{k+1})\hat{r}_{k}+d_{k+1}(Z_{k+1}-H_{k+1}\hat{X}_{k+1|k})\] (37) \[\hat{R}_{k+1}=(1-d_{k+1})\hat{R}_{k}+d_{k+1}(e_{k+1}e_{k+1}^{T}-H_{k+1}P_{k+1 |k}H_{k+1}^{T})\] (38) \[\hat{q}_{k+1}=(1-d_{k+1})\hat{q}_{k}+d_{k+1}(\hat{X}_{k+1|k+1}-F_{k+1}\hat{ X}_{k|k})\] (39) \[\hat{Q}_{k+1}=(1-d_{k+1})\hat{Q}_{k}+d_{k+1}(K_{k+1}e_{k+1}e_{k+1 }^{T}K_{k+1}^{T}\] \[+P_{k+1|k+1}-F_{k+1}P_{k+1|k+1}F_{k+1}^{T})\] (40)  
where \(\hat{q}_{k+1}\) represents the mean of process noise at \(k+1\); \(\hat{r}_{k+1}\) is the mean of \(k+1\), \(e_{k+1}\) is the residual at time instant \(k+1\); \(d_{k+1}=(1-b)/(1-b^{k+2})\), \(b\) is the forgetting factor and \(0<b<1\).  
Generally, Sage-Husa algorithm can simultaneously estimate process noise \(\hat{Q}_{k+1}\) and measurement noise \(\hat{R}_{k+1}\). In fact, the algorithm cannot estimate both \(\hat{Q}_{k+1}\) and \(\hat{R}_{k+1}\) at the same time. It can be seen from (37) and (39) that the calculation of \(\hat{Q}_{k+1}\) and \(\hat{R}_{k+1}\) depends on \(e_{k+1}\). The change of \(e_{k+1}\) will affect the calculation of \(\hat{Q}_{k+1}\) and \(\hat{R}_{k+1}\) at the same time, which cannot guarantee the accuracy of the estimation results. In addition, there are minus signs in the calculation of \(\hat{Q}_{k+1}\) and \(\hat{R}_{k+1}\), which may affect the semi-positive and positive definiteness of \(\hat{Q}_{k+1}\) and \(\hat{R}_{k+1}\), leading to filter divergence.  
In the electromechanical transient process of generator, the influence of measurement noise \(\hat{R}_{k+1}\) on the estimation is more important. Generally speaking, process noise \(Q\) is a constant. Assuming that both process noise as well as measurement noise are Gauss, white noise with mean value equals to zero, i.e., \(r=0\) and \(q=0\).  
Sage-Husa algorithm can be simplified as follows.  
1. Filtering equation: \[\hat{X}_{k+1|k}=F_{k}\hat{X}_{k|k}\] (41) \[P_{k+1|k}=F_{k}P_{k|k}F_{k}^{T}+Q\] (42) \[K_{k+1}=P_{k+1|k}H_{k+1}^{T}(H_{k+1}P_{k+1|k}H_{k+1}^{T}+\hat{R}_{k+1})^{-1}\] (43) \[e_{k+1}=Z_{k+1}-H_{k+1}\hat{X}_{k+1|k}\] (44) \[\hat{X}_{k+1|k+1}=\hat{X}_{k+1|k}+K_{k+1}e_{k+1}\] (45) \[P_{k+1|k+1}=(I-K_{k+1}H_{k+1})P_{k+1|k}\] (46) 2. Measurement noise estimator: \[\hat{R}_{k+1}=(1-d_{k+1})\hat{R}_{k}+d_{k+1}(e_{k+1}e_{k+1}^{T}-H_{k+1}P_{k+1|k }H_{k+1}^{T})\] (47)  
In order to ensure the positive covariance of measurement noise, (47) is replaced by (48). It can be seen from the formula that a certain filtering-precision is sacrificed to ensure the stability of the filter.  
\[\hat{R}_{k+1}=(1-d_{k+1})\hat{R}_{k}+d_{k+1}(e_{k+1}e_{k+1}^{T}) \tag{48}\]