6 min read
On-Device Gait Analysis with iPhone LiDAR and HealthKit
Most gait analysis systems require dedicated hardware: pressure-sensitive mats, instrumented shoes, or clinical-grade motion capture rigs. The iPhone 12 Pro and later ship with a LiDAR scanner that can produce a dense depth map at 30 fps — more than enough to track the geometry of a walking stride. This post covers how I built a system that uses nothing but the phone itself to flag gait irregularities in real time.
The sensor pipeline
ARKit gives you per-frame depth maps through ARDepthData. The key insight is that you don't need the full reconstruction — just a cropped region of interest at foot height. I extract a ~200×100 pixel slice from the bottom third of each depth frame and track the lowest-point trajectory as a proxy for step timing.
Step events are derived by looking for local minima in the depth signal over a rolling 2-second window. From that you can compute cadence, stride symmetry (left vs. right timing), and coefficient of variation — a standard clinical measure of gait regularity.
Getting the data to a web dashboard
The companion HealthKitBridge iOS app runs a local HTTP server on the device (using Swift's Network framework). The TypeScript web dashboard at health.andernet.dev polls this endpoint over the local network — no internet required, no data leaves the room.
HealthKit is used for ground-truth step counts (the onboard pedometer is extremely accurate) and to pull longer-term trends: resting heart rate, VO₂ max estimates, and walking speed history Apple already captures in the background.
What it can (and can't) detect
The system reliably catches asymmetric stride timing — a common early indicator of hip or knee issues — and large cadence deviations. It's less reliable on carpeted surfaces (the LiDAR reading is noisier) and doesn't handle stairs or slopes well without an explicit classifier. Clinical-grade it is not, but as a personal tracking tool it's surprisingly useful.
Source code for both the iOS bridge and the TypeScript dashboard are on GitHub if you want to dig in.