Predict: \[ \hat{x}_k = a \hat{x}_{k-1} \] \[ p_k = a p_{k-1} a \] Update: \[ g_k = p_k / (p_k + r) \] \[ \hat{x}_k \leftarrow \hat{x}_k + g_k(z_k - \hat{x}_k)\] \[ p_k \leftarrow (1 - g_k)p_k \] Note that I've used the assignment (arrow) symbol, instead of the standard equal sign, in the last two lines of the update. Altough this usage is nontraditional, it gets across the idea that the update to $\hat{x}_k$ and $p_k$ is modifying their current values (from the prediction step), rather than defining those values in terms of a previous step (as prediction does). [9]
To try out our filter, we'll need:
$k$ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
$x_k$ | |||||||||||
$z_k$ | |||||||||||
$p_k$ | |||||||||||
$\hat{x}_k$ | |||||||||||
$g_k$ |
Previous: Prediction and Update Next: A More Realistic Model
[9] Indeed, if you look at the source code for this page, you will see that the JavaScript for the prediction and update is even simpler than the formulas:
// Predict xhat = a * xhat; p = a * p * a; // Update g = p / (p + r); xhat = xhat + g * (z - xhat); p = (1 - g) * p;I thank Marco Camurri and John Mahoney for pointing out inconsistencies in my use of these equations, in earlier versions of this tutorial.
[10] I have added noise from a uniform distribution rather than the Gaussian (normal) distribution assumed by the Kalman Filter, but it doesn't make much difference from the perspective of this demo.