# Calculate velocity and errors from distance between GPS points

I'm using a Kalman filter to track the position of a vehicle and for my measurement, I have a GPX file (WGS84 Format) containing information about the latitude, longitude, elevation and the timestamp of each point given by GPS. Using this data, I computed the distance between GPS points (Using Geodesic distance and Vincenty formula) and, since the timestamp information is known, the time difference between the points can be used to calculate the time delta. Since, we now have the distance and the time delta between the points, we can calculate the velocity (= distance between points/time delta) which could then be also used as a measurement input to the Kalman.

What would be the uncertainty and error of the computed velocity from GPS in comparison to velocity computed directly from vehicle sensors (eg: velocity computed from wheel speed)? (Considering the GPS data itself is noisy, Vincenty is accurate to about 1mm, the geodesic method is accurate to round-off and assuming wheel has no slip, wear and ideal road dynamics)

Code

``````import gpxpy
import pandas as pd
import numpy as np
from geopy.distance import vincenty, geodesic
import matplotlib.pyplot as plt

"Import GPS Data"
with open('my_run_001.gpx') as fh:
gpx_file = gpxpy.parse(fh)
segment = gpx_file.tracks.segments
coords = pd.DataFrame([
{'lat': p.latitude,
'lon': p.longitude,
'ele': p.elevation,
} for p in segment.points])

"Compute delta between timestamps"
times = pd.Series([p.time for p in segment.points], name='time')
dt = np.diff(times.values) / np.timedelta64(1, 's')

"Find distance between points using Vincenty and Geodesic methods"
vx = []
for i in range(len(coords.lat)-1):
if(i<=2425):
vincenty_distance = vincenty([coords.lat[i], coords.lon[i]],[coords.lat[i+1], coords.lon[i+1]]).meters
vx.append(vincenty_distance)
print(vx)

vy = []
for i in range(len(coords.lat)-1):
if(i<=2425):
geodesic_distance = geodesic([coords.lat[i], coords.lon[i]],[coords.lat[i+1], coords.lon[i+1]]).meters
vy.append(geodesic_distance)
print(vy)

"Compute and plot velocity"
velocity = vx/dt
time = [i for i in range(len(dt))]
plt.plot(velocity,time)
plt.xlabel('time')
plt.ylabel('velocity')
plt.title('Plot of Velocity vs Time')
plt.show()
``````

Reference for GPX Data: https://github.com/stevenvandorpe/testdata/blob/master/gps_coordinates/gpx/my_run_001.gpx

Plot of Velocity versus Time • A google search shows iPhone accuracy can be up to 10 meters. Time on location, number of sats, and other factor effect the quality. However if the points are far apart then this error maybe negated. Using WAAS the FAA says it's accurate to 2m but the Jets using it are moving 100+ mph. We used to do asset management, and the client wanted signs within 1/2 m. we argued it was quicker and cheaper to get them within 2m. And it they couldn't find the sign from 2m, it wasn't a GPS issue. So it depends on the project scope/use. – Bill Chappell Sep 4 '19 at 15:08
• That's a fair point Bill! It is pretty ambiguous to talk about GPS accuracy without specifying the scope of this requirement because it depends on a lot of factors. I will provide some more additional detail to the requirement in the question. – surajr Sep 4 '19 at 15:19
• I believe that your approach is correct but because the data are so noisy you should apply filters like lowpass filter that removes impossible changes in speed. I would say that you would find better experts from the site for digital signal processing dsp.stackexchange.com. – user30184 Sep 4 '19 at 18:58
• As per the Tour there should be only one question asked per question. – PolyGeo Sep 12 '19 at 2:08
• Have updated the question accordingly! – surajr Sep 12 '19 at 8:57