## 5 Weighted Least-Squares Approach to State Estimation
### Contemporaneous Form  
First, the contemporaneous form of the state space model is considered, which is also the form employed by [PERSON] and [PERSON]. The starting point is given by writing down the equations of the state space model, Equations (1) and (2), for all time points, \(t=1,\ldots,N\):  
\[ \begin{split}\mathbf{x}_{1}&=\mathrm{A}_{1}\mathbf{x }_{0}+\eta_{1}\\ \mathbf{y}_{1}&=\mathrm{C}_{1}\mathbf{x}_{1}+ \boldsymbol{\epsilon}_{1}\\ \mathbf{x}_{2}&=\mathrm{A}_{2}\mathbf{x}_{1}+ \eta_{2}\\ \mathbf{y}_{2}&=\mathrm{C}_{2}\mathbf{x}_{2}+ \boldsymbol{\epsilon}_{2}\\ \vdots\\ \mathbf{x}_{N}&=\mathrm{A}_{N}\mathbf{x}_{N-1}+ \boldsymbol{\eta}_{N}\\ \mathbf{y}_{N}&=\mathrm{C}_{N}\mathbf{x}_{N}+ \boldsymbol{\epsilon}_{N}\end{split}  \tag{58}\]  
Note that in the first of these equations, the term \(\mathrm{A}_{1}\mathbf{x}_{0}\) can be interpreted as the prediction of the state at time \(t=1\), denoted as \(\mathbf{x}_{1|0}=\mathrm{A}_{1}\mathbf{x}_{0}\). Then, the set of Equation (58) may be rearranged as  
\[ \begin{split}-\mathbf{x}_{1|0}&=-\mathbf{x}_{1}+ \boldsymbol{\eta}_{1}\\ \mathbf{y}_{1}&=\mathrm{C}_{1}\mathbf{x}_{1}+ \boldsymbol{\epsilon}_{1}\\ \mathbf{0}&=\mathrm{A}_{2}\mathbf{x}_{1}-\mathbf{x}_{2}+ \boldsymbol{\eta}_{2}\\ \mathbf{y}_{2}&=\mathrm{C}_{2}\mathbf{x}_{2}+ \boldsymbol{\epsilon}_{2}\\ \vdots\\ \mathbf{0}&=\mathrm{A}_{N}\mathbf{x}_{N-1}-\mathbf{x}_{N}+ \boldsymbol{\eta}_{N}\\ \mathbf{y}_{N}&=\mathrm{C}_{N}\mathbf{x}_{N}+ \boldsymbol{\epsilon}_{N}\end{split}  \tag{59}\]  
By defining  
\[\mathcal{Y}= \begin{pmatrix}-\mathbf{x}_{1|0}\\ \mathbf{y}_{1}\\ \mathbf{0}\\ \mathbf{y}_{2}\\ \vdots\\ \mathbf{0}\\ \mathbf{y}_{N}\end{pmatrix} ,\quad\mathcal{X}= \begin{pmatrix}\mathbf{x}_{1}\\ \mathbf{x}_{2}\\ \mathbf{x}_{3}\\ \vdots\\ \mathbf{x}_{N-1}\\ \mathbf{x}_{N}\end{pmatrix} ,\quad\mathcal{E}= \begin{pmatrix}\boldsymbol{ \eta}_{1}\\ \boldsymbol{\epsilon}_{1}\\ \boldsymbol{\eta}_{2}\\ \boldsymbol{\epsilon}_{2}\\ \boldsymbol{\eta}_{3}\\ \vdots\\ \boldsymbol{\eta}_{N}\\ \boldsymbol{\epsilon}_{N}\end{pmatrix}  \tag{60}\]  
and  
\[\mathcal{A}= \begin{pmatrix}-\mathrm{I}^{(m)}&0&0&\ldots&0&0\\ \mathrm{C}_{1}&0&0&\ldots&0&0\\ \mathrm{A}_{2}&-\mathrm{I}^{(m)}&0&\ldots&0&0\\ 0&\mathrm{C}_{2}&0&\ldots&0&0\\ 0&\mathrm{A}_{3}&-\mathrm{I}^{(m)}&\ldots&0&0\\ \vdots&\vdots&\vdots&\ddots&\vdots&\vdots\\ 0&0&0&\ldots&\mathrm{A}_{N}&-\mathrm{I}^{(m)}\\ 0&0&0&\ldots&0&\mathrm{C}_{N}\end{pmatrix} , \tag{61}\]  
the set of Equation (59) can be rewritten as  
\[\mathcal{Y}=\mathcal{AX}+\mathcal{E} \tag{62}\]The vector \(\mathcal{Y}\) contains the known data, including the prediction of the state at \(t=1\). The vector \(\mathcal{E}\) contains the unknown noise terms, for which the covariance matrix is given by  
\[\mathcal{R}= \begin{pmatrix}\mathbb{Q}_{1}&\mathbb{S}_{1}&0&0&\ldots&0&0\\ \mathbb{S}_{1}^{\mathsf{T}}&\mathbb{R}_{1}&0&0&\ldots&0&0\\ 0&0&\mathbb{Q}_{2}&\mathbb{S}_{2}&\ldots&0&0\\ 0&0&\mathbb{S}_{2}^{\mathsf{T}}&\mathbb{R}_{2}&\ldots&0&0\\ \vdots&\vdots&\vdots&\vdots&\ddots&\vdots&\vdots\\ 0&0&0&0&\ldots&\mathbb{Q}_{N}&\mathbb{S}_{N}\\ 0&0&0&0&\ldots&\mathbb{S}_{N}^{\mathsf{T}}&\mathbb{R}_{N}\end{pmatrix}  \tag{63}\]  
The inverse of \(\mathcal{R}\) is given by  
\[\mathcal{R}^{-1}= \begin{pmatrix}\mathbf{\Omega}_{1}&\mathbf{\Sigma}_{1}&0&0& \ldots&0&0\\ \mathbf{\Sigma}_{1}^{\mathsf{T}}&\mathbf{\Psi}_{1}&0&0&\ldots&0&0\\ 0&0&\mathbf{\Omega}_{2}&\mathbf{\Sigma}_{2}&\ldots&0&0\\ 0&0&\mathbf{\Sigma}_{2}^{\mathsf{T}}&\mathbf{\Psi}_{2}&\ldots&0&0\\ \vdots&\vdots&\vdots&\vdots&\ddots&\vdots&\vdots\\ 0&0&0&0&\ldots&\mathbf{\Omega}_{N}&\mathbf{\Sigma}_{N}\\ 0&0&0&0&\ldots&\mathbf{\Sigma}_{N}^{\mathsf{T}}&\mathbf{\Psi}_{N}\end{pmatrix}  \tag{64}\]  
where the matrices \(\mathbf{\Omega}_{t},\mathbf{\Psi}_{t}\), and \(\mathbf{\Sigma}_{t}\) have been defined in Equations (8)-(10). Equations (60)-(63) represent a weighted least-squares problem to be solved for \(\mathcal{X}\), i.e., the sequence of the states.