Overview

I designed a portable EKG and integrated it with a GoPro. I wanted to see the heart respond to environmental stimulii while doing really cool stuff. At the heart of the system (pun intended) is an Instrument Amplifier circuit, which amplifies the differential signal generated by your heart muscle. The amplified signal is fed into an Analog-to-Digital converter on the Arduino Uno, and then saved to an SD card. The EKG trace is generated after-the-fact with custom software that performs filtering, heartbeat detection, and a scrolling video overlay.

Mechanical

The EKG is powered by a single 9V alkaline battery, and built into a plastic project enclosure box. I cut holes for access to the LCD screen, on/off switch, start/stop button, and status LED. Nylon webbing is threaded through the flange holes to create a belt of sorts, and I can wear this around my belly, or waist. The electrodes are soldered to a 3.5mm audio jack, which is easily inserted and removed through the side of the enclosure.

Electrical

Two electrodes are worn on the upper chest (above the pectoral muscles) and one on the lower abdomen. The signal from the chest electrodes are fed into the amplifier circuit on the Olimex EKG/EMG shield and amplified nearly 1000 times. The signal is also band-pass filtered for noise. The third worn electrode is a driven signal, which is intended to help improve overall signal integrity (this is commonly referred to as the "Right Leg Drive", though it's not imperative to be on the right leg.)

A momentary pushbutton is used to start and stop the data collection.

The amplified heartbeat signal is fed into the Analog-to-Digital converter (ADC) on the Arduino Uno, and sampled at 256Hz. Data is stored on an SD Card via the serial bus with help from the SparkFun OpenLog datalogger.

To help synchronize the data with the video, I added an LED and piezo buzzer that blink/buzz at the beginning of each data capture. The data filename is broadcast via LED and buzzer in morse code. In theory I can use the audio of the piezo buzzer to automatically sync the data to the video track. In practice, the piezo buzzer was too quiet to be heard by the GoPro.. I will work on this for the next iteration..

Software

Firmware

The firmware was written in C as supported by the Arduino IDE. The firmware features are as follows:

Post Processing

The post processing code is written in C++ with Visual Studio Express 2012. ADC values are read from the data file, and rendered as a scrolling line graph. OpenCV routines are used to draw lines and manage color-space transformations. The scrolling graph is saved as an H.264 encoded video file with FFMpeg. Additionally, a full printout of the EKG trace data is created and saved in Scalable-Vector-Graphic format.

Post processing software features:

The GoPro file and heartbeat graph file are composited together using Sony Vegas.

Videos

Sample EKG Readout Sheets

EKG Readout EKG Readout

Miscellany

I built up two other instrument-amplifier circuits, but used the Olimex shield in this prototype. I did this due to time constraints, as my field testing dates were fixed. In the next iteration I will roll my own instrument amplifiers which will allow me to optimize the size of the integration. Smaller is better, here.

The contact electrodes that Olimex sells, in my opinion are junk. I got much better signal integrity by buying real EKG electrodes & wiring harness from China via Ebay. The downside with real electrodes, is that they are one-time use. However, they are very inexpensive.

The OpenLog, while very useful, interferes with Arduino programming. It is connected to the RX/TX lines of the Arduino, which are the same lines used by the Arduino bootloader. In order to successfully program the Arduino the OpenLog must be disconnected. In a future design I will keep all peripherals on an SPI bus if possible.

Contact Me

I can be reached on twitter (@derefnull) or via email: andrew at derefnull.org. Please contact me with questions or comments.

References & Related Reading

Improving Common-Mode Rejection Using the Right-Leg Drive Amplifier
Homemade Electrocardiograph, Jason Nguyen
ECG Measurement System, Chia-Hung Chen, Shi-Gun Pan, Peter Kinget