← All Base Form Math projects
BM-28NOT STARTEDBASE FORM · PROBABILITYMATHPYTHON

Phone tracker

Clean up a jumpy GPS trace with a Kalman filter that fuses position and speed readings.

EST.8 h
REWARD+100 XP
AFTERTim Babb

ML-ARENA BENCHMARKS

YOUR NUMBER VS THE INDUSTRY'S
METRICINDUSTRYMINE
position error
GOAL · ≥ 30% lower error than raw; matches filterpy
raw GPS · filterpy—
no results yet
YOUR RESULTS

Your recorded results appear here.

Brief

GPS on a phone jumps around by several metres. The phone also knows its speed and heading, and a person cannot teleport. A Kalman filter combines all of that. It keeps a best guess of where you are and how fast you are moving, along with how unsure it is, and updates both every time a reading comes in.

The model has a hidden state, here x=(x,y,vx,vy)\mathbf{x} = (x, y, v_x, v_y). Each step has two parts. Predict: move the state forward with x^−=Fx^\hat{\mathbf{x}}^- = F\hat{\mathbf{x}} and grow the uncertainty with P−=FPF⊤+QP^- = F P F^\top + Q. Update: compare the measurement z\mathbf{z} with what you expected, Hx^−H\hat{\mathbf{x}}^-, and move part of the way toward it. The share is the Kalman gain K=P−H⊤(HP−H⊤+R)−1K = P^- H^\top (H P^- H^\top + R)^{-1}, giving x^=x^−+K(z−Hx^−)\hat{\mathbf{x}} = \hat{\mathbf{x}}^- + K(\mathbf{z} - H\hat{\mathbf{x}}^-) and P=(I−KH)P−P = (I - KH)P^-.

Everything is Gaussian, so a mean vector and a covariance matrix carry the whole belief. You set two things by hand: QQ, how much the true motion can wander from constant velocity, and RR, how noisy the sensors are. Most of the craft is choosing them. To measure error you need the truth, so start with a simulated walk. For a real check, walk a route you know exactly, such as a running track, or use a public dataset with ground truth such as Google's Smartphone Decimeter Challenge.

VISUALFig. 1
-4 -2 0 2 4 6 position (m) predict: 0 ± 2.0 GPS: 3 ± 1.5 update: 1.92 ± 1.2
One update in one dimension. The prediction says 0 ± 2 m and GPS says 3 ± 1.5 m. The fused estimate is 1.92 ± 1.2 m, closer to the more certain source and narrower than both. Why it's here: The matrix formulas do exactly this, in four dimensions at once.
HINT · OBJECTIVE 2
Stuck? Hints stay hidden until you ask.
HINT · OBJECTIVE 6
Stuck? Hints stay hidden until you ask.

DATA · your phone's sensors or a public trace

Objectives

0 / 6 CLEARED

Read-only. Log in to update progress.

VICTORY CONDITIONS

  1. RMS position error at least 30% lower than raw GPS against ground truth. Record the reduction with `python tools/mlarena.py record BM-28 "<percent lower>"`.
  2. Your filtered states match filterpy.kalman.KalmanFilter within 1e-9 on the same inputs.
  3. The real trace is plotted raw and filtered on the same axes, with a short note on the Q and R you chose and why.

Side quests

Add an RTS smoother, which runs backward over the whole trace after the forward pass. filterpy has one to check against.
Feed the accelerometer in as a control input and see whether the filter reacts faster to turns.
Check that the filter is honest. The normalised innovation squared should average about the number of measured values.

Terms in plain words

State-space model
A model with a hidden state (here position and velocity) that evolves by a known rule, plus noisy measurements of part of that state.
Covariance matrix
Holds the variance of each state variable on its diagonal and how pairs of them vary together off the diagonal. It describes the filter's uncertainty.
Process noise (Q)
How much the true motion can drift from the model in one step, for example because the walker speeds up or turns.
Measurement noise (R)
How noisy each sensor reading is. A GPS fix might be off by 5 metres, so its variance is around 25 m².
Kalman gain
The weight that decides how far to move the prediction toward a new measurement. It is large when the prediction is uncertain and the sensor is good.