Kalman Filter Derivation I am trying to follow the derivation of Kalman Filters from the book Introduction to Random Signals and Applied Kalman Filtering by Brown and Hwang. 
$$ P_k^{-} = E[(x_k-\hat{x}_k^{-})(x_k-\hat{x}_k^{-})^T] $$
$$ E[v_kv_k^T] = R_k $$
$$ E[w_kw_k^T] = Q_k $$
The rest can be found in the excerpt. The hairy part of the derivation is 
$$ E \bigg[ 
\bigg( (x_k-\hat{x}_k^-) - K_k (H_kx_k + v_k - H_k\hat{x}_k^{-}) \bigg)
\bigg( (x_k-\hat{x}_k^-) - K_k (H_kx_k + v_k - H_k\hat{x}_k^{-}) \bigg)^T
\bigg]
$$
The authors first expand the multiplication inside the expectation and then apply the operator. The provide a hint where they say $(x_k-\hat{x}^-)$ is uncorrelated to $v_k$, so I believe whenever these two are multiplied the expectation is zero. The result of this derivation is 
$$ P_k = (I - K_kH_k)P_k^- (I-K_kH_k)^T + K_kR_kK_k^T $$
I tried to replicate their results and failed. 
Note: See Gelb's Applied Optimal Estimation book. His notation is much better and derivation is clearer. 
 A: This follows by  manipulating the equation you wrote in your question in the following way. 
Start with 
$$ P_k = E \left[ 
\left( (x_k-\hat{x}_k^-) - K_k (H_kx_k + v_k - H_k\hat{x}_k^{-}) \right)
\left( (x_k-\hat{x}_k^-) - K_k (H_kx_k + v_k - H_k\hat{x}_k^{-}) \right)^T
\right],$$
and collect terms to obtain
$$ P_k = E \left[ 
\left( (I - K_k H_k)(x_k-\hat{x}_k^{-})  - K_k v_k \right)
\left( (I - K_k H_k)(x_k-\hat{x}_k^{-})  - K_k v_k \right)^T
\right].$$
Transpose the term in the second parentheses, 
$$E \big[ 
\left( (I - K_k H_k)(x_k-\hat{x}_k^{-})  - K_k v_k \right)
\left( (x_k-\hat{x}_k^{-})^T(I - H_k K_k )^T  - v_k^T K_k^T  \right)
\big],$$
and expand by multiplying the two parentheses, which leads to
\begin{align}
 P_k =& E \big[ 
(I - K_k H_k)(x_k-\hat{x}_k^{-}) (x_k-\hat{x}_k^{-})^T(I - H_k K_k )^T \\[1.5ex]
 &-(I - K_k H_k)(x_k-\hat{x}_k^{-}) v_k^T H_k^T K_k^T \\[1.5ex]
 &- K_k H_kv_k(x_k-\hat{x}_k^{-})^T(I - H_k K_k )^T \\[1.5ex]
 &+ K_k H_kv_k v_k^T H_k^T K_k^T     
\big].
\end{align}
Use the fact that $K_k$ and $H_k$ are predetermined (not stochastic) and you can rewrite this as
\begin{align}
P_k =&
(I - K_k H_k)E[(x_k-\hat{x}_k^{-}) (x_k-\hat{x}_k^{-})^T](I - H_k K_k )^T \\[1.5ex]
 &-(I - K_k H_k)E[(x_k-\hat{x}_k^{-}) v_k^T]  K_k^T \\[1.5ex]
 &- K_k E[v_k(x_k-\hat{x}_k^{-})^T](I - H_k K_k )^T \\[1.5ex]
 &+ K_k  E[v_k v_k^T] K_k^T.  
