Case StudyTechnical Guide

ECG beat detection that holds up in heavy motion: inside BeatTrac

How WearNex built BeatTrac, a lightweight ECG (EKG) beat detector that keeps heart rate and HRV reliable in heavy motion, even on chips without an FPU or DSP.

BeatTrac is WearNex’s ECG (EKG) beat detection engine: it finds every heartbeat in a chest-strap or smart-garment ECG while the wearer runs, lifts or cycles, and it does it on the wearable itself. On public recordings of 27 people walking, cycling, jogging and running it finds 99.7% of beats correctly, using under 1% of a small Bluetooth chip’s processor, even a chip with no floating-point unit.

Below is one of our own chest-strap ECG recordings, with the beats found by the classic Pan-Tompkins detector, BeatTrac 1.3.7 and BeatTrac 1.3.17 marked on it. Switch each detector on and off, zoom and scroll, and jump to the places where they disagree.

Loading the recording…

ECG beat detection on this recording

This one is a test, not a normal wear. The wearer added motion artefact and lift-off events to the signal on purpose, to see what each detector does when the strap stops giving a clean ECG. It is 184 seconds long. The signal is flat for a while when the strap lifts off, and for a long stretch it is swamped by movement.

Use Next and Previous to step through the places where the detectors disagree. Three are worth finding by hand.

Around 40s: the strap lifts off. From 37.5s to 44.1s there is no signal at all, and none of the three detectors marks a beat in it. Look at the heart-rate panel. Pan-Tompkins carries on reporting about 68 beats a minute until 42s, five seconds after its last beat, and then reads 37 to 38 from 45s to 50s once the signal is back. BeatTrac stops reporting a heart rate three seconds after its last beat, and starts again at 45s on 65.

75 to 120s: heavy movement. The signal swings several times wider than in the quiet parts. Over these 45 seconds Pan-Tompkins marks 60 beats and its heart rate ranges from 61 to 124 beats a minute. BeatTrac marks 53 beats and its heart rate stays between 59 and 70.

Around 160s: the noisiest stretch. Pan-Tompkins’ heart rate jumps from 65 to 76 at 156s, peaks at 108 at 160s, and is not back to 70 until 172s. Over the same stretch, 150s to 172s, BeatTrac’s heart rate stays between 62 and 70.

Why heart rate and HRV need more than a clean ECG

WearNex develops ECG wearables and smart garments for a range of clients, many of them for the gym and fitness market. Almost every one needs two things from the ECG: heart rate, and heart rate variability (HRV), the small beat-to-beat changes in timing that reflect recovery and stress.

At rest both are easy: each heartbeat is a sharp spike that stands out. In a gym the body can easily become the source of the noise. Footstrikes, a bouncing strap and electrodes shifting on the skin all put spikes into the signal, some bigger than the heartbeat itself. Near maximum effort the heart beats close to three times a second, and the beats crowd together. HRV is the harder of the two. One missed or invented beat turns one interval into nonsense, and that single interval can multiply an HRV reading many times. Classic detectors were designed for clinical recordings of people lying still, such as in a hospital bed, so we needed our own: one that stays reliable in heavy motion, and that tells us honestly when it cannot be.

Designed for low-power wearables

Our wearables live on small batteries, so the design started from power, not accuracy alone.

  • Detect on the device, not in the phone. Streaming the raw ECG over Bluetooth Low Energy (BLE) keeps the radio busy all the time, and the radio is usually the biggest power draw on a wearable. Detecting beats on the device means it only has to send heart rate, beat times and HRV: a few bytes per heartbeat instead of a continuous waveform.
  • Light enough to stay out of the way. The detector shares the chip with the Bluetooth stack, so it has to be cheap in terms of processor capability. It works through the signal in small batches and lets the processor sleep in between, rather than keeping it awake.
  • No floating-point unit required. The lowest-cost, lowest-power Bluetooth chips, such as Nordic’s nRF54LS05 family, leave out the floating-point unit (FPU) and the DSP instructions. Floating-point code still runs on them, but in software, roughly fifteen times slower. So BeatTrac has a fixed-point build that does its heavy lifting in whole-number arithmetic, with results matching the standard build within our test margins.
  • ECG only. BeatTrac needs no accelerometer or other sensor, everything comes from the ECG itself, although we are working on an ML-based BeatTrac that uses only a motion sensor. Stay tuned for that post!

