# Clock Ensemble Algorithm Test in the Establishment of Space-Based Time Reference
## 2 Clock Ensemble Algorithm
### Two-Stage Kalman Clock Ensemble Algorithm  
The NKT algorithm mainly optimizes the long-term stability of the time scale but cannot effectively improve the short-term and medium stability. The TKT algorithm uses the characteristics of the atomic clock model to filter out WFM by one-stage filtering and improves the short and medium-term frequency stability of the time scale [49].  
In the two-stage Kalman filter clock ensemble algorithm, the first filter is used to estimate the two statuses of the clock. There are WFM and RWFM in the first status and only RWFM in the second status. The second filter is similar to the natural Kalman filter, except that there is only one status vector, the phase. It is used to generate the timescale, and the input is the output of the first filter. In this way, the algorithm is equivalent to weighting the time series containing only RWFM. The generated timescale only contains RWFM, and the short and medium-term frequency stability is higher.  
The principle is as follows.  
In a clock group of \(N\) clocks, the \(i+1\) clock is subtracted from the first clock, and the resulting time deviation is denoted \(Z_{i}(t)\), with a total of \(N-1\) time deviation. Therefore, there are \(N-1\) filters and \(N-1\) time deviation processed, respectively. According to the atomic clock stochastic differential equation model shown below  
\[\left\{\begin{array}{c}X_{1}(t)=x_{0}+y_{0}\cdot t+1/2\cdot d\cdot t^{2}+ \sigma_{1}\cdot W_{1}(t)\\ +\sigma_{2}\cdot\int_{0}^{t}W_{2}(s)\ ds\\ X_{2}(t)=y_{0}+d\cdot t+\sigma_{2}\cdot W_{2}(t)\end{array}\right. \tag{6}\]  
\(W_{1}(t)\) and \(W_{2}(t)\), respectively, represent two independent Wiener processes, and each Wiener process follows a normal distribution whose mean is 0 and variance is time \(t\). \(\sigma_{1}\) and \(\sigma_{2}\) are the diffusion coefficients of the two Wiener processes, respectively, which are used to indicate the intensity of noise. The integral of \(W_{1}(t)\) and \(W_{2}(t)\) against time \(t\) is WFM and RWFM, respectively [50].  
Attain two status estimators, denoted as \(\hat{X}_{1,i}(t)\) and \(\hat{X}_{2,i}(t)\). When the Kalman filter is used for status estimation, \(\hat{X}_{1,i}(t)\) contains WFM and RWFM, while \(\hat{X}_{2,i}(t)\) contains only RWFM.  
Then, the time deviation is reconstructed, and for each estimate, let  
\[\widetilde{X}_{1}(t+1)=\widetilde{X}_{1}(t)+\hat{X}_{2}(t)\cdot T \tag{7}\]  
Taking the initial value of the \(\widetilde{X}_{1}(t)\) to be zero, Equation (7) can be rewritten as  
\[\widetilde{X}_{1}(t)=\sum_{m=0}^{t-1}\hat{X}_{2}(m)\cdot T \tag{8}\]Therefore, \(\widetilde{X}_{1}(t)\) is reconstructed through the estimator \(\hat{X}_{2}(t)\) to obtain the reconstructed time deviation. The WFM in the time deviation \(Z(t)\) is filtered out by the first filter and the reconstruction of the time difference, and the reconstructed time deviation containing only RWFM is obtained. Finally, the second filter is a single-status Kalman filter, which is used to generate TA. Since each reconstructed clock only contains RWFM, TA only contains RWFM.