# Correct Kalman Filter for Gaussian State Space Model

I am trying to follow a paper where they say they apply the Kalman filter, but don't give the forumulation for the Kalman filter! Moreover I have looked at two references Wikipeadia and Durbin and Koopman 2001, but they seem to give slightly different formulations, I would like to know which is either is correct!

The system I wish to apply the Kalman filter to is

$\textbf{z}_k=\textbf{H}\textbf{x}_k+\textbf{v}_k$ $\textbf{v}_k \sim N(\textbf{0},\textbf{R})$

$\textbf{H}$ does not change over time
$\textbf{R}$ is a diagonal of constants

$\textbf{x}_k=\textbf{F}\textbf{x}_{k-1}+(\textbf{I}-\textbf{F}){\mu} + \textbf{w}_k$ $\textbf{w}_k \sim N(\textbf{0},\textbf{Q})$

$\textbf{I}$ is the identity matrix
$\mu$ is the vector of mean values of $\textbf{x}$
$\textbf{F}$ is diagonal with the AR(1) params which do not change over time
$\textbf{Q}$ is diagonal with the innovation processes for $\textbf{x}$

First things first is this the correct way to set up an AR(1) state space model?

The first formulation of the Klaman filter is given here. See the section "details".

They subscript the $\textbf{H}$ and $\textbf{F}$ with k which seems to denote that there matrices are evolving over time but no updating equations are given for them so it seems in practice they are treated as constant?

In the details section the final variance estimate is given as:

$\textbf{P}_{k|k}=(\textbf{I}-\textbf{K}_k\textbf{H}_k)\textbf{P}_{k|k-1}$

where

$\textbf{P}_{k|k-1}=\textbf{F}_{k}\textbf{P}_{k-1|k-1}\textbf{F}_{k}'+\textbf{Q}_{k}$
$\textbf{K}_{k}=\textbf{P}_{k|k-1}\textbf{H}_{k}'\textbf{S}_{k}^{-1}$
$\textbf{S}_{k}=\textbf{H}_{k}\textbf{P}_{k|k-1}\textbf{H}_{k}'+\textbf{R}_{k}$

Expanding out

$\textbf{P}_{k|k}=(\textbf{I}-\textbf{K}_k\textbf{H}_k)\textbf{P}_{k|k-1}$
$\textbf{P}_{k|k}=(\textbf{P}_{k|k-1}-\textbf{K}_k\textbf{H}_k\textbf{P}_{k|k-1})$

sub in $\textbf{P}_{k|k-1}$ and $\textbf{K}_{k}$

$\textbf{P}_{k|k}=((\textbf{F}_{k}\textbf{P}_{k-1|k-1}\textbf{F}_{k}'+\textbf{Q}_{k})-(\textbf{P}_{k|k-1}\textbf{H}_{k}'\textbf{S}_{k}^{-1})\textbf{H}_k(\textbf{F}_{k}\textbf{P}_{k-1|k-1}\textbf{F}_{k}'+\textbf{Q}_{k}))$

there is a new $\textbf{P}_{k|k-1}$ term which we substitute as well

$\textbf{P}_{k|k}=((\textbf{F}_{k}\textbf{P}_{k-1|k-1}\textbf{F}_{k}'+\textbf{Q}_{k})-((\textbf{F}_{k}\textbf{P}_{k-1|k-1}\textbf{F}_{k}'+\textbf{Q}_{k})\textbf{H}_{k}'\textbf{S}_{k}^{-1})\textbf{H}_k(\textbf{F}_{k}\textbf{P}_{k-1|k-1}\textbf{F}_{k}'+\textbf{Q}_{k}))$

Meanwhile Durbin & Koopman 2001 give $\textbf{P}_{k|k}$ as see eqn 4.10 on p67 that I have substituted back into equation 4.3 on page 66:

$\textbf{P}_{k|k}=\textbf{F}_{k}\textbf{P}_{k-1|k-1}\textbf{F}_{k}'-(\textbf{F}_{k}\textbf{P}_{k-1|k-1}\textbf{H}_{k}'\textbf{S}_{k}^{-1}\textbf{H}_k\textbf{P}_{k-1|k-1}\textbf{F}_{k}')+\textbf{Q}_t$

note that I have changed the nomenclature to match that given in Wikipedia to facilitate comparison

Their state space model is slightly different

$\textbf{x}_k=\textbf{F}\textbf{x}_{k-1} + \textbf{A}\textbf{w}_k$ $\textbf{w}_k \sim N(\textbf{0},\textbf{Q})$

However the missing $(\textbf{I}-\textbf{F}){\mu}$ term is constant so should not affect the posterior variance estimate. Also the $\textbf{A}$ term is simply assumed to be the identity matrix to match my original model shown above

Questions:

1. Which is any of these formulations is correct?
2. If they are both correct how do i change the derivation to get them to match?

Any questions just ask, even happy to write out the D&K2001 derivation in full if it helps.

EDIT: One thing I have noticed is that the time scripting is also slightly different in D&K2001

$\textbf{z}_k=\textbf{H}\textbf{x}_k+\textbf{v}_k$ $\textbf{v}_k \sim N(\textbf{0},\textbf{R})$

$\textbf{x}_{k+1}=\textbf{F}\textbf{x}_{k} + \textbf{A}\textbf{w}_k$ $\textbf{w}_k \sim N(\textbf{0},\textbf{Q})$

$\textbf{A}$ still assumed to be the identity matrix
So when you start the series at $\textbf{x}=\mu$ the D&K2001 will base this value for $\textbf{x}$ in the first measurement equation.

Whereas the Wikipedia formulation will update $\textbf{x}$ first before using it in the measurement equation.

Maybe this helps to explain the difference although I'm still unclear as to how it would lead to the differences shown above?