Altitude smoothing
Raw GPS altitude is noisy — easily ±5 m per fix even on open sky, much worse in cities. Cumulating positive deltas naively gives elevation gain numbers that are 20–50% too high. Altitude smoothing fixes this without losing real climbs.
Why it matters
Cumulative elevation gain (Σ positive Δh) over 5,000 noisy samples ≈ 5000 × √variance. A trip with a real 1,200 m climb can naively report 1,800 m gain — pure noise contribution. The correctness of the metric matters because it feeds Naismith's rule and the terrain difficulty index.
Algorithm
Two-pass low-pass filter:
Pass 1 — Outlier rejection. A point's altitude differing by
more than outlier_threshold (default 50 m) from its
neighbours' median is replaced by that median. Catches single
catastrophic readings (the GPS occasionally returns 0 m or
20,000 m).
Pass 2 — Moving-average smoother. A symmetric window of
window_size points (default 9) takes the mean. Edge effects
are handled with a shrinking window (a 5-point average at
position 2, etc.).
Cumulative gain is then:
gain = sum(max(0, h_smooth[i] - h_smooth[i-1]) for i in 1..N)
- threshold_filter
Where threshold_filter ignores any single delta smaller than
min_step (default 1.5 m) — accumulated micro-deltas are pure
noise.
Why three knobs and not just one
Each knob handles a different failure mode:
- Outlier threshold — catches absurd single readings. Without it, even a 9-point smoother still bleeds the bad value across 9 surrounding points.
- Window size — controls how aggressively we smooth real variation. 9 is a sweet spot: removes per-point jitter, preserves changes over 5+ seconds at typical GPS rates.
- Min-step threshold — catches the zero-mean noise that passes through smoothing. Even after a perfect smoother, Σ |Δh| over zero-mean noise = O(N × σ).
Calibration
The defaults are calibrated against:
- Tereza's Camino reference dataset (known elevation profiles for Saint-Jean → Santiago).
- Bike commute traces in Prague (smaller climbs, more samples).
- Drive across Switzerland (lots of sustained climbing).
Across all three, the smoothed gain matches the reference within ±5%.
Related
- Naismith's rule — uses smoothed elevation gain as input.
- GPS drift elimination — the X/Y cousin of this filter.
Need help? Contact support · Where Is Tereza?