Monday, November 4, 2013

Collecting ECG with my EEG setup

When playing with a new EEG system (home-built or purchased), it is important to start with signals that are easy to obtain.  By starting with easy signals, you can more readily confirm that your system is working, or you an more readily trouble-shoot it until it is working.  It is for this reason that I always start my EEG hacking by measuring signals from my heart rather than from my brain.  The electrocardiogram (ECG, or EKG) is a far stronger signal with a much easier to see structure than the EEG.  Plus, to measure ECG, you do not need to put sticky, goopy electrodes in your hair.  Yay!

If you have never recorded your own ECG, here I'm going to give a photo tour of how I do it.  I happen to be using the OpenBCI system, but you can do the same thing with nearly any EEG system.  For example, when I first got my OpenEEG board from Olimex, I tested with ECG.  It worked just fine.

Using OpenBCI to Record my Heart Signals (ECG) from my Left Wrist and Right Wrist (my right wrist not shown because it is holding the camera!)

ECG Overview

EEG is the measurement of the electrical signals generated by your brain.  By contrast, ECG is the measurement of the electrical signals generated by your heart.  When the heart contracts, it generates a relatively strong electrical gradient in your body.  With electrodes on your skin, you can measure the difference in potential (ie, voltage) across your body caused by your heart.  That's what the ECG records.

ECG Can Be Measured Across Many Locations.  I'm going to use my two wrists.
Any measurement of electric voltage is a comparison of electrical potential between two different locations in space.  Therefore, to record one's ECG (or EEG), you need to attach at least two electrodes to your body.  Given that ECG signals are so strong, you have lots of choices of where to put your electrodes.  The only requirement is that your two measurement locations are on either side of the heart.  For me, my wrists are a very convenient, so that's where I'm going to attach my electrodes.

Hardware Needed

To measure one's ECG, you need electrodes to attach to your skin, you need wires to connect the electrodes to your electronics, you need some signal acquisition electronics that are appropriate for biosignals, and you need a computer and some software to record and visualize the ECG signals.  I'm going to talk about each of these elements in the sections that follow.

Electrodes:  Electrodes are simply pieces of metal that are electrically connected to your skin.  As long as you make good contact, nearly anything can be used as an electrode...they do not have to be specific to ECG.  If you don't want to get ECG electrodes, you could use EEG electrodes, you could use a piece of copper tape, or you can even use a piece of bare wire (if you can keep it attached to your skin).  But, I want to make this easy for myself, so I'm going to use cheap, disposable ECG electrodes.

I like the disposable ECG electrodes because they are self-adhesive, they come with conductive gel already attached, and they have a nice little button snap for attaching lead wires. They can be purchased from many, many places on-line.  One source is BioPac, where they are $0.38 each.  You can find them even cheaper, if you search around.


