I am currently working on deriving the Kalman Gain from the covariance of the updated state and have encountered an equality issue that I am unable to resolve. Below are the derivation steps and the specific problem I am facing. Could you please help me identify where I might be going wrong?
Problem Details:
I am trying to derive the covariance of the updated state $\mathbf{P}_{n+1}$ given the following equations:
Predicted State: $$ \mathbf{x}_p = \mathbf{F} \mathbf{x}_n $$
Predicted State Covariance: $$ \mathbf{P}_p = \mathbf{F} \mathbf{P}_n \mathbf{F}^T + \mathbf{Q} $$
Measurement Residual: $$ \mathbf{y}_n = \mathbf{z}_n - \mathbf{H} \mathbf{x}_p $$
Measurement Residual Covariance: $$ \mathbf{S}_n = \mathbf{H} \mathbf{P}_p \mathbf{H}^T + \mathbf{R} $$
Updated State Estimate: $$ \mathbf{x}_{n+1} = \mathbf{x}_p + \mathbf{K}_n \mathbf{y}_n $$
Covariance Derivation Steps:
Starting from the updated state equation, I thought I could derive the updated state covariance $\mathbf{P}_{n+1}$ in two forms:
First Form: $$ \mathbf{P}_{n+1} = \mathbf{P}_p + \mathbf{K}_n \mathbf{S}_n \mathbf{K}_n^T $$ Substituting $\mathbf{S}_n$: $$ \mathbf{P}_{n+1} = \mathbf{P}_p + \mathbf{K}_n (\mathbf{H} \mathbf{P}_p \mathbf{H}^T + \mathbf{R}) \mathbf{K}_n^T $$
Second Form: Reorganizing the updated state: $$ \mathbf{x}_{n+1} = \mathbf{x}_p + \mathbf{K}_n (\mathbf{z}_n - \mathbf{H} \mathbf{x}_p) = (\mathbf{I} - \mathbf{K}_n \mathbf{H}) \mathbf{x}_p + \mathbf{K}_n \mathbf{z}_n $$ From here, I derived $\mathbf{P}_{n+1}$ as: $$ \mathbf{P}_{n+1} = (\mathbf{I} - \mathbf{K}_n \mathbf{H}) \mathbf{P}_p (\mathbf{I} - \mathbf{K}_n \mathbf{H})^T + \mathbf{K}_n \mathbf{R} \mathbf{K}_n^T $$
This form is the equation used to obtain the Kalman Gain, minimizing $\mathbf{P}_{n+1}$.
Issue Encountered:
The two different forms of the equations I derived to express $\mathbf{P}_{n+1}$ seem to be not equivalent.
Expression 1: $$ \mathbf{P}_{n+1} = \mathbf{P}_p + \mathbf{K}_n \mathbf{H} \mathbf{P}_p \mathbf{H}^T \mathbf{K}_n^T + \mathbf{K}_n \mathbf{R} \mathbf{K}_n^T $$
Expression 2: $$ \mathbf{P}_{n+1} = \mathbf{P}_p - \mathbf{P}_p \mathbf{H}^T \mathbf{K}_n^T - \mathbf{K}_n \mathbf{H} \mathbf{P}_p + \mathbf{K}_n \mathbf{H} \mathbf{P}_p \mathbf{H}^T \mathbf{K}_n^T + \mathbf{K}_n \mathbf{R} \mathbf{K}_n^T $$
From my understanding, these expressions should be equivalent based on the properties of covariance matrices and Bayesian updates. However, I am struggling to reconcile them. Could you please help me understand if there is a mistake in my derivation or if there is a specific property or step I am overlooking?