Kalman Filter
The problem with GPS data
The idea behind the bike’s GPS system is to receive live GPS data while the bike is running, and use that data to determine the current position of the bike and where it needs to go. In theory, simply receiving GPS data and interpreting it without any filtering would work properly, however, with inaccuracies and noise affecting the GPS, a filter is needed to more accurately determine the location of the bike. The Kalman filter is the bike’s current filtering method for GPS data, and it helps reduce noise and increase the accuracy of the GPS plotting.
Kalman Filter equation
The general idea behind the Kalman filter is to combine a number of averaging techniques that give an accurate estimate of the actual location. One of these techniques used is Dead Reckoning, which determines position based on previous position and speed. Say the position of the bike at time k is represented by the variable xk. We can inductively define xk to be equal to axk-1, where a is some constant, and xk-1 is the position of the bike at time k-1. Using this, we define each position based on the previous position, only requiring GPS data for the start position. In the case of the bike, the position needs to be calculated as pairs of x y or lat long coordinates, and the function would be applied to each separately, making the position formula (xk,yk) = (a+xk-1, b+yk-1). Notice that a and b are being added to the old position rather than multiplied. This is because we can calculate the distance traveled during the timestep between kand k-1using the bike’s velocity data and the relative angle at time k-1. We use basic trig functions to calculate this distance, with a=speed cos(angle) timestep and b=speed sin(angle) timestep. Another simple formula used in the Kalman filter states that the observed position at time k is equal to the actual position plus some random noise value. Although intuitive, this formula is an integral part of the filter, as we can combine it with the first formula to get the equation xk = xk-1+gk(zk-xk-1). In this equation, xk represents our estimated state at time k, gk is our gain at time k and zk is our observed state at time k. This equation estimates the state taking into account both the observed state and the previous state, and the gain is some value between 0 and 1 that represents which one you put more emphasis on. We can calculate gain given the average noise of the GPS, for example, if the gain was 1, xk would be equal to zk, in other words, we have no noise.