Saving Lives With Open-Source Electrocardiography

A few months ago, MobilECG wowed us with a formidable electrocardiograph (ECG, also EKG) machine in the format of a business card, complete with an OLED display. We’ve seen business card hacks before, but that was the coolest. But that’s peanuts compared with the serious project that it supports: making an open-source ECG machine that can actually save lives by being affordable enough to be where it’s needed, when it’s needed.

The project, MobilECG, is an open-source, wearable device that supports all of the major ECG modes. In their talk, [Péter Isza] and [Róbert Csordás] taught us a lot about what that exactly entails and how the heart works. We learned a lot, and we’ll share some of that with you after the break.

ECG

The heart has four chambers, and driving these different muscles in sequence produces tell-tale electrical signals. When measured in the right places, with the right resolution, these signals tell a doctor a lot about the heart’s functioning. [Péter] laid it out for us.

ecg_waveformFor instance, measuring the electrical potential between two thumbs yields a signal of approximately a millivolt which lasts for around 80 milliseconds. The technical challenge here is to discriminate the 1 mV signal from the roughly 300 mV baseline, without accidentally introducing noise that would drown out the tiny signal. MobilECG approaches this problem by throwing 24 bits of ADC resolution at the problem and doing the filtering in software where it’s noiseless. This is what their business card does.

But there are a couple more tricks available if you’re willing to hook up more electrodes, and a medical ECG has twelve signals measured from ten electrodes across the body. Four of these are on the hands and feet, while six more leads are located on the chest near the heart.

ecg_wilsons“Wilson’s central terminal” is a derived voltage that’s computed from the hand and foot electrodes. It’s the average of the three others relative to the right foot. This voltage is used as a baseline for the other measurements, and because it’s an average reading across the whole body, it’s relatively immune to all but common-mode noise. The voltages from the chest leads, measured in reference to Wilson’s central terminal, give particularly detailed information about heart function, including precursors to heart attacks.

The trick to get rid of the common-mode noise is to re-introduce the opposite of the noise back into the body. Called “right-leg drive”, this method essentially cancels out the results of the body being a big antenna.

The biggest source of interference, which you’ve noticed when you touch an oscilloscope probe, is the roughly one-volt 50/60 Hz power line signal pulling your body voltage up and down at all times. Right leg drive cancels this out, and gets rid of other common-mode signals.

Signal Processing

With these signals in mind, [Róbert] came on and walked us through the design of the credit-card demo, which is essentially just a precise ADC. All of the magic takes place in firmware, and most of that is in filtering. Basically, they need to use an IIR filter for computational complexity reasons, but they can’t afford the distortion that introduces. If you run an IIR filter on the data backwards, it cancels out this distortion, but that means keeping the data around in a buffer and running the IIR on overlapping sections. The rest of details are technical, so see the talk or their GitHub if you want to know more.

qrs_extractionThese filters are applied to all of the signals. Then to detect a heartbeat, they need to look for a peak in one of the signals; it’s called “QRS detection”. It’s a very clever peak-detection algorithm with a dead-time that’s proportional to the current heart rate, and a decaying threshold thereafter until the next peak is detected. Making the algorithm adaptive like this helps cancel out the effects of the patient or the electrodes moving.

The Hardware

To wrap up the talk, [Róbert] provided us with an overview of the main unit’s hardware design. Of course, it’s all open so you’re free to dig into the details yourself.

Where the business-card version uses a general-purpose ADC, the full-fledged device uses a special-purpose analog front-end, based on Analog Devices TI’s ADS1298, that is designed specifically for ECGs. It digitizes eight channels simultaneously, and calculates the Wilson’s central terminal and right-leg drive voltages in hardware. The rest of the hardware design is an STM32F4 microcontroller and a Bluetooth module to get the data out. Measuring all of the signals, the device should run on its built-in battery for a day. That’s pretty impressive for something that’s smaller than a cell phone.

The Future

We think that making low-cost, open-source medical devices is fantastic. It’s a way to get medical care to the most people for the least cost. Thanks, [Péter] and [Robert] for sharing your project with us!

17 thoughts on “Saving Lives With Open-Source Electrocardiography

  1. Interesting. I’ve learned something about digital filtering. (Running the IIR backwards a second time to correct the phase error.)

    For anyone not know with digital filters:
    FIR: Finite Input Response (no feedback)
    IIR: Infinite Input Response (with output feedback, making it infinite)
    Digital filters are awesome when you are in need of a high order filter. I’ve once made a 15th order highpass filter (FIR). The limiting factor is the processing power and input frequency. It works because a heartbeat is relative slow. (Higher input frequency => less computation time => worse filter.)

    I’m not sure why the IIR filter in this design needs to be in ‘blocks’. Both IIR and FIR are continuous filters. They talk briefly about settling time, with a continuous filter you only have settling time once. The only downside could be that the backwards IIR needs a dedicated block of memory. With the STM32F4 I don’t think this is going to be a problem. Same goes for computing power.

    Digital filters are really interesting when implemented in an FPGA, because each step can be calculated in parallel. Also digital filters are used for the Digital Defined Radio’s and (more interesting) Cognitive Radio.

  2. I have one of their ecg touch devices. It pairs with a mobile phone to give an ecg reading. You get one free ecg review by a licensed physician, then you can buy more reviews. Seems to work great, but im in good health so i dunno how accurate it is for the unhealthy with only two points of contact. But for the price, it’s peice of mind for the hypocondriac in me.

    1. That sounds like something unexpected that might actually lead to someone having a heart attack. Perhaps a faux analog gauge on the front that slowly moves between “Healthy” and “Seek Medical Attention” would be better.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.