\end{align}
Finally, since   $(x_k−\hat{x}_k^{-})$ is uncorrelated with $v_k$, which implies that 
$$E[(x_k-\hat{x}_k^{-}) v_k^T]=E[v_k(x_k-\hat{x}_k^{-})^T]=0,$$
and using the definitions 
\begin{align}
P_k^- & \equiv E[(x_k-\hat{x}_k^{-}) (x_k-\hat{x}_k^{-})^T] \\[1.5ex]
R_k & \equiv E[v_k v_k^T] 
\end{align}
it follows that
$$  P_k = 
(I - K_k H_k)P_k^-(I - H_k K_k )^T + K_k R_k K_k^T.  
$$
A: The transition and observation formulas of the Kalman Filter are as follows:
$$ x_k = \Phi_{k-1}x_{k-1} + w_{k-1} $$mla
$$ z_k = H_k x_k + v_k $$
$x_k = (n \times 1)$ vector, state of the process at time $k$
$\Phi_k = (n \times n)$ matrix, describing the transition from
$x_{k-1}$ to $x_{k}$.
$w_k = (n \times 1)$ vector, white noise, Gaussian with zero mean,
covariance $Q_k$
$z_k = (n \times 1)$ vector, observation
$H_k = (m \times n)$ matrix, how does the hidden state appear to outside world, without noise
$v_k = (m \times 1)$ vector, measurement error
Noise with zero mean implies
$$ E[v_k] = E[w_k] = 0 $$
Also
$$ E[v_kv_k^T] = R_k $$
$$ E[w_kw_k^T] = Q_k $$
The relationship between the state and error could be stated as follows:
$$ \hat{x}_k^+ = x_k + \tilde{x_k}^+ $$
$$ \hat{x}_k^- = x_k + \tilde{x_k}^- $$
We want to update our best guess $\hat{x}_k^-$'i after
measurement. We'd like to do that by linearly somehow combining
measurement and latest guess linearly,
$$ \hat{x}_k^+ = \hat{x}_k^- + K_k (z_k - H_k \hat{x}_k^-)   $$
$\hat{x}_k^+$ is the estimation after the measurement update. $K_k$
is the so-called blending factor which we don't know what it is yet.
Rearranging,
$$= \hat{x}_k^- - K_kH_k\hat{x}_k^- + K_kz_k    $$
$$ \hat{x}_k^+ = \hat{x}_k^- (I - K_kH_k) + K_kz_k $$
To make it cleaner $K_k' = I - K_kH_k$ and rewrite the original equations as
$$ \hat{x}_k^+  = K_k' \hat{x}_k^- + K_kz_k  \qquad (1)  $$
$$ z_k = H_k x_k + v_k \qquad (2) $$
$$ \hat{x}_k^+ = x_k + \tilde{x_k}^+ \qquad (3) $$
$$ \hat{x}_k^- = x_k + \tilde{x_k}^- \qquad (4) $$
Put (1) in (2)
$$ \hat{x}_k^+ = K_k' \hat{x}_k^- + K_k(H_k x_k + v_k)   $$
Expand LHS of (3) 
$$ x_k + \tilde{x_k}^+ = K_k' \hat{x}_k^- + K_k(H_k x_k + v_k)   $$
Take $x_k$'yi to RHS
$$ \tilde{x_k}^+ = K_k' \hat{x}_k^- + K_k(H_k x_k + v_k) - x_k   $$
Instead of (4) $\hat{x}_k^-$ 
$$  = K_k' (x_k + \tilde{x_k}^-) + K_k(H_k x_k + v_k) - x_k   $$
Bring $x_k$ together and group
$$  = K_k' x_k + K_kH_k x_k  - x_k + K_k'\tilde{x_k}^- + K_kv_k   $$
$$ \tilde{x_k}^+ = x_k (K_k' + K_kH_k - I) + K_k'\tilde{x_k}^- + K_kv_k   $$
Take the expectation of the statement above
$$ E[\tilde{x_k}^+] = E[x_k (K_k' + K_kH_k - I)] + E[K_k'\tilde{x_k}^-] + E[K_kv_k]  $$
Right? Let's stop here and think about unbiasedness for a while
If estimator $\hat{x}^+$ had to be unbiased, that means 
$$ E[\hat{x_k}^+] = E[x_k] $$
must be true. Rearrange
$$ E[\hat{x_k}^+] - E[x_k] = 0$$
$$ E[\hat{x_k}^+ - x_k] = 0$$
$$ E[ \tilde{x_k}^+] = 0$$
Let's return to the main derivation; If $E[\tilde{x_k}^+] =0$ needs to
be true and also for $E[\tilde{x_k}^-] = 0$ the only thing remaining
is $K_k' + K_kH_k - I$ to be zero (because $E[v_k]=0$ would also be
true), then the expectation to be zero for any $x_k$ depends
$$ K_k' + K_kH_k - I = 0 $$
to be true. Which also implies
$$ K_k' = I - K_kH_k  $$
Put this into the estimator in (1)
$$ \hat{x}_k^+  = (I - K_kH_k ) \hat{x}_k^- + K_kz_k  $$
or
$$ \hat{x}_k^+  = \hat{x}_k^- + K_k(z_k - H_k\hat{x}_k^- )  $$
If we use (4) for $\hat{x}_k^-$ 
$$ \hat{x}_k^+  =  (x_k + \tilde{x_k}^-) + K_k(z_k - H_k( x_k + \tilde{x_k}^-) )  $$
Regroup
$$ \hat{x}_k^+  =  \tilde{x_k}^- (I - K_kH_k) + x_k + K_k(z_k - H_kx_k)   $$
Use (2) for $z_k - H_kx_k$ 
$$ \hat{x}_k^+ - x_k =  (I - K_kH_k)\tilde{x_k}^- + K_kv_k   $$
$$ \tilde{x}_k^+ = (I - K_kH_k)\tilde{x_k}^- + K_kv_k   $$
This gives us the estimation error.
Definition
$$ P_k^+ = E[ \tilde{x_k}^+\tilde{x_k}^{+T} ]$$
$$ P_k^- = E[ \tilde{x_k}^- \tilde{x_k}^{-T} ]$$
This is simply the application of the covariance calculation. Now we
take the formula three above and insert into the formula two above
$$ =  E \big[ (I - K_kH_k)\tilde{x_k}^- + K_kv_k \big] \big[\tilde{x_k}^{-T}(I - H_k^TK_k^T) + v_k^TK_k^T \big] $$
Meaning,
$$ = E \bigg[ (I - K_kH_k)\tilde{x_k}^- \big( \tilde{x_k}^{-T}(I - H_k^TK_k^T) + v_k^TK_k^T \big) + \qquad (5)$$
$$ K_kv_k \big( \tilde{x_k}^{-T}(I - H_k^TK_k^T) + v_k^TK_k^T  \big) \bigg] $$
We had defined before
$$ P_k^- = E[ \tilde{x_k}^- \tilde{x_k}^{-T} ]$$
$$ E[v_kv_k^T] = R_k $$
Also, since we assumed there is no correlation between measurement error
and noise,
$$ E[\tilde{x_k}^-v_k^T] = E[v_k\tilde{x_k}^{-T}] = 0 $$
We use all that to simplify  (5)
$$ P_k^{+} =  (I - K_kH_k)P_k^-(I - H_k^TK_k^T) + K_kR_kK_k^T \qquad (6)$$
How do we find the optimal $K_k$? The goal is to minimize the values
in the diagonal of $P_k^+$ which means our cost function is
$$ J_k = E[ \tilde{x_k}^{+T}\tilde{x_k} ] $$
whose result would only be a scalar. This is also the same thing as optimizing
$$ J_k = Tr(P_k^+) $$
We used trace because it gives us some abilities with
derivativces. For example we know that if $B$ is symmetric,
$$ \frac{\partial }{\partial A} Tr(ABA^T) = 2AB $$
$$ Tr(P_k^{+}) =  Tr((I - K_kH_k)P_k^-(I - H_k^TK_k^T)) + Tr(K_kR_kK_k^T) $$
There are two traces above, I guess we can see the form $ABA^T$ in
them, we can take their derivative w/ respect to  $K_k$
$$ \frac{\partial Tr(P_k^{+})}{\partial K_k}  =
-2(I - K_kH_k)P_k^- H_k^T + 2K_kR_k
$$
Make it equal to zero and solve,
$$ 0 = -2(I - K_kH_k)P_k^- H_k^T + 2K_kR_k
$$
$$   2P_k^- H_k^T = 2K_kH_kP_k^- H_k^T + 2K_kR_k $$
$$  P_k^- H_k^T = K_kH_kP_k^- H_k^T + K_kR_k  $$
$$  P_k^- H_k^T = K_k(H_kP_k^- H_k^T + R_k)  $$
$$  K_k = P_k^- H_k^T(H_kP_k^- H_k^T + R_k)^{-1} $$
$K_k$ is called the Kalman gain matrix. If we put this into (6) and
after a little manipulation,
$$ P_k^+ = P_k^- -P_k^- H_k^T (H_kP_k^- H_k^T + R_k)^{-1}H_kP_k^-  $$
$$ = [I - K_kH_k]P_k^-  $$
These masurements are for updating after measurement. How do we
estimate before measurement?
$$ \hat{x}_k^- = E[\Phi_{k-1}x_{k-1}^+ + w] = \Phi_{k-1}x_{k-1}^+ $$
$$ P_k^- = Cov(\Phi_{k-1}x_{k-1}^+) = E[(\Phi_{k-1}x_{k-1}^+ + w)(\Phi_{k-1}x_{k-1}^+ + w)^T) $$
$$ =  \Phi_{k-1}P_{k-1}^+\Phi_{k-1}^T + Q_{k-1}  $$
Sources
Gelb
Blog
