This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.

# How to Create Kalman Filter in Python – Part II Contributor:
QuantInsti
Visit: QuantInsti

See Part I of this series to get started with the Statistical terms and concepts used in Kalman Filter.

## Equations in Kalman Filter

Kalman Filter is a type of prediction algorithm. Thus, the Kalman filter’s success depends on our estimated values and its variance from the actual values. In Kalman Filter, we assume that depending on the previous state, we can predict the next state.

At the outset, we would like to clarify that this article on the Kalman filter tutorial is not about the derivation of the equations but trying to explain how the equations help us in estimating or predicting a value. Now, as we said earlier, we are trying to predict the value of something which cannot be directly measured. Thus, there will obviously be some error in the predicted value and the actual value.

If the system itself contains some errors, then it is called measurement noise. For example, if the weighing scales itself shows different readings for the same football player, it will be measurement noise.

If the process when the measurement takes place has certain factors which are not taken into account, then it is called as process noise. For example, if we are predicting the Apollo Rocket’s position, and we could not account for the wind during the initial blast off phase, then we will encounter some error between the actual location and the predicted location.

Kalman Filter is used to reduce these errors and successfully predict the next state.

Now, supposing we pick out one player and weigh that individual 10 times, we might get different values due to some measurement errors.

Mr. Rudolf Kalman developed the status update equation taking into account three values, ie

• True value
• The estimated or predicted value
• Measured value

### Status update equation

The status update equation is as follows:

Current state estimated value

= Predicted value of current state + Kalman Gain * ( measured value – predicted value of the state)

Let us understand this equation further.

In our example, we can say that given the measured values of all ten measurements, we will take the average of the values to estimate the true value.

To work this equation, we take one measurement which becomes the measured value. In the initial step, we guess the predicted value.

Now since the average is computed, in this example, the Kalman gain would be (1/N) as with each successive iteration, the second part of the equation would be decreasing, thus giving us a better-estimated value.

We should note that the current estimated value becomes the predicted value of the current state in the next iteration.

For now, we knew that the actual weight is constant, and hence it was easy to predict the estimated value. But what if we had to take into account that the state of the system (which was the weight in this case) changes. For that we will now move on to the next equation in the Kalman Filter tutorial i.e. State extrapolation.

Stay tuned for the next installment, in which the Rekhit will explain how to work with State extrapolation equation. 