01Overview
GPS Sensor Fusion is the filtering layer between raw sensors and your gameplay or visualization. It fuses GPS (low rate, position + velocity) with an optional AHRS/IMU (high rate, heading + turn rate) to produce a smooth, high-rate estimate of position, velocity and heading — handling turns correctly and degrading gracefully when GPS drops out. No networking, no third-party packages, and an allocation-free hot path suitable for desktop and mobile.
02Key features
- Linear Kalman Filter6-state constant-velocity model with quality-adaptive measurement noise.
- Extended Kalman Filter8-state CTRV model fusing GPS position + velocity with AHRS heading + turn rate. Correct through turns via a proper Jacobian.
- Adaptive heading filterExponential smoothing with 360° wraparound, rate limiting and a stationary dead-zone that kills compass jitter.
- CTRV dead reckoningLightweight predictor to interpolate between GPS fixes without the full EKF.
- NMEA 0183 generator & parserStandard RMC/GGA/GLL/GSA/GSV/VTG from any talker ID. Locale-safe, never throws on malformed input.
- Geodesy helpersHaversine distance, initial bearing, knots→km/h, and lat/lon → local ENU (Unity meters).
- Drop-in MonoBehaviourSmooths a Transform from dual-rate input with KF/EKF fusion and GPS-loss handling — inspector-configurable.
- Pluggable sources + record/replayFeed from raw NMEA, Unity device GPS, or a recorded CSV track. Record & replay with faithful timing — no hardware needed.
- Zero-allocation math coreIn-place matrix ops, Gauss-Jordan inversion with regularization and condition-number monitoring.
- Unit testedAn EditMode suite covers matrix math, filter convergence, NMEA I/O, geodesy and record/replay.
03What’s inside
Everything lives under the KephStudio.SensorFusion namespace and compiles into its own assembly.
| KalmanFilter | 6-state linear KF — simple & fast, GPS position/velocity only. |
| ExtendedKalmanFilter | 8-state CTRV filter — best quality, ingests AHRS between GPS fixes. |
| HeadingFilter | Standalone adaptive heading smoother (EMA + rate limit + dead-zone). |
| GPSMovementState | CTRV dead-reckoning predictor for interpolation between fixes. |
| NMEAGenerator / NmeaParser | Standard NMEA 0183 generation and parsing into a GpsFix. |
| GeoUtils | Geodesy: haversine, bearing, unit conversions, lat/lon → local ENU. |
| IGpsSource (+ impls) | NmeaGpsSource, LocationServiceGpsSource, GpsTrackReplayer. |
| SfMatrix | Zero-allocation dense matrix backing the filters. |
04Included sample
Synthetic Track Demo
Generates a noisy GPS track, runs it through the EKF, and plots truth / noisy / filtered paths with LineRenderers — no GPS hardware required.
05Changelog
Initial extraction into a standalone, dependency-free package.
- Kalman, Extended Kalman (CTRV), heading and dead-reckoning filters.
- Standard NMEA 0183 generation & parsing with any talker ID.
- Pluggable GPS sources: NMEA, Unity LocationService, CSV record & replay.
- Zero-allocation SfMatrix and an EditMode unit-test suite.