To put them on your skin, many websites talk about preparing your skin with an abrasive rub followed by alcohol.  While this is important if you want high-fidelity signals, we don't need this kind of quality.  We're just trying to see if our electronics work.  Therefore, no preparation is necessary.  Simply find a piece of skin without too much hair (for me, that's the inside of my wrists), peel off the paper backing, and stick them to your skin.  Easy!

Self-Adhesive Disposable ECG Electrodes Stuck to my Wrists.
ECG Lead Wires:  With the electrodes on the wrists, you need wires to bring the signals back to your electronics.  Again, there is no magic here.  You can use any wire.  Because I'm making life easy for myself, I bought some ECG lead wires that are made to connect to the button snaps on the ECG electrodes.  There are several different styles of these wires...some with snaps and some with clips.  I happened to get the ones with clips, but it doesn't really matter.  As when buying the electrodes, you can buy lead wires lots of different places.  I don't remember where I got mine.  Some are available from Biopac, or you can just check out Amazon.

The ECG lead wires that I use.  They have nice clips on the ends (picture on right) for attaching to ECG electrodes.  They also have the "touchproof" connectors on the other end for connecting to standard ECG electrodes.  Alternatively, you can use plain wire, if you prefer.
When selecting which lead wires to buy/make, the only trick is in the connector that attaches to the electronics.  Most ECG leads come with these nice little push-plugs that are referred to as "touchproof connectors".  They have this name because the electrical contacts are fully shrouded by plastic and can't be touched.  Note that EEG electrodes often come with the same type of connectors, too, which makes the ECG/EEG transition easy.  While you can always just cut off the connectors and use the raw wire, I like these connectors.  The challenge with the touchproof connectors is that they come in a few different diameters.  So, if you want to use the connectors, it's good to know what diameter connectors are on your wires so that you can buy the correct mating jacks.  My lead wires happened to have 1.5 mm connectors.

Since my EEG electrodes have the same 1.5 mm touchproof plugs as my ECG lead wires, it made sense to me to invest the time and money to buy the mating touchproof jacks.  I bought some 1.5 mm touchproof jacks from PlasticsOne.  I happened to buy the panel-mount version, but PCB mount would also be a good choice.  At over $3 each, these are not cheap.  They are convenient, though.  I mounted the jacks to a scrap piece of plastic and soldered on some wires to go to my electronics.  Easy.


Electronics:  The whole point of this exercise is to use my heart signals as a way of testing my EEG electronics.  So, for me, I'll be using EEG electronics (OpenBCI, OpenEEG, whatever).  But, if you were just doing ECG, ECG signals are generally stronger, which means that the electronics do not need to have such low self-noise.  As a result, ECG electronics tend to be cheaper than EEG electronics.  Regardless, I'm using EEG electronics.  In this case, I'm using OpenBCI.

For my setup, I connect one lead wire to "Input 1" (the "+" input) and one lead wire to the common reference input, "SRB" (the "-" input).  See the picture below.


Computer and Software:  Obviously, any computer will work...you just need one that will connect to your ECG/EEG electronics.  OpenBCI interfaces to the computer via an Arduino Uno.  That part is easy.  The harder part is what software to use on the PC.  You could use the custom displays that we have made for OpenBCI.  Or, following up from my last post, you could use BrainBay, which is an open source biosignal analysis program for Windows.  I recently wrote a software interface for OpenBCI to allow its data to be received and processed by BrainBay.  That's what I'm going to use here.

ECG Results

With the setup that I described above, I started BrainBay, relaxed my wrists (muscle contractions make electricity, too, which can mask the ECG signal), and watched my ECG data scroll by on the BrainBay display.  Some example data is shown below.  It should the ECG signal recorded for four heart beats.  It's always comforting to scientifically confirm that one's heart is beating.

ECG Signal Recorded using OpenBCI and Visualized using BrainBay.
I find the ECG signal itself to be fascinating.  Each component of the waveform corresponds to action in a different part of the heart.  Below, I've excerpted one heart beat from the waveform above and have shown it with annotations.  The little bump (downward in my data above) is the "P-wave", which is the atria contracting to push blood to the ventricles.  The sharp spike is the "R-wave", which is main contraction of the ventricles to push blood out to the body.  The big long bump is the "T-wave", which is the ventricles relaxing and re-polarizing to get ready for the next heart beat.  Note that usually the R-wave is much bigger and that the P- and T-waves are inverted compared to this trace, so I probably just had some wires plugged in backwards.  Still, all the components are there and they look pretty good.

Compared to the challenges in measuring EEG signals from the scalp, I find that ECG is way easier to measure reliably.  That's why I use it as my first test of an EEG system.  If I stick electrodes on my wrists  and don't see a signal like that shown above, I know that something is wrong with the electronics and not my body.  If you find yourself hacking EEG systems for fun, you might want to consider using this technique as well.  Plus, you might learn something about ECG and your heart, which is cool, too!


Follow-Up: In trying my homemade electrodes, I used ECG as my first test.
Follow-Up: I also was able to measure EOG using a similar setup.
Follow-Up: I've now tried to share the data from this post on my github.  Try it!

19 comments:

  1. Nice write up Chip!
    I'm following a similar path: testing ECG signal with my system (ADS1299 EVM) before touching EEG. I'm lucky to have ECG signal simulator in my lab :)

    Beside that, are you missing any posts? You jump from EEG hacking begin and then boom... OpenBCI.
    I'm interested to know about your journey with OpenBCI. My lab (me a a lab mate) is trying to build an EEG acquisition system with the ADS1299. I'm scratching my head everyday. My background is EE and I have never done anything in Biomedical Engineering.

    ReplyDelete
    Replies
    1. It all started with me founding an announcement that DARPA was offering a little money to develop a low-cost EEG system to enable "citizen science" by the common man. I said, "Hey, I like citizen science. I'm a common man. I like electronics (and I do some professionally). Let's make it work!".

      True, I didn't know much about EEG specifically, but I did know a little bit about electrophysiologic measurements in general. I also knew of this guy named Joel who did this PulseSensor thing...a super-low cost pulse sensor for hackers. So, I called him up, we made a plan, we won the DARPA funding (now long-past) and he/we made OpenBCI. Joel just achieved his KickStarter, so he'll be carrying it forward. It's an exciting story.

      Back to the narrow issue of this EEG Hacker blog...it's not specifically about OpenBCI...it's about me exploring EEG to see what it takes to make something cool happen. Of course, once we got OpenBCI to work, most posts involve OpenBCI. It is a pretty hacker-friendly little system for doing electrophysiologic measurements...though I might be a bit biased ;)

      Delete
    2. Typo Correction: in the first sentence, replace "...with me founding an announcement..." to "...with me *finding* an announcement...".

      Delete
  2. Wow, winning a DARPA fund, it's amazing! Your OpenBCI will definately open the door to electrophysiologic measurements for common man. It's great that the KickStarter campaign achieved the goal. It will make the OpenBCI more accessible and build a great community.

    Don't worry about the topic of your posts. I'm enjoy reading them all. Those EEG related post are great! It's just that I'm struggling with bringing the ADS1299 up so I'm interested in your journey at the beginning. It would be great if you can share it or pointing me somewhere where I can find it. I'm looking for some guidance.

    Thanks for sharing!


    ReplyDelete
    Replies
    1. If you bought the TI ADS1299 Dev Kit, and are trying to use the software that came with the Dev Kit, I feel for your pain. I found it very difficult to do anything beyond just getting a few-seconds of data. I found that the software was quite cumbersome.

      The Dev Kit is two pieces...a 1299 daughter card attached to a generic TI carrier board (the carrier board has the microcontroller). Perhaps, if had detached the daughter card and tried to attach it to an Arduino or something, it would have been more useful. I never tried.

      Joel did all the heavy lifting on getting 1299 working on our OpenBCI board, including the lowest-level software to set the registers correctly. So, you might check out the OpenBCI schematic and the base 1299 Arduino library. All that info is linked on the OpenBCI "Technology" page. Also, check out the forum...there's a discussion of other folks doing their own breakout boards...so you might learn something there, too.

      Delete
    2. Here's the Technology page: http://www.openbci.com/technology-update/

      Here's the forum topic that I was refering to: http://www.openbci.com/forums/topic/check-out-my-hardware/

      Delete
    3. My lab bought it. It's my only way to test the 1299 capabilities anyway. I'm not confident to build my board yet but soon.

      Yes, I plan to use the Launchpad or Arduino to collect the data from it.

      Oh the forum is a great resource. It links me to the Building and Crashing blog where the author posted some design consideration, justification...

      Thanks for you help Chip!

      Delete
    4. Can't wait to hear how it works out for you!

      Delete
  3. Great posting,
    I have a question. Did you try just getting signal from either wrist?
    I am wondering if you can still peak P or T wave

    ReplyDelete
    Replies
    1. Hi!

      I'm not sure that I understand your question. The recordings that I show above use an electrode on each wrist. The system then records the voltage difference between the two electrodes. So, the signal you see in my plots is the voltage difference between my two wrists.

      I could swap the electrodes (well, the electrode wires) going to my two wrists, but that would just invert the signal. Otherwise, it would be identical.

      Does that answer what you were asking? Sorry I'm confused...

      Thanks for reading!

      Chip

      Delete
  4. Hi, thanks for your response,

    What I meant was "does the single pairing give you the same look as the differential ECG shown here?" To measure the ECG, I know its better to have at least two electrodes doing differential schemes. I am just curious about what one electrode give you on the wrist.

    Thank you,

    Ben

    ReplyDelete
    Replies
    1. Hi Ben, I might still be misunderstanding your question...but you can't measure the ECG on just one wrist. ECG is a voltage measurement and voltage measurements are an evaluation of the electrical potential between two points.

      In a regular electrical circuit, it is common to measure the voltage relative to the circuit's ground. The ground becomes your reference for the voltage measurements.

      Your body has no "ground", so you pick a spot and declare it to be your reference. In the pictures above, the red wire (my right wrist) is plugged into "SRB", so it is my reference for all my voltage measurements. In this case, I'm only doing one measurement (ie, my left wrist), so it's a basic normal regular voltage measurement between my wrists. If I disconnect one of my wrists, I get no valid reading -- it just becomes all crazy and noisy with no ECG signal in there.

      Perhaps you're asking about what one wrist looks like when you connect it to somewhere else on the body that is NOT the wrist. That's a good question. The answer depends upon where you attach the reference electrode (the red wire). It is common to put it on the leg, but you could try putting it anywhere. And you'll get quite different signals...though they will always have some kind of sharp pulse once per heartbeat. The main difference will be the amplitude of the signal and whether the signal pulses upward or pulses downward.

      Hope I answered your question!

      Chip

      Delete
    2. Hi Ben and Chip,
      I think Ben is asking how can you measure ECG with only two electrodes compare to a "normal" ECG setup with 3 electrodes.
      I agree with Chip that we need only two electrodes to measure the voltage between two hands. But in fact ( at least from my recording and some of my friends with their ECG recording circuits), differential signals from 2 hands only are very noisy. An additional electrode which connects to the right leg significantly improve the signal quality. Why? I'm not quite sure...

      I present my measuring data here:
      http://eegexplore.blogspot.com/2014/05/collecting-ecg-signal-with-ti-ads1299.html

      Delete
  5. um curious about ur article
    http://eeghacker.blogspot.com/2013/11/measuring-eog-with-my-eeg-setup.html
    Can i have ur EOG sample signal and matlab program...
    I'm interested in creating a eog signal filter using FPGA (HDL) but i dont have a sample data... and i like to have matlab program too...
    Thank you carry on your good work

    email:viraj.uom@gmail.com

    ReplyDelete
    Replies
    1. I just tried posting my data to my github. Hopefully, it'll work for you:

      https://github.com/chipaudette/EEGHacker/tree/master/Data/2013-11-08%20EOG

      Delete
    2. BrainBay doesn't know how to read .mat files. Is this a Matlab project?
      I'm trying to get filters set up in Brainbay just like the above ECG . But I'm lacking the values used and am having serious software stability issues.
      I'm not interested in data. I am connected to the device and am seeing data. I just need to filter it.

      Delete
  6. Hello :)

    This article is very interesting.
    I have an Olimex EEG SMT with 4 active electrodes and a passive one, how can I use it as an ECG device as you did here?

    Thanks!

    ReplyDelete
  7. Eeg Hacker: Collecting Ecg With My Eeg Setup >>>>> Download Now

    >>>>> Download Full

    Eeg Hacker: Collecting Ecg With My Eeg Setup >>>>> Download LINK

    >>>>> Download Now

    Eeg Hacker: Collecting Ecg With My Eeg Setup >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete
  8. Getting an ECG test in Delhi is now easier than ever! Whether for routine checkups or specific concerns, ensure your heart's health with a reliable ECG test. Delhi offers numerous top-notch facilities with expert professionals. Don't wait until it's too late—schedule your ECG test today and take a proactive step towards a healthier heart.

    ReplyDelete