# How to correct/filter inaccurate speeds calculated from a GPS track

I am working on a simple application that allows the user to do a lot of different things with a GPX file (GPS track). Some things computed are: average speed, max speed, etc. The max speed values I'm getting are very unrealistic, and when I look at a plot of the data, it's clear that there are spikes that represent inaccuracies. See the image below, which was a snowboarding run I did the other day... there are two spikes of ~57mph and 70mph, which I know are inaccurate.

I'm a bit rusty on my statistics, but I know there are probably multiple approaches to filtering/smoothing/correcting this data to remove the erroneous values, while retaining the quality I desire.

What is the best approach to accomplish that goal, and why?

A quick explanation of how the values in the plot are generated: each point logged by the GPS unit contains latitude/longitude values and a time value. Using the spherical law of cosines, the distance between any neighboring points in the track can be calculated, and that along with the time elapsed gives the average speed for the segment between those two points. This is repeated for each set of neighboring points in the track to generate the plot above. Obviously the inaccurate speed values are a result of positioning error from the GPS unit... if it logs me too far backward for one logged point, and then too far forward for the next point, the distance covered in that segment is calculated as much higher than it really was, and therefore so is my speed. In the segment leading up to the highest spike in the plot above, I supposedly increased my speed from ~12mph to 70mph over a segment of 100ft.

-
your question might be better answered on stackoverflow.com - here are some relevant links: stackoverflow.com/questions/1134579/smooth-gps-data, stackoverflow.com/questions/9311168/smooth-of-series-data. basically, the idea is to use either a Kalman filter or a moving average, depending on your needs. –  Vincent Tjeng Mar 1 '13 at 2:54
@VincentTjeng thanks for the link. I'd actually already come up with using a moving average on my own (5 points seems to work pretty well), but I figured I'd see what else was out there. Looks like if I'm serious I'll have to dig deep and learn about the Kalman filters. Thanks. –  The111 Mar 1 '13 at 3:04
> "two spikes of ~57mph and 70mph, which I know are accurate". I would guess that you mean "inaccurate", unless you're a much better snowboarder than I am. –  bubba Mar 1 '13 at 4:06
@bubba yes that was a typo, thanks. ;-) –  The111 Mar 1 '13 at 8:48

Using a moving average seems reasonable. It's quick, easy, and will probably do what you want. There are lots of variations , but a simple calculation that replaces each value $v_i$ by the average of $v_{i-2}$, $v_{i-1}$, $v_i$, $v_{i+1}$, $v_{i+2}$ will probably work fine. If the result still looks too rough, expand to 7 points.