How GPS Calculates Train Speed: The Science Explained
A plain-English explanation of how GPS satellites, Doppler shift, and the Haversine formula combine to give you a real-time speed reading on a moving train.
GPS does not measure speed directly — it measures position. Speed is derived either from the change in position over time (Haversine formula) or from Doppler frequency shift in the satellite signal, which is usually more accurate.
- Position-based speed = distance ÷ time, via the Haversine formula
- Doppler speed reads velocity directly from signal frequency shift
- TrainSpeedTest.net prefers Doppler speed when available
- EMA smoothing filters out noisy GPS samples
Speed derivation
Position-based & Doppler
Single-fix uncertainty
Depends on conditions
Accuracy reject threshold
Samples worse than this are discarded
Error at 100 km/h
From a ±10m position error
GPS Measures Position, Not Speed
This is the single most important thing to understand: your GPS receiver does not have a speedometer built in. It measures position, and from a series of positions recorded over time, it calculates how fast you are moving.
Position-Based Speed: distance ÷ time
The most straightforward approach is: speed = distance / time. Your GPS receiver records your position (latitude and longitude) at regular intervals. Between two successive positions, you can calculate the straight-line distance over the surface of the Earth.
The Haversine Formula
Calculating distance between two GPS coordinates requires accounting for the Earth's curvature — a flat-plane distance formula would introduce errors over any real distance. The Haversine formula solves this: given two points (lat1, lon1) and (lat2, lon2), it calculates the great-circle distance from the difference in latitudes and longitudes. Dividing this distance by the time elapsed between the two GPS samples gives speed in metres per second.
Doppler-Based Speed: A More Direct Method
Many modern devices also report a Doppler velocity — derived from the frequency shift of the GPS satellite signals. Because the satellites are moving relative to you, their signals arrive at a slightly shifted frequency. By measuring this shift across multiple satellites, the receiver can calculate your velocity with high accuracy.
Why TrainSpeedTest.net Prefers Doppler Speed
This Doppler speed is usually more reliable than position-based speed, especially over short time intervals. TrainSpeedTest.net uses native GPS speed data (Doppler speed) when available, and falls back to the Haversine calculation when not.
Raw GPS Data Is Noisy
A single GPS fix has horizontal uncertainty of ±5-50 metres depending on conditions. If you sample positions every second, this noise can cause speed to jump between readings — which is why raw GPS speed alone is not enough for a smooth display.
EMA Smoothing and Filtering
TrainSpeedTest.net applies an exponential moving average (EMA) filter to smooth speed readings. The filter reduces noise while preserving real acceleration events.
Acceleration limits
Unrealistically sudden speed jumps are dampened.
Negative-speed guard
Values below zero are clamped and discarded.
Stationary drift guard
GPS drift while parked or stopped is not shown as movement.
Accuracy rejection
Fixes with reported accuracy worse than 200m are discarded entirely.
What Affects Accuracy in Practice
Several environmental and hardware factors combine to determine how good your reading will be.
Satellite count
More visible satellites means better geometric accuracy.
Open sky
Trees, buildings, and tunnels block or reflect signals.
Multipath
Signals bouncing off surfaces can create phantom positions.
Receiver quality
High-end chipsets track more satellite systems simultaneously.
Speed Changes the Error Proportion
For a train travelling at 100 km/h, a position error of ±10 metres over a 1-second sample introduces a speed error of roughly ±2 km/h. At 200 km/h, the same absolute position error represents a proportionally smaller speed error — which is why GPS speed readings tend to look more stable at higher train speeds.
Putting It All Together
In practice, TrainSpeedTest.net combines Doppler speed (when the device provides it), Haversine-derived speed (as a fallback), and EMA smoothing (to stabilise the display) into a single reading that updates roughly once per second — accurate enough for a genuinely useful speedometer, without pretending to be a certified railway instrument.
Frequently Asked Questions
Try the Train Speed Test
Measure your train speed live in your browser — no app required.
Works on iPhone, Android & any modern browser · Always free