# understanding error covariance matrix in Kalman filter

I have recently started reading about Kalman filter for the very first time. I am using a pdf from MIT as a reference.(pdf link: https://web.mit.edu/kirtley/kirtley/binlustuff/literature/control/Kalman%20filter.pdf). In this they talk about minimizing the mean squared error which is nothing but trace of the error covariance matrix. However i am unable to understand what the elements of error covariance matrix actually are? As per the pdf, let $$x_k \in \mathbb{R}^n$$ be the actual state vector at time instant 'k'. Let $$\hat{x_k'}$$ be the prior estimate and $$\hat{x_k}$$ be the updated estimate after measurement. Then the error covariance matrix is at time k is defined as: $$P_k=E[(x_k-\hat{x_k})(x_k-\hat{x_k})^T]$$. Then they have talked about how trace of error covariance matrix gives mean squared error and we can minimize it. I am adding a screenshot from the pdf: screenshot from pdf I am unable to understand what the elements $$P_k$$ actually are and how is it's trace the mean squared errors. This $$P_k$$ is defined for time 'k' then how can it give mean squared error for other time instants as shown in the image?

• Do not use this resource, it is terrible. Pick any other one on the topic, it will be better than this one.
– KBS
Commented Aug 26, 2022 at 13:48
• it does seem very confusing to me. I will look for other resources. Actually i was using it just for understanding the derivation of kalman gain matrix, since in other resources that i was using did not explain it's derivation. Commented Aug 26, 2022 at 13:59

The important takeaway is that the derivation of the Kalman "gain" matrix $$K_k$$ is based on minimizing the trace of $$P_k$$. The diagonal elements of $$P_k$$ (that are summed together in the trace) are the variances of the estimation errors for the individual elements of the state vector. For example, if element $$i$$ of the state vector $$x_k$$ was a position in meters, then entry $$(P_k)_{ii}$$ is the variance of the estimation error for state element $$i$$ (in units m$$^2$$). And it turns out that minimizing the sum of the estimation error variances over all the elements of the state is a good criterion for obtaining good estimates.
• @VAdarsh You have a pretty good understanding of it for just getting started. One interesting thing that can give some insight is: The computation of the estimate covariances $P_1, ..., P_k, ..., P_N$ and the Kalman gains $K_1, ..., K_k, ..., K_N$ at each time instant can be computed off-line ahead of time. That is, they do not depend on the observed data whatsoever, and only depend on the initial covariance $P_0$, and the model parameters $F, H, Q, R$. So the Kalman gains are essentially deterministic parameters that tell us how much we should weight observations vs our state transition model Commented Aug 26, 2022 at 14:07
• is it because we can actually derive a recursive equation for $P_k$ and $P_k$ being in expression for optimal kalman gain, so kalman gain also gets a recursive equation, which can be determined by $P_0$ Commented Aug 26, 2022 at 17:08
• @VAdarsh Yes, that's pretty much it. The choice of $P_0$ is one of the most important aspects for "tuning" the filter correctly. Commented Aug 29, 2022 at 13:52