0

I'm interested to see if it's possible to compute the velocity given only GPS data and so, I calculated the distance between GPS points and computed the velocity by dividing it by the time interval between the points. However, when this computed velocity is plotted against time, I obtain a very noisy plot.

What is the best way to reduce the noise and obtain a smooth plot?

Plot of Velocity vs Time

I read about using Butterworth filters and specifically, Low Pass Filters to remove impossible changes in the velocity but unfortunately, I do not know which filter is most appropriate for this problem and how to configure them using the libraries in Python.

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[0].segments[0]
    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

surajr
  • 53
  • 6
  • Welcome to SE.SP! It's not clear that your code is using the Kalman filter. Usually, the Kalman filter takes as input your measurements (e.g. position), and then the state is updated using your signal model (which usually adds velocity). The Kalman filter state propagation of the velocity part of the state can then be used as an estimate of the velocity. See this answer to a similar (but simpler) question. – Peter K. Sep 06 '19 at 13:45
  • Note: if the "duplicate" doesn't answer your question, feel free to edit it and we can reopen and answer your real question once you've clarified what you're after. – Peter K. Sep 06 '19 at 13:46
  • Hello Peter! Yes, this does not include the Kalman portion of the code. The code given is only for calculating the velocity from the GPS points and to plot it. My question here is only to see how I can reduce the noise from this velocity plot in order to obtain a clearer output. – surajr Sep 06 '19 at 13:53
  • Have modified the title and changed the description. I hope that it's much better now :) – surajr Sep 06 '19 at 14:01
  • So, you're calculating the velocity directly from the position measurements? That's usually not going to yield a good velocity estimate (as your plot shows). You're better off using the Kalman filter to effectively do the smoothing / estimation for you to get the velocity. Because the velocity is the derivative of the position, high frequency noise (any noise) on the position measurements gets exploded significantly in the velocity. I'll re-open, but this seems (to me) to be the wrong approach. – Peter K. Sep 06 '19 at 14:08
  • 1
    Yes, I'm trying to calculate the velocity directly from position measurements. It was just an idea that I wanted to try out. The background being, if it was possible to calculate this velocity and give it later as an actual measurement along with the position to the Kalman but unfortunately, this might be a wrong approach and it doesn't seem to be working too well! In addition, I'm also working separately on using the Kalman filter to give the speed estimate using the answer that you referenced :) – surajr Sep 06 '19 at 14:18

0 Answers0