Music sync and the ECG: measuring a beat

A heart monitor and a music-synced light show solve the same problem: turning a noisy waveform into beats and a rate. Where the two match and where they differ.

My first software job was on ECG machines. A lot of the work came down to one thing: find each heartbeat in a messy signal and work out the rate. Music has the same problem. DJ software has been doing beat detection for years, so this isn’t a new idea. But after doing it at work every day, lights that follow the music stopped being a someday project. I love live music, and the part I always missed at home was the lights hitting with the song. So I started building it.

A heart monitor and a music-synced lighting system do the same basic job. Each takes a continuous, noisy signal, finds the repeating event in it, and reports when that event happens and how often. The heart monitor reports beats per minute. A light show reports the same thing, in color.

These notes compare the two. The comparison is useful because cardiology has spent decades on beat detection. Most of the failure modes we ran into while building FirePod already have a name on the medical side.

The signal

An ECG trace repeats a familiar shape for each heartbeat: a small P wave, a sharp spike called the QRS complex, then a rounded T wave. The tallest point of the spike, the R peak, is the easiest feature to find. Most heart rate measurement starts there.

Music has an equivalent in the kick drum and other sharp attacks. In a lot of dance and pop music, the beat is as easy to spot as an R peak. In other music it isn’t. A ballad, an ambient track or a live recording may have no clean spike at all. A good system has to handle both without changing how it behaves from one song to the next.

Rate comes from intervals

Heart rate isn’t read off a label. It’s measured. The time between two R peaks is the RR interval, and the rate is 60 divided by that interval in seconds. An interval of 0.8 seconds is 75 beats per minute.

Music tempo works the same way: a beat every 0.5 seconds is 120 BPM. In theory a lighting system could skip the measurement and read the tempo from the song’s details. In practice those details are usually missing. We checked nearly 600 tracks on SoundCloud for a tempo value. None had one. Like a monitor, a lighting system has to measure the rate from the signal itself.

Noise and artifacts

ECG readings pick up noise from patient movement, muscle activity and electrical hum from the building’s power. Each one can look like a heartbeat if the detector isn’t careful.

Microphone-based “music modes” have the same problem with different sources: people talking, a TV in the next room, the echo of the room itself. Quiet songs barely register over the background. The cleanest place to measure the beat is the audio itself, before it reaches a speaker and a room. That’s where FirePod sits: it is the speaker, so it has the music before anyone hears it.

Double counting

A known ECG failure is double counting. If the T wave is tall enough, the detector can mistake it for a second R peak, and the monitor reports twice the real heart rate.

Music has a version of this that is harder to call wrong. A song at 70 BPM can just as fairly be counted at 140, and many tracks written in half time sit right on that line. Both readings are defensible.

Gaps

A monitor that loses the signal should say so. It shouldn’t fill the gap with beats that aren’t there.

Music has deliberate gaps: breakdowns, quiet intros, the bar before a drop. When the beat goes away, the lights should rest instead of pulsing to a beat nobody can hear. When the beat comes back, the change in the room is bigger for it.

Output rate

Measuring the beat is half the job. The other half is the display. A monitor draws its trace at a fixed sweep speed, whatever the heart is doing.

Smart lights have a fixed ceiling too. In our testing, some bulbs start dropping changes if they receive more than two or three a second. So not every detected beat should become a light change. Fewer, well-timed changes look better in a room than constant flicker that the bulbs can’t keep up with.

Timing

Some cardiac equipment has to act on the beat, not after it. A defibrillator in synchronized mode times its shock to the R wave, because the wrong moment matters.

Lights face a milder version of the same requirement. A system that listens through a microphone only learns about a drum hit after the room has already heard it, so the lights trail the music. Because FirePod plays the music itself, the lights can land on the beat instead.

Summary

ECG monitorMusic-synced lights
EventR peak in the QRS complexKick drum and other sharp attacks
Rate60 ÷ RR interval60 ÷ beat interval
Labelled dataNone. Rate is measuredTempo is usually missing from songs
NoiseMovement, muscle, mains humTalking, TV, room echo
Double countingTall T wave read as a beatHalf time vs double time
GapsReport loss of signalRest during breakdowns
OutputFixed sweep speedBulbs drop changes above two or three a second

FirePod applies these principles to the lights you already own: Philips Hue, WiZ, LIFX, Govee and other brands, all following the same beat. It’s coming soon. See how it works or sign up for updates.

More from Firedance

Get updatesGet the early-bird price

Firedance isn't available yet. Leave your email and we'll let you know when it launches.

Leave your email and you'll hear first when Firedance launches, so you can get the early-bird price.