← All Base Form Math projects
BM-13NOT STARTEDBASE FORM · CALCULUSMATHPYTHON

Speedometer from GPS

Turn a GPS log into speed and acceleration curves, and smooth out the noise without wrecking the peaks.

EST.5 h
REWARD+100 XP
AFTERoriginal

ML-ARENA BENCHMARKS

YOUR NUMBER VS THE INDUSTRY'S
METRICINDUSTRYMINE
speed error on a synthetic track
GOAL · lower error than numpy.gradient on noisy data
numpy.gradient—
no results yet
YOUR RESULTS

Your recorded results appear here.

Brief

A GPS log is a list of positions with timestamps, about one per second. Speed is not in that list. You get it from the derivative of position: how fast position changes, in the limit of a tiny time step.

v(t)=lim⁡h→0s(t+h)−s(t)hv(t) = \lim_{h \to 0} \frac{s(t+h) - s(t)}{h}

With samples you can't take the limit, so you use a finite difference. The forward difference [s(t+h)−s(t)]/h[s(t+h) - s(t)]/h has an error that shrinks like hh. The central difference [s(t+h)−s(t−h)]/2h[s(t+h) - s(t-h)]/2h looks at one sample on each side, and its error shrinks like h2h^2. numpy.gradient uses central differences inside the array and one-sided ones at the ends.

The catch is noise. GPS positions jitter by a few metres. A difference divides that jitter by hh, so a 3 m wobble over one second looks like several metres per second of fake speed, and a smaller hh makes it worse. The fix is to fit a smooth curve to a window of samples with least squares, then differentiate the fit. A wide window kills the noise but also flattens real peaks, like the moment you brake hard. This project is about finding that balance and measuring it.

To turn latitude φ\varphi and longitude λ\lambda (in radians) into metres near a reference point, use x=R(λ−λ0)cos⁡φ0x = R(\lambda - \lambda_0)\cos\varphi_0 and y=R(φ−φ0)y = R(\varphi - \varphi_0) with R≈6371R \approx 6371 km.

VISUALFig. 1
time tposition s(t) t − h t t + h true slope (the speed) central: [s(t+h) − s(t−h)] / 2h forward: [s(t+h) − s(t)] / h The central line runs almostparallel to the tangent. Theforward line is visibly steeper.
The tangent at t is the true speed. The central difference is nearly parallel to it; the forward difference is visibly off. Why it's here: Objective 2 asks you to measure this gap. The picture shows why the central one wins.
HINT · OBJECTIVE 3
Stuck? Hints stay hidden until you ask.
HINT · OBJECTIVE 4
Stuck? Hints stay hidden until you ask.

DATA · your phone's GPS export or a public track

Objectives

0 / 6 CLEARED

Read-only. Log in to update progress.

VICTORY CONDITIONS

  1. On the noisy synthetic track, your speed RMSE is lower than `numpy.gradient` on the same data. Record both with `python tools/mlarena.py record BM-13 "<yours> vs <np.gradient> m/s"`.
  2. Your top speed is within 5% of the true top speed, so the smoothing did not flatten the peaks.
  3. The README shows speed and acceleration curves for a real GPS log.

Side quests

Compare your smoother with scipy.signal.savgol_filter(x, window_length, polyorder, deriv=1, delta=dt).
Many GPS apps also log a speed measured from the Doppler shift of the satellite signals. If yours does, compare it with your derivative.

Terms in plain words

Derivative
The rate of change at one instant. Speed is the derivative of position with respect to time.
Finite difference
An estimate of a derivative from samples: the change in value divided by the change in time.
Central difference
[s(t+h) − s(t−h)] / 2h. It uses one sample on each side, and its error shrinks like h², while the forward difference shrinks only like h.
Noise amplification
A difference divides measurement noise by a small h. Halve h and the noise in the speed roughly doubles.
Savitzky–Golay filter
Fits a small polynomial to a sliding window of samples by least squares and takes the derivative of the fit.