# Get rid of jumping GPS data with pykalman

I have gps data that I get from a smartphone application. Whenever the smartphone is stationary, the gps points are jumping. I understand that the signal is inaccurate due to the reception in a city between buildings and signal loss whenever inside.

From this post I wanted to give a shot to the Kalman filter. Using this article I was able to try out the Ramer-Douglas-Peucker algorithm on the latitude and longitude, and try the pykalman package for the elevation data. Also I have tried the pykalman example from the github project to play with the filter.

According to these readings, I assume to have the wrong input parameters :

``````measurements = numpy.column_stack([longitude_list, latitude_list])
# F_k : state transition matrix
F = numpy.array([ [1, 0],
[0, 1] ])

# H_k : the observation matrix
H = numpy.array([ [1, 0],
[0, 1] ])

# R : covariance R of delta_k observation noise N(0, R)
R = numpy.diag([1e-4, 1e-4])

kf = kf.em(measurements, n_iter=100)
(filtered_state_means, filtered_state_covariances) = kf.filter(measurements)
(smoothed_state_means, smoothed_state_covariances) = kf.smooth(measurements)
``````

The figures below are from matplotlib. The top left is with an iteration km.em(n_iter=2), top right with iteration 10, bottom left is iteration 50, bottom right is iteration 100. Whenever I try higher, I have a timeout. It does not seem that my filter work much on this case. Indeed the same shape is output (it might looks different at first because of the scale axis).

How can I improve my stationary gps jumping data?

• Did you ever find a good solution for this kind of problem? Commented Feb 13, 2018 at 18:42

If you want to solve the problem of jumping GPS points with pykalman, here is a detailed answer.

However, it seems that pykalman is not the ideal solution to your problem, since, if I understand you correctly, we are talking about jumping points at rest. Kalman filters work better when you are dealing with routes, meaning when users are actually moving around.

For your problem, it would probably make more sense to create some sort of rule-based model that detects when a user is at rest. Usually you can solve this with acceleration sensor data from the smartphone, or maybe you have measurement accuracy for the location data.

If you have neither measurement accuracy nor acceleration data, you can also use information such as aspect, distance traveled, or speed between two points and create a rule-based model as follows:

1. identify a sequence of points where the aspect varies strongly, speed is too fast, etc. Tweak the parameters as it makes sense for your data.

2. determine the centroid of the jumping points.

3. Delete all points except centroid.