Heart rate that fell apart when you walked
A health smartwatch lost the heart rate as soon as you started walking. I built a rig to compare it against a chest strap, then rebuilt the algorithm. Error while walking dropped from 8.2 to 5.5 bpm, and RAM from 6.9 to 2.7 kB.
A health smartwatch with ECG, heart rate and SpO2 lost the heart rate as soon as you started walking. Walking is the hard case for a wrist sensor: every step moves it and adds its own rhythm to the signal.
It’s easy to tweak a heart-rate algorithm until it looks good on one walk. To know if it’s really better, you need a reference. So I built two things: a way to measure it, and a better algorithm.
The first bug was a unit
The motion detector compared a threshold of 0.10 against acceleration in the wrong unit. Every pulse was flagged as motion and thrown away.
A way to measure it
I built the whole loop. A BLE service on the watch streams per-beat PPG and heart rate, plus raw PPG at 100 Hz and accelerometer data at 50 Hz. A Kotlin Android app records the watch and a reference chest strap side by side, with activity markers. Python scripts score each session and replay the filters, so I can try a change on recorded data before it goes on the watch.
An algorithm that expects motion
The new estimator runs a DFT on a 25 Hz grid. The accelerometer gives the step rate, and notches at 0.5×, 1× and 2× that rate remove the step and arm-swing peaks. A beat-interval prior and a bounded tracker stop the estimate from jumping around, and clip, jump and artifact-hold gates keep it steady.
Fitting it on the watch
The MCU was already at 98% RAM. I ported the estimator to C++ with an optimized FFT library and checked it against golden vectors from Python. Before switching it on, I ran it in shadow mode next to the old one. Along the way I also fixed a stack overflow that only happened while the watch was being worn.
Conclusion
Mean absolute error while walking, against the chest strap, went from 8.2 to 5.5 bpm.
The estimator’s RAM went from 6.9 kB to 2.7 kB.
The algorithm gets the attention, but the chest strap, the recorder app and the scoring scripts are what make 5.5 bpm a measurement and not a guess.