How BeatTrac works

BeatTrac listens for heartbeat energy, learns the shape of the wearer’s own heartbeat, and then trusts shape over loudness.

  1. Listen in the heartbeat’s band. An energy filter tuned to the frequencies of the QRS complex (the sharp part of each beat) flags every moment that might be a heartbeat.
  2. Learn the wearer’s heartbeat. BeatTrac keeps a template of that person’s own QRS shape and refreshes it only from clean, confident beats, so it adapts to where the strap sits and how the heart’s signal looks without learning from noise.
  3. Choose by shape, rather than loudness. When a footstrike lands right next to a real beat, both can look like candidates, and the footstrike is often louder. BeatTrac compares every candidate with the template and keeps the best match.
  4. A second pair of eyes. At high heart rates real beats can sit just below the energy filter’s bar. A second detector, which matches the template directly, catches them. It has safeguards, it must see real heartbeat energy, and it is never allowed to teach the template, so it cannot drift onto other waves.
  5. Keep the proven heart rate. The heart rate on screen comes from a separate, deliberately conservative stream. The improved beat list feeds beat timing and HRV, so better beats never come at the cost of a ‘jumpier’ heart rate.
  6. Being honest about HRV. Every interval between beats carries validity flags. Intervals with the fingerprints of a detection error, such as one about twice the usual length (a missed beat) or two short ones that add up to a normal one (an extra beat), are marked as unusable. BeatTrac never invents, moves or corrects a beat, it only says which intervals can be trusted.

“BeatTrac recognises a heartbeat the way you recognise a friend’s voice in a noisy gym: by how it sounds, not by who is shouting loudest.”

How BeatTrac compares

We compared three detectors on the same public recordings and the same processor: the classic Pan-Tompkins detector (1985, the textbook reference), the first BeatTrac release (1.3.7) and the current release (1.3.17).

DetectorBeats found correctly in motion (F1)Errors per 1,000 beatsCortex-M33 with FPUCortex-M33 without FPU
Pan-Tompkins (textbook)97.2%5851–54kabout 500k
BeatTrac 1.3.799.7%5424–688k7,300–13,200k
BeatTrac 1.3.1799.7%5219–393k500–969k (fixed-point build)

Accuracy from 27 people walking, hand-cycling, jogging and running (public research recordings, GUDB and the PhysioNet Pulse Transit Time dataset). Processor figures are instructions per second of ECG at heart rates from 75 to 200bpm, measured in an Arm Cortex-M33 emulator. On a 128MHz chip, 1,000k instructions per second is under 1% of the processor.

What the numbers say:

  • BeatTrac makes about a tenth of the errors of Pan-Tompkins in motion. Pan-Tompkins is lighter, but its extra beats come mostly from motion spikes, exactly what breaks HRV.
  • The current BeatTrac matches the first release’s accuracy at about half its cost on a chip with an FPU.
  • On a chip without an FPU, the fixed-point build keeps BeatTrac under 1M instructions per second, against about 7M for the same detector running floating-point code in software.
  • The current release also reports beats from about half a second after the strap goes on, and flags the HRV intervals it cannot vouch for.

The figure at the top of this page shows these detectors side by side on a real recording.

Talk to us about ECG wearables

If you’re building an ECG wearable or smart garment and need heart rate and HRV you can rely on during exercise, without draining the battery, get in touch: we can help from signal processing through to the finished product.

BeatTrac is a work in progress. The results and the recording on this page reflect our testing at the time of writing, are shared for information only, and may change as the detector develops. BeatTrac is a heart-rate and beat-timing research tool, not a medical device, and nothing here is medical advice or a guarantee of performance.

Building something that combines electronics and textiles?

Tell us where you are in the process, from a sketch through to a product ready for manufacture. No obligation, and no question too early.