This project began from an oversimplification. One day, I wondered: “How hard can it be to make an EKG? How hard is it to amplify the heart’s electrical signal? It can’t be too expensive to make one myself, right?” A quick search on the internet gave me the motivation to build one myself, and so I did. This page is meant to document the stages that I went through in building this EKG for a couple dollars.
Anyone can do this, and as such, I encourage anyone to take up a similar project as a fun way to practice their programming and circuit building skills.
Hold up, It’s safety time. While I do support any opportunity to learn circuits and experiment, there’s something about safety that has to be said about this particular project. This EKG circuit has no electrical isolation from whatever it is connected to.
Because of this, everyone needs to know that this EKG should never be used on a desktop computer, or a laptop charging off a wall wart of any kind. This is because if the computer’s power supply is poorly designed, or even if some random accident occurs, there’s the potential for mains electricity to travel from the power supply to the computer, through the audio port, through the EKG, to your body. This is what is known as electrocution, and it is potentially fatal. 120VAC is not something you want across your chest.
As such, I only really recommend building this circuit if A) You’re willing to come up with some form of isolation to protect yourself, or B) You understand all the risks involved, and you’ll do everything in your ability to avoid using alongside any mains power device. In my case, I only use this circuit along side a laptop computer that is working off of battery power only. I’d put my charging cable somewhere far away when messing around with this circuit.
1) Drafting a few goals:
In the couple of days that followed the conception of this project, I created the set of goals below:
- The EKG must work on a laptop computer. — Other then the fact that I wanted the satisfaction that I could potentially take this EKG anywhere, I defined this goal because I already had a good idea of how to make a decent program in Pure Data at the time.
- The EKG should involve some kind of analog filtering — This one is a bit of curious nature. Though I knew my EKG would not necessarily function without my laptop, and I could have easily utilized some digital filters with my laptop, I still wanted the EKG to stand alone as much as possible. So I figured that the device itself should have some sort filtering component onboard. I was also curious to see how it would turn out.
- The EKG must be built and functioning by the end of the current semester — This was just a semi-lax deadline of a couple months that helped me to keep moving things along.
- The EKG should be cheap within these guidelines — As I was more concerned about just buying the right components, I actually didn’t have a particular price in mind for this project. I opted for cheaper components whenever it was convenient.
2) Picking a schematic:
Before I could even start looking for hardware, I had to find a decent schematic. Some google searching about the subject of “DIY EKGs” yielded a good number of websites. The creator of this site, John Nguyen, was generous enough to document his entire process of constructing an EKG from his own original schematic (seen below). Additionally, his design incorporated some neat analog filtering. And thus, Having already attended to the goals of designing an EKG that 1) works with a computer and 2) involves some kind of analog filter, Nguyen’s site naturally became the “textbook” behind this project.
Several opamp configurations can be seen here:
- IC3A: Ad buffer that creates a virtual ground at 4.5V for the circuit.
- IC1A and IC1B: The combination of these two form an instrumentation amplifier with a gain around 20. Its purpose is to selectively amplify the voltage difference between the chest electrodes.
- IC2B and IC3B: Summing amplifiers.
- IC3A: An integrator. The exact effect of the incorporated feedback was a bit difficult to isolate. It turns out that this bit of the circuit is better understood at the final summing amplifier (IC3B) where one can see that the integrator works to have the two signal’s cancel each other out if the input ever happens to go stagnate. Imagine the voltage across an inductor when you give it a pulse train for an input signal. This circuit as a whole behaves in a nearly identical manner. This could serve to eliminate any sort of DC bias that may exist across the skin somewhere.
Most EKGs nowadays are designed with a 12-lead configuration. This is not one of them. Rather, this circuit represents just one of those leads.
The good thing about software is that I can start prototyping right away. I had at least 50% of the program coded by the day I ordered parts from Mouser. This encompassed a simulator of sorts that would allow me to simulate the electrical waveform of a typical heart beat. Below is a video of the simulator that I used before I was able to collect real heart data. In retrospect, I should have went over everything a bit more slowly, but the gist is that the program has some sliders and things to change what the (simulated) EKG signal looks like, and how it’s displayed to the user.
More of the program was written after the hardware had been constructed (See section #4) but it’s best to describe the details about how it works right here. The language that I used to create this program was Pure Data. While Pure Data is a visual language typically used for electronic music synthesis, I figured that it had all of the right tools to build the application that I had in mind. With the input being the computer’s audio port, the program takes the input signal and runs it through a notch filter to cut out the remaining 60Hz noise from the mains. From there, peak detection is performed by recording the time when the level of the signal surpasses a specified threshold value. This works only because the R portion of the wave usually forms the maximum amplitude of the EKG signal… for healthy hearts at least. Pure Data has a built in object for this sort of thing called [env~].
The program source code can be downloaded here. Note that the link is a download for a zip file. You also need to download and install Pure Data (official site here) in order to run the program. Once you unzip the file, open WORKSPACE.pd to start playing around.
All of the electrical components were soldered onto single-sided perf board.
Excluding the cost of shipping the electrical components, I spent $7.26 on this project. While it maybe could have been done for a bit cheaper, I suppose it’s not a bad price when DIY kits of similar complexity may cost at least $20. A small breakdown of my costs is shown below:
|Tin of Altoids||$2.00|
|RadioShack Perf Board||$2.50|
|Shipping costs, 1
Soldering Iron, and
From here, there’s not much to it except following the schematic, and there are many ways to do this. I took the freedom to add a 1Mohm potentiometer in series with R12 so that I could have some control over the output gain. Given the chance to do it again, I would give the layout another thought in order to reduce the number of jumper wires I had to use.
Having soldered on all of the hardware, it was time to see how it would connect to the program. The clip below offers a good idea of what the system looks like:
The schematic below shows how I connected the EKG circuit to the computer. Note how R1 and R2 form a voltage divider that brings a 9V signal down to 1V at the computer input.
One thing to be wary about regarding this schematic: saying that the EKG signal spans from 4.5V to -4.5V is not totally accurate, at least for me. During my use, I used the battery’s negative terminal for ground instead of a virtual ground of some kind. This caused the EKG signal to span from 0V to 9V with the baseline sitting at 4.5V. However, the audio input behaves as though it uses a coupling capacitor to eliminate DC offset, so it’s acceptable assume that the EKG signal centers itself at 0V for the sake of focusing upon the amplitude of the signal.
Now to show off some recorded EKG data:
The electrodes were attached in a Lead I configuration (Positive electrode on left pec, negative electrode on right pec). I was bit surprised by how clearly things managed to turn out. The high signal to noise ratio can be attributed to the use of an instrumentation amplifier and a digital stop band at 60 Hz. And, I’ll say this again, It’s important to keep the computer disconnected from mains at all times while recording with this EKG!
There’s no doubt that collecting clean biological signals poses a good deal of fun. This circuit should see another programming application in the near future.
Heres a case where the leads weren’t pressed tightly to the skin and the notch filter wasn’t turned on.