<?xml version="1.0" encoding="windows-1252"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Blogging Protagonist &#187; DIY ECG</title>
	<atom:link href="http://www.SWHarden.com/blog/category/diy-ecg-home-made-electrocardiogram/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.SWHarden.com/blog</link>
	<description>A collection of thoughts in technological degradation</description>
	<lastBuildDate>Wed, 10 Mar 2010 17:10:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>DIY ECG Machine On The Cheap</title>
		<link>http://www.SWHarden.com/blog/2009-08-14-diy-ecg-machine-on-the-cheap/</link>
		<comments>http://www.SWHarden.com/blog/2009-08-14-diy-ecg-machine-on-the-cheap/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 02:15:00 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Circuitry]]></category>
		<category><![CDATA[DIY ECG]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.SWHarden.com/blog/?p=1512</guid>
		<description><![CDATA[Note from the Author: This page documents how I made an incredibly simple ECG machine with a minimum of parts to view the electrical activity of my own heart.  Feel free to repeat my experiment, but do so at your own risk.  There are similar projects floating around on the internet, but I [...]]]></description>
			<content:encoded><![CDATA[<p><table><tr><td style="text-indent: 25px; background-color: #E5E5E5; padding: 10px; border-top-width: 1px; border-bottom-width: 1px; border-left-width: 7px;border-top-style: solid; border-right-style: solid;border-bottom-style: solid;border-left-style: solid;border-top-color: #B5B5B5; border-right-color: #B5B5B5;border-bottom-color: #B5B5B5; border-left-color: #B5B5B5;border-right-width: 1px;background-image: url(http://www.swharden.com/graphics/layout_2006_08_12/quotes.jpg); background-position: left top; background-repeat: no-repeat;"><b>Note from the Author:</b> This page documents how I made an incredibly simple ECG machine with a minimum of parts to view the electrical activity of my own heart.  Feel free to repeat my experiment, but do so at your own risk.  There are similar projects floating around on the internet, but I aim to provide a more complete, well-documented, and cheaper solution, with emphasis on ECG processing and analysis, rather than just visualization.  If you have any questions or suggestions please <a href="http://www.swharden.com/blog/send-scott-a-message/" >contact me</a>. Also, if you attempt this project yourself I&#8217;d love to post your results! Good luck!<br />
&#8211;Scott</td></tr></table></p>
<h2>Background</h2>
<p><b>You&#8217;ve probably seen somebody in a hospital setting hooked up to a big mess of wires used to analyze their heartbeat.</b> <a href="http://www.SWHarden.com/blog/images/ecgman.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/ecgman.png" alt="ecgman" title="ecgman" width="400" height="320" class="alignright size-full wp-image-1518" /></a>The goal of such a machine (called an <a href="http://en.wikipedia.org/wiki/Electrocardiography" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">electrocardiograph, or ECG</a>) is to amplify, measure, and record the natural electrical potential created by the heart. Note that cardiac electrical signals are different than <a href="http://en.wikipedia.org/wiki/Heart_sounds" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">heart sounds</a>, which are listened to with a <a href="http://en.wikipedia.org/wiki/Stethoscope" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">stethoscope</a>. The intrinsic cardiac pacemaker system is responsible for generating these electrical signals which serve to command and coordinate contraction of the four chambers at the heart at the appropriate intervals [atria (upper chambers) first, then the ventricles (lower chambers) a fraction of a second later], and their analysis reveals a wealth of information about cardiac regulation, as well insights into pathological conditions. Each heartbeat produces a similar pattern in the ECG signal, called a PQRST wave. <a href="http://www.SWHarden.com/blog/images/ecg_principle_slow.gif" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/ecg_principle_slow.gif" alt="ecg_principle_slow" title="ecg_principle_slow" width="300" class="aligncenter size-full wp-image-1556" align="right"/></a> [<a href="http://www.swharden.com/blog/images/ecg2.jpg" >picture</a>]  The smooth curve in the ECG (P) is caused by the stimulation of the atria via the <a href="http://en.wikipedia.org/wiki/Sinoatrial_node" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">Sinoatrial (SA) node</a> in the right atrium.  There is a brief pause, as the electrical impulse is slowed by the <a href="http://en.wikipedia.org/wiki/Atrioventricular_node" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">Atrioventricular (AV) node</a> and <a href="http://en.wikipedia.org/wiki/Purkinje_fibers" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">Purkinje fibers</a> in the <a href="http://en.wikipedia.org/wiki/Bundle_of_His" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">bundle of His</a>. The prominent spike in the ECG (the <i>QRS complex</i>) is caused by this step, where the electrical impulse travels through the inter-ventricular septum and up through the outer walls of the ventricles. The sharp peak is the <i>R</i> component, and exact heart rate can be calculated as the inverse of the R-to-R interval (RRi).  Fancy, huh?</p>
<h2>Project Goal</h2>
<p>The goal of this project is to generate an extremely cheap, functional ECG machine made from common parts, most of which can be found around your house.  This do-it-yourself (DIY) ECG project is different than many others on the internet in that it greatly simplifies the circuitry by eliminating noise reduction components, accomplishing this via software-based data post-processing.  Additionally, this writeup is intended for those without any computer, electrical, or biomedical experience, and should be far less convoluted than the suspiciously-cryptic write-ups currently available online.  In short, I want to give everybody the power to visualize and analyze their own heartbeat!  </p>
<h2>The ECG of my own heart:</h2>
<p><a href="http://www.SWHarden.com/blog/images/ecg31.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/ecg31.png" alt="ecg31" title="ecg31" width="459" height="241" class="aligncenter size-full wp-image-1592" /></a></p>
<h2>Video Overview</h2>
<p><b>I know a lot of Internet readers aren&#8217;t big fans of reading.</b>  Therefore, I provided an outline of the process in video form.  Check out the videos, and if you like what you see read more!</p>
<h2>Video 1/3: Introducing my ECG machine</h2>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/6-zNMup_pgk&#038;hl=en&#038;fs=1&#038;color1=0x006699&#038;color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/6-zNMup_pgk&#038;hl=en&#038;fs=1&#038;color1=0x006699&#038;color2=0x54abd6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<h2>Video 2/3: Recording my ECG</h2>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/izet7cgtMjU&#038;hl=en&#038;fs=1&#038;color1=0x006699&#038;color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/izet7cgtMjU&#038;hl=en&#038;fs=1&#038;color1=0x006699&#038;color2=0x54abd6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<h2>Video 3/3: Analyzing my ECG</h2>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/Q4y20Lu3rn0&#038;hl=en&#038;fs=1&#038;color1=0x006699&#038;color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Q4y20Lu3rn0&#038;hl=en&#038;fs=1&#038;color1=0x006699&#038;color2=0x54abd6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<h2>Electrical Theory</h2>
<p><b>Measurement:</b> The electrical signals which command cardiac musculature can be detected on the surface of the skin.  In theory one could grab the two leads of a standard volt meter, one with each hand, and see the voltage change as their heart beats, but the fluctuations are rapid and by the time these signals reach the skin they are extremely weak (a few millionths of a volt) and difficult to detect with simple devices.  Therefore, amplification is needed.</p>
<p><b>Amplification:</b> A simple way to amplify the electrical difference between two points is to use a <a href="http://en.wikipedia.org/wiki/Operational_amplifier" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">operational amplifier</a>, otherwise known as an op-amp.  The gain (multiplication factor) of an op-amp is controlled by varying the resistors attached to it, and an op-amp with a gain of 1000 will take a 1 millivolt signal and amplify it to 1 volt. There are many different types of microchip op-amps, and they&#8217;re often packaged with multiple op-amps in one chip (such as the quad-op-amp <a href="http://www.mcu.hk/GIF/LM324.gif" onclick="javascript:urchinTracker ('/outbound/article/www.mcu.hk');">lm324</a>, or the dual-op-amp <a href="http://www4.zero.ad.jp/electronics/stdata/lm358/LM358N.gif" onclick="javascript:urchinTracker ('/outbound/article/www4.zero.ad.jp');">lm358n</a>). Any op-amp designed for low voltage will do for our purposes, and we only need one.  </p>
<p><b>Noise:</b> Unfortunately, the heart is not the only source of voltage on the skin.  Radiation from a variety of things (computers, cell phones, lights, and especially the wiring in your walls) is absorbed by your skin and is measured with your ECG, in many cases masking your ECG in a sea of electrical noise.  The traditional method of eliminating this noise is to use complicated analog circuitry, but since this noise has a characteristic, repeating, high-frequency wave pattern, it can be separated from the ECG (which is much slower in comparison) using digital signal processing computer software!</p>
<p><b>Digitization:</b> Once amplified, the ECG signal along with a bunch of noise is in analog form.  You could display the output with an <a href="http://en.wikipedia.org/wiki/Oscilloscope" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">oscilloscope</a>, but to load it into your PC you need an analog-to-digital converter.  Don&#8217;t worry!  If you&#8217;ve got a sound card with a microphone input, you&#8217;ve already got one!  It&#8217;s just that easy.  We&#8217;ll simply wire the output of our ECG circuit to the input of our sound card, record the output of the op-amp using standard sound recording software, remove the noise from the ECG digitally, and output gorgeous ECG traces ready for visualization and analysis!</p>
<h2>Parts/Cost</h2>
<p>I&#8217;ll be upfront and say that I spent $0.00 making my ECG machine, because I was able to salvage all the parts I needed from a pile of old circuit boards. If you need specific components, check your local RadioShack.  If that&#8217;s a no-go, hit-up <a href="www.DigiKey.com">Digikey</a> (it&#8217;s probably cheaper too). Also, resistor values are flexible.  Use mine as a good starter set, and vary them to suit your needs. If you buy everything from <a href="www.DigiKey.com">Digikey</a>, the total cost of this project would be about $1.  For now, here&#8217;s a list of all the parts you need:</p>
<blockquote><ul>
<li><b>1x low voltage op-amp</b> <a href="http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&#038;name=LM358NFS-ND" onclick="javascript:urchinTracker ('/outbound/article/search.digikey.com');">LM358N</a> $0.40</li>
<li><b>1x 100kOhm resistor</b> (brn,blk,yel) virtually free</li>
<li><b>1x 1kOhm resistor</b> (brn,blk,red) virtually free</li>
<li><b>1x 0.1uF capacitor</b> (104Z) virtually free</li>
<li><b>Microphone cable</b> to get from the op-amp to your PC</li>
<li><b>Electrodes</b> <a href="http://www.ustreas.gov/" onclick="javascript:urchinTracker ('/outbound/article/www.ustreas.gov');">3 pennies</a> should do. ($0.03)</li>
</ul>
</blockquote>
<h2>Making the Device</h2>
<p><b>Keep in mind that I&#8217;m not an electrical engineer</b> (I have a masters in molecular biology but I&#8217;m currently a dental student if you must know) and I&#8217;m only reporting what worked well for <i>me</i>.  I don&#8217;t claim this is perfect, and I&#8217;m certainly open for (and welcome) suggestions for improvement.  With that in mind, here&#8217;s what I did!</p>
<div align="center"><a href="http://www.SWHarden.com/blog/images/img_2694.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/img_2694-525x237.png" alt="img_2694" title="img_2694" width="525" height="237" class="aligncenter size-medium wp-image-1541" /></a></div>
<p><b>This is pretty much it.</b>  First off is a power source.  If you want to be safe, use three AAA batteries in series.  If you&#8217;re a daredevil and enjoy showing off your ghettorigging skills, do what I did and grab 5v from a free USB plug! Mua ha ha ha.  The power goes into the circuit and so do the leads/electrodes connected to the body.  You can get pretty good results with only two leads, but if you want to experiment try hooking up an extra ground lead and slap it on your foot.  More on the electrodes later.  The signal from the leads is amplified by the circuit and put out the headphone cable, ready to enter your PC&#8217;s sound card through the microphone jack!</p>
<div align="center"><a href="http://www.SWHarden.com/blog/images/img_2686.jpg" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/img_2686-525x393.jpg" alt="img_2686" title="img_2686" width="525" height="393" class="aligncenter size-medium wp-image-1535" /></a></div>
<p><b>Note how I left room in the center of the circuit board.</b>  That was intentional!  I wanted to expand this project by adding a microcontroller to do some on-board, real-time analysis.  Specifically, an <a href="http://thinklabs.in/shop/images/mega8.jpg" onclick="javascript:urchinTracker ('/outbound/article/thinklabs.in');">ATMega8</a>!  I never got around to it though.  Its purpose would be to analyze the output of the op-amp and graph the ECG on a LCD screen, or at least measure the time between beats and display HR on a screen. (More ideas are at the bottom of this document.) Anyway, too much work for now, maybe I&#8217;ll do it one day in the future.</p>
<h2>ECG circuit diagram:</h2>
<div align="center"><a href="http://www.SWHarden.com/blog/images/simple_ecg_circuit.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/simple_ecg_circuit.png" alt="simple_ecg_circuit" title="simple_ecg_circuit" width="243" height="276" class="aligncenter size-full wp-image-1548" /></a></div>
<p><b>This is the circuit diagram.</b> This is a classical high-gain analog differential amplifier.  It just outputs the multiplied difference of the inputs.  The 0.1uF capacitor helps stabilize the signal and reduce high frequency noise (such as the audio produced by a nearby AM radio station). Use Google if you&#8217;re interested in learning exactly how it works.  </p>
<h2>ECG schematic:</h2>
<div align="center"><a href="http://www.SWHarden.com/blog/images/simple_ecg_circuit2.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/simple_ecg_circuit2-525x374.png" alt="simple_ecg_circuit2" title="simple_ecg_circuit2" width="525" height="374" class="aligncenter size-medium wp-image-1549" /></a></div>
<p><b>This is how I used my LM358N</b> to create the circuit above.  Note that there is a small difference in my board from the photos and this diagram.  This diagram is correct, but the circuit in some of the pictures is not.  Briefly, when I built it I accidentally connected the (-) lead directly to ground, rather than to the appropriate pin on the microchip.  This required me to place a 220kOhm between the leads to stabilize the signal.  I imagine if you wire it CORRECTLY (as shown in these circuit diagrams) it will work fine, but if you find it too finicky (jumping quickly from too loud to too quiet), try tossing in a high-impedance resistor between the leads like I did.  Overall, this circuit is extremely flexible and I encourage you to build it on a breadboard and try different things.  Use this diagram as a starting point and experiment yourself!</p>
<h2>The Electrodes:</h2>
<div align="center"><a href="http://www.SWHarden.com/blog/images/img_2704.jpg" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/img_2704-525x393.jpg" alt="img_2704" title="img_2704" width="525" height="393" class="aligncenter size-medium wp-image-1539" /></a></div>
<p><b>You can make electrodes out of anything conductive.</b>  The most recent graphs were created from wires with gator clips on them clamping onto pennies (pictured).  Yeah, I know I could solder directly to the pennies (they&#8217;re copper) but gator clips are fast, easy, and can be clipped to different materials (such as aluminum foil) for testing.  A dot of moisturizing lotion applied to the pennies can be used to improve conduction between the pennies and the skin, but I didn&#8217;t find this to be very helpful.  If pressed firmly on the body, conduction seems to be fine. Oh! I just remembered. <b>USE ELECTRICAL TAPE TO ATTACH LEADS TO YOUR BODY!</b>  I tried a million different things, from rubber bands to packaging tape.  The bottom line is that electrical tape is stretchy enough to be flexible, sticky enough not to fall off (even when moistened by the natural oils/sweat on your skin), and doesn&#8217;t hurt that bad to peel off.</p>
<div align="center"><img src="http://www.swharden.com/blog/images/diy_ecg7.jpg"/></div>
<p><b>Some of the best electrodes</b> I used were made from aluminum cans!  Rinse-out a soda can, cut it into &#8220;pads&#8221;, and use the sharp edge of a razor blade or pair of scissors to <i>scrape off the wax coating on all contact surfaces</i>.  Although a little unconformable and prone to cut skin due to their sharp edges, these little guys work great!</p>
<h2>Hooking it Up</h2>
<p><b>This part is the most difficult part of the project!</b>  This circuit is extremely finicky.  The best way to get it right is to open your sound editor (In Windows I use <a href="http://www.goldwave.com/" onclick="javascript:urchinTracker ('/outbound/article/www.goldwave.com');">GoldWave</a> because it&#8217;s simple, powerful, and free, but similar tools exist for Linux and other Unix-based OSes) and view the low-frequency bars in live mode while you set up.  When neither electrode is touched, it should be relatively quiet.  When only the + electrode is touched, it should go crazy with noise.  When you touch both (one with each hand) the noise should start to go away, possibly varying by how much you squeeze (how good of a connection you have).  The whole setup process is a game between too much and too little conduction.  You&#8217;ll find that somewhere in the middle, you&#8217;ll see (and maybe hear) a low-frequency burst of noise once a second corresponding to your heartbeat. [note: Did you know that's how the second was invented?  I believe it was ] Once you get that good heartbeat, tape up your electrodes and start recording.  <b>If you can&#8217;t get it no matter what you do, start by putting the ground electrode in your mouth (yeah, I said it) and pressing the + electrode firmly and steadily on your chest.  If that works (it almost always does), you know what to look for, so keep trying on your skin.</b> For short recordings (maybe just a few beats) the mouth/chest method works <i>beautifully</i>, and requires far less noise reduction (if any), but is simply impractical for long-term recordings.  I inside vs. outside potential is less susceptible to noise-causing electrical radiation.  Perhaps other orifices would function similarly? I&#8217;ll leave it at that. I&#8217;ve also found that adding a third electrode (another ground) somewhere else on my body helps a little, but not significantly.  Don&#8217;t give up at this step if you don&#8217;t get it right away!  If you hear noise when + is touched, your circuit is working.  Keep trying and you&#8217;ll get it eventually.</p>
<h2>Recording the ECG</h2>
<p><b>This is the easy part.</b>  Keep an eye on your &#8220;bars&#8221; display in the audio program to make sure something you&#8217;re doing (typing, clicking, etc) isn&#8217;t messing up the recording.  If you want, try surfing the net or playing computer games to see how your heart varies.  Make sure that as you tap the keyboard and click the mouse, you&#8217;re not getting noise back into your system.  If this is a problem, try powering your device by batteries (a good idea for safety&#8217;s sake anyway) rather than another power source (such as USB power).  Record as long as you want!  Save the file as a standard, mono, wave file.</p>
<h2>Digitally Eliminating Noise</h2>
<p><b>Now it&#8217;s time to clean-up the trace.</b> Using GoldWave, first apply a lowpass filter at 30 Hz.  This kills most of your electrical noise (&gt; 30hz), while leaving the ECG intact (&lt; 15Hz).  However, it dramatically decreases the volume (potential) of the audio file.  Increase the volume as necessary to maximize the window with the ECG signal.  You should see clear heartbeats at this point.  You may want to apply an auto-gain filter to normalize the heartbeats potentials. Save the file as a raw sound file (.snd) at 1000 Hz (1 kHz) resolution.</p>
<h2>Presentation and Analysis</h2>
<p><b>Now you&#8217;re ready to analyze!</b> Plop your .snd file in the same folder as my [<a href="http://www.SWHarden.com/blog/images/ecg.py" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');">ecg.py script</a>], edit the end of the script to reflect your .snd filename, and run the script by double-clicking it.  (Keep in mind that my script was written for <a href="http://www.python.org/download/releases/2.5.4/" onclick="javascript:urchinTracker ('/outbound/article/www.python.org');">python 2.5.4</a> and requires <a href="http://sourceforge.net/projects/matplotlib/files/"href ="http://sourceforge.net/projects/numpy/files/NumPy/">numpy 1.3.0rc2 for python 2.5</a>, and <a  onclick="javascript:urchinTracker ('/outbound/article/sourceforge.net');">matplotlib 0.99 for python 2.5</a> &#8211; make sure you get the versions right!)  Here&#8217;s what you&#8217;ll see!</p>
<div align="center"><a href="http://www.SWHarden.com/blog/images/diy_ecg_sample_trace.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/diy_ecg_sample_trace-525x303.png" alt="diy_ecg_sample_trace" title="diy_ecg_sample_trace" width="525" height="303" class="aligncenter size-medium wp-image-1531" /></a></div>
<p><b>This is a small region of the ECG trace.</b>  The &#8220;R&#8221; peak is most obvious, but the details of the other peaks are not as visible.  If you want more definition in the trace (such as the blue one at the top of the page), consider applying a small collection of customized band-stop filters to the audio file rather than a single, sweeping lowpass filter.  Refer to <a href="http://www.swharden.com/blog/category/diy-ecg-home-made-electrocardiogram/" >earlier posts in the DIY ECG category</a> for details.  Specifically, code on <a href="http://www.swharden.com/blog/2009-01-15-circuits-vs-software/" >Circuits vs. Software for noise reduction</a> entry can help.  For our purposes, calculating heart rate from R-to-R intervals (RRIs) can be done accurately with traces such as this.</p>
<div align="center"><a href="http://www.SWHarden.com/blog/images/diy_ecg_heart_rate_over_time.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/diy_ecg_heart_rate_over_time-525x303.png" alt="diy_ecg_heart_rate_over_time" title="diy_ecg_heart_rate_over_time" width="525" height="303" class="aligncenter size-medium wp-image-1525" /></a></div>
<p><b>Your heart rate fluctuates a lot over time!</b>  By plotting the inverse of your RRIs, you can see your heart rate as a function of time.  Investigate what makes it go up, go down, and how much.  You&#8217;d be surprised by what you find.  I found that checking my email raises my heart rate more than first-person-shooter video games.  I get incredibly anxious when I check my mail these days, because I fear bad news from my new university (who knows why, I just get nervous about it).  I wonder if accurate RRIs could be used to assess nervousness for the purposes of lie detection?</p>
<div align="center"><a href="http://www.SWHarden.com/blog/images/diy_ecg_rr_beat_interval.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/diy_ecg_rr_beat_interval-525x303.png" alt="diy_ecg_rr_beat_interval" title="diy_ecg_rr_beat_interval" width="525" height="303" class="aligncenter size-medium wp-image-1529" /></a></div>
<p><b>This is the RRI plot</b> where the value of each RRI (in milliseconds) is represented for each beat.  It&#8217;s basically the inverse of heart rate.  Miscalculated heartbeats would show up as extremely high or extremely low dots on this graph.  However, excluding points above or below certain bounds means that if your heart did double-beat, or skip a beat, you wouldn&#8217;t see it.  Note that I just realized my axis label is wrong (it should be sec, not ms).  Oh well =o\</p>
<div align="center"><a href="http://www.SWHarden.com/blog/images/diy_ecg_poincare_plot.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/diy_ecg_poincare_plot-525x303.png" alt="diy_ecg_poincare_plot" title="diy_ecg_poincare_plot" width="525" height="303" class="aligncenter size-medium wp-image-1526" /></a></div>
<p><b>A <a href="http://en.wikipedia.org/wiki/Poincar%C3%A9_plot" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">Poincare Plot</a></b> is a commonly-used method to visually assess heart rate variability as a function of RRIs.  In this plot, each RRI is plotted against the RRI of the next subsequent beat.  In a heart which beats at the same speed continuously, only a single dot would be visible in the center.  In a heart which beats mostly-continuously, and only changes its rate very slowly, a linear line of dots would be visible in a 1:1 ratio.  However, in real life the heart varies RRIs greatly from beat to beat, producing a small cloud of dots.  The size of the cloud corresponds to the speed at which the autonomic nervous system can modulate heart rate in the time frame of a single beat.</p>
<div align="center"><a href="http://www.SWHarden.com/blog/images/diy_ecg_rr_deviation_histogram.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/diy_ecg_rr_deviation_histogram-525x303.png" alt="diy_ecg_rr_deviation_histogram" title="diy_ecg_rr_deviation_histogram" width="525" height="303" class="aligncenter size-medium wp-image-1530" /></a></div>
<p><b>The frequency of occurrence</b> of various RRIs can be expressed by a histogram.  The center peak corresponds to the standard heart rate.  Peaks to the right and left of the center peak correspond to increased and decreased RRIs, respectively. A gross oversimplification of the interpretation of such data would be to state that the upper peak represents the cardio-inhibitory parasympathetic autonomic nervous system component, and the lower peak represents the cardio-stimulatory sympathetic autonomic nervous system component.</p>
<div align="center"><a href="http://www.SWHarden.com/blog/images/diy_ecg_power_spectrum_raw.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/diy_ecg_power_spectrum_raw-525x303.png" alt="diy_ecg_power_spectrum_raw" title="diy_ecg_power_spectrum_raw" width="525" height="303" class="aligncenter size-medium wp-image-1527" /></a></div>
<p><b>Taking the <a href="http://en.wikipedia.org/wiki/Fast_Fourier_transform" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">Fast Fourier Transformation</a> of the data</b> produces a unique trace whose significance is extremely difficult to interpret.  Near 0Hz (infinite time) the trace heads toward &#8734; (infinite power). To simplify the graph and eliminate the near-infinite, low-frequency peak we will normalize the trace by multiplying each data point by its frequency, and dividing the vertical axis units by Hz to compensate.  This will produce the following graph&#8230;</p>
<p><a href="http://www.SWHarden.com/blog/images/diy_ecg_power_spectrum_weighted.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/diy_ecg_power_spectrum_weighted-525x303.png" alt="diy_ecg_power_spectrum_weighted" title="diy_ecg_power_spectrum_weighted" width="525" height="303" class="aligncenter size-medium wp-image-1528" /></a><br />
<b>This is the power spectrum density (PSD) plot</b> of the ECG data we recorded.  Its physiological interpretation is extraordinarily difficult to understand and confirm, and is the subject of great debate in the field of autonomic neurological cardiac regulation.  An oversimplified explanation of the significance of this graph is that the parasympathetic (cardio-inhibitory) branch of the autonomic nervous system works faster than the sympathetic (cardio-stimulatory) branch.  Therefore, the lower peak corresponds to the sympathetic component (combined with persistent parasympathetic input, it&#8217;s complicated), while the higher-frequency peak corresponds to the parasympathetic component, and the sympathetic/parasympathetic relationship can be assessed by the ratio of the integrated areas of these peaks after a complicated <a href="http://en.wikipedia.org/wiki/Curve_fitting" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">curve fitting</a> processes which completely separates overlapping peaks. To learn more about power spectral analysis of heart rate over time in the frequency domain, I recommend skimming <a href="http://www.macses.ucsf.edu/Research/Allostatic/notebook/heart.rate.html" onclick="javascript:urchinTracker ('/outbound/article/www.macses.ucsf.edu');">this introduction to heart rate variability website</a> and the article on <a href="http://www.swharden.com/blog/wp-admin/post.php?action=edit&#038;post=1512" >Heart Rate Variability following Myocardial Infarction</a> (heart attack).  Also, National Institute of Health (NIH) funded studies on HRV should be available from <a href="http://www.ncbi.nlm.nih.gov/pubmed/" onclick="javascript:urchinTracker ('/outbound/article/www.ncbi.nlm.nih.gov');">pubmed.org</a>.  If you want your head to explode, read <a href="http://jap.physiology.org/cgi/reprint/100/3/817.pdf" onclick="javascript:urchinTracker ('/outbound/article/jap.physiology.org');">Frequency-Domain Characteristics and Filtering of Blood Flow Following the Onset of Exercise: Implications for Kinetics Analysis</a> for a lot of good frequency-domain-analysis-related discussion and rationalization.</p>
<h2>Encouraging Words:</h2>
<p><b>Please, if you try this don&#8217;t die.</b>  The last thing I want is to have some kid calling me up and yelling at me that he nearly electrocuted himself when he tried to plug my device directly into a wall socket and now has to spend the rest of his life with two Abraham Lincolns tattooed onto his chest resembling a second set of nipples.  Please, if you try this use common sense, and of course you&#8217;re responsible for your own actions.  I provide this information as a description of what I did and what worked for me.  If you make something similar that works, I&#8217;ve love to see it!  Send in your pictures of your circuit, charts of your traces, improved code, or whatever you want and I&#8217;ll feature it on the site.  <b>GOOD LUCK!</b></p>
<h2>Fancier Circuit:</h2>
<p><b>If you want to try this, go for it!</b>  Briefly, this circuit uses 6 op-amps to help eliminate effects of noise.  It&#8217;s also safer, because of the diodes interconnecting the electrodes.  It&#8217;s the same circuit as on [<a href="http://www.eng.utah.edu/~jnguyen/ecg/ecg_index.html" onclick="javascript:urchinTracker ('/outbound/article/www.eng.utah.edu');">this page</a>].<br />
<a href="http://www.SWHarden.com/blog/images/diy_ecg_circuit.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/diy_ecg_circuit-500x449.png" alt="" title="diy_ecg_circuit" width="500" height="449" class="alignnone size-medium wp-image-676" align="center" /></a></p>
<h2>Last minute thoughts:</h2>
<blockquote><ul>
<li>More homemade ECG information can be found on my <a href="http://www.swharden.com/blog/category/diy-ecg-home-made-electrocardiogram/" >earlier posts in the DIY ECG category</a>, however this page is the primary location of my most recent thoughts and ideas.
</li>
<li>You can use moisturizing lotion between the electrodes and your skin to increase conduction.  However, keep in mind that <i>better conduction is not always what you want</i>.  You&#8217;ll have to experiment for yourself.
</li>
<li>Variation in location of electrodes will vary the shape of the ECG.  I usually place electrodes on each side of my chest near my arms.  If your ECG appears upside-down, reverse the leads!
</li>
<li>Adding extra leads can improve grounding.  Try grounding one of your feet with a third lead to improve your signal. Also, if you&#8217;re powering your device via USB power consider trying battery power &#8211; it should be less noisy.</li>
<li>While recording, be aware of what you do!  I found that if I&#8217;m not well-grounded, my ECG is fine as long as I don&#8217;t touch my keyboard.  If I start typing, every keypress shows up as a giant spike, bigger than my heartbeat!</li>
<li>If you get reliable results, I wonder if you could make the device portable? Try using a portable tape recorder, voice recorder, or maybe even minidisc recorder to record the output of the ECG machine for an entire day.  I haven&#8217;t tried it, but why wouldn&#8217;t it work? If you want to get fancy, have a <a href="http://www.swharden.com/blog/category/microcontrollers/" >microcontroller</a> handle the signal processing and determine RRIs (should be easy) and save this data to a <a href="http://www.instructables.com/id/Cheap-DIY-SD-card-breadboard-socket/" onclick="javascript:urchinTracker ('/outbound/article/www.instructables.com');">SD card</a> or <a href="http://www.4dsystems.com.au/prod.php?id=22" onclick="javascript:urchinTracker ('/outbound/article/www.4dsystems.com.au');">fancy flash logger</a>. </li>
<li>The microcontroller could output heart rate <a href="http://www.swharden.com/blog/2009-05-14-simple-case-avrpc-serial-communication-via-max232/" >via the serial port</a>.</li>
<li>If you have a microcontroller on board, why not <a href="http://www.swharden.com/blog/2009-05-17-attiny2313-controlling-a-hd44780-lcd-via-avr-gcc/" >display heart rate on a character LCD?</a></li>
<li>While you have a LCD on there, display the ECG <i>graphically</i>!</li>
<li>Perhaps a wireless implementation would be useful.</li>
<li>Like, I said, there are other, more complicated analog circuits which reduce noise of the outputted signal.  I actually built <a href="http://www.eng.utah.edu/~jnguyen/ecg/ecg_index.html" onclick="javascript:urchinTracker ('/outbound/article/www.eng.utah.edu');">Jason Nguyen&#8217;s fancy circuit</a> which <a href="http://www.eng.utah.edu/~jnguyen/ecg/bigsch.gif" onclick="javascript:urchinTracker ('/outbound/article/www.eng.utah.edu');">used 6 op-amps</a> but the result wasn&#8217;t much better than the simple, 1 op-amp circuit I describe here once digital filtering was applied.
</li>
<li>Arrhythmic heartbeats (where your heart screws-up and misfires, skips a beat, double-beats, or beats awkwardly) are physiological (normal) and surprisingly common.  Although shocking to hear about, sparse, single arrhythmic heartbeats are normal and are a completely different ball game than chronic, potentially deadly heart arrhythmias in which every beat is messed-up.  If you&#8217;re in tune with your body, you might actually <i>feel</i> these occurrences happening.  About three times a week I feel my heart screw up a beat (often when it&#8217;s quiet), and it feels like a sinking feeling in my chest.  I was told by a doctor that it&#8217;s totally normal and happens many times every day without me noticing, and that most people <i>never</i> notice these single arrhythmic beats.  I thought it was my heart skipping a beat, but I wasn&#8217;t sure. That was my motivation behind building this device &#8211; I wanted to <i>see</i> what my arrhythmic beats looked like.  It turns out that it&#8217;s more of a double-beat than a skipped beat, as observed when I <a href="http://www.swharden.com/blog/images/murm2.png" >captured a single arrhythmic heartbeat</a> with my ECG machine, as described in <a href="http://www.swharden.com/blog/2009-01-20-653-diy-ecg-detected-an-irregular-heartbeat/" >this entry</a>.</li>
<li>You can improve the safety of this device by attaching diodes between leads, similar to <a href="http://www.swharden.com/blog/images/diy_ecg_circuit.png" >the more complicated circuit</a>.  Theory is that if a huge surge of energy <i>does</i> for whatever reason get into the ECG circuit, it&#8217;ll short itself out at the circuit level (conducting through the diodes) rather than at your body (across your chest / through your heart).</li>
<li>Alternatively, use an AC <a href="http://en.wikipedia.org/wiki/Opto-isolator" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">opto-isolator</a> between the PC sound card and the ECG circuit to eliminate the possibility of significant current coming back from the PC.</li>
<li>On the <a href="http://hackaday.com/2009/08/22/collect-and-analyze-ecg-data/" onclick="javascript:urchinTracker ('/outbound/article/hackaday.com');">Hackaday post</a>, <a href="http://dren.dk/" onclick="javascript:urchinTracker ('/outbound/article/dren.dk');">Flemming Frandsen</a> noted that an improperly grounded PC could be dangerous because the stored charge would be manifest in the ground of the microphone jack.  If you were to ground yourself to true ground (using a bench power supply or sticking your finger in the ground socket of an AC wall plug) this energy could travel through <i>you</i>!  So be careful to only ground yourself with respect to the circuit using only battery power to minimize this risk.</li>
<li>Do not attempt anything on this page.  Ever.  Don&#8217;t even read it. You read it already! You&#8217;re sill reading it aren&#8217;t you?  Yeah. You don&#8217;t follow directions well do you?</li>
</ul>
</blockquote>
<h2>SAMPLE FILTERED RECORDING:</h2>
<p>I think this is the same one I used in the 3rd video from my single op-amp circuit. [<a href='http://www.SWHarden.com/blog/images/scottecg.snd'>scottecg.snd</a>]   It&#8217;s about an hour long, and in raw sound format (1000 Hz).  It&#8217;s already been filtered (low-pass filtered at 30Hz). You can use it with my code below!</p>
<h2>CODE</h2>
<pre class="prettyprint python">
print "importing libraries..."
import numpy, pylab
print "DONE"

class ECG:

    def trim(self, data,degree=100):
        print 'trimming'
        i,data2=0,[]
        while i&lt;len(data):
            data2.append(sum(data[i:i+degree])/degree)
            i+=degree
        return data2

    def smooth(self,list,degree=15):
        mults=[1]
        s=[]
        for i in range(degree): mults.append(mults[-1]+1)
        for i in range(degree): mults.append(mults[-1]-1)
        for i in range(len(list)-len(mults)):
            small=list[i:i+len(mults)]
            for j in range(len(small)):
                small[j]=small[j]*mults[j]
            val=sum(small)/sum(mults)
            s.append(val)
        return s

    def smoothWindow(self,list,degree=10):
        list2=[]
        for i in range(len(list)):
            list2.append(sum(list[i:i+degree])/float(degree))
        return list2

    def invertYs(self):
        print 'inverting'
        self.ys=self.ys*-1

    def takeDeriv(self,dist=5):
        print 'taking derivative'
        self.dys=[]
        for i in range(dist,len(self.ys)):
            self.dys.append(self.ys[i]-self.ys[i-dist])
        self.dxs=self.xs[0:len(self.dys)]

    def genXs(self, length, hz):
        print 'generating Xs'
        step = 1.0/(hz)
        xs=[]
        for i in range(length): xs.append(step*i)
        return xs

    def loadFile(self, fname, startAt=None, length=None, hz=1000):
        print 'loading',fname
        self.ys = numpy.memmap(fname, dtype='h', mode='r')*-1
        print 'read %d points.'%len(self.ys)
        self.xs = self.genXs(len(self.ys),hz)
        if startAt and length:
            self.ys=self.ys[startAt:startAt+length]
            self.xs=self.xs[startAt:startAt+length]

    def findBeats(self):
        print 'finding beats'
        self.bx,self.by=[],[]
        for i in range(100,len(self.ys)-100):
          if self.ys[i]&lt;15000: continue # SET THIS VISUALLY
          if self.ys[i]&lt;self.ys[i+1] or self.ys[i]&lt;self.ys[i-1]: continue
          if self.ys[i]-self.ys[i-100]&gt;5000 and self.ys[i]-self.ys[i+100]&gt;5000:
              self.bx.append(self.xs[i])
              self.by.append(self.ys[i])
        print "found %d beats"%(len(self.bx))

    def genRRIs(self,fromText=False):
        print 'generating RRIs'
        self.rris=[]
        if fromText: mult=1
        else: 1000.0
        for i in range(1,len(self.bx)):
            rri=(self.bx[i]-self.bx[i-1])*mult
            #if fromText==False and len(self.rris)&gt;1:
                #if abs(rri-self.rris[-1])&gt;rri/2.0: continue
            #print i, "%.03f\t%.03f\t%.2f"%(bx[i],rri,60.0/rri)
            self.rris.append(rri)

    def removeOutliers(self):
        beatT=[]
        beatRRI=[]
        beatBPM=[]
        for i in range(1,len(self.rris)):
            #CHANGE THIS AS NEEDED
            if self.rris[i]&lt;0.5 or self.rris[i]&gt;1.1: continue
            if abs(self.rris[i]-self.rris[i-1])&gt;self.rris[i-1]/5: continue
            beatT.append(self.bx[i])
            beatRRI.append(self.rris[i])
        self.bx=beatT
        self.rris=beatRRI

    def graphTrace(self):
        pylab.plot(self.xs,self.ys)
        #pylab.plot(self.xs[100000:100000+4000],self.ys[100000:100000+4000])
        pylab.title("Electrocardiograph")
        pylab.xlabel("Time (seconds)")
        pylab.ylabel("Potential (au)")

    def graphDeriv(self):
        pylab.plot(self.dxs,self.dys)
        pylab.xlabel("Time (seconds)")
        pylab.ylabel("d/dt Potential (au)")

    def graphBeats(self):
        pylab.plot(self.bx,self.by,'.')

    def graphRRIs(self):
        pylab.plot(self.bx,self.rris,'.')
        pylab.title("Beat Intervals")
        pylab.xlabel("Beat Number")
        pylab.ylabel("RRI (ms)")

    def graphHRs(self):
        #HR TREND
        hrs=(60.0/numpy.array(self.rris)).tolist()
        bxs=(numpy.array(self.bx[0:len(hrs)])/60.0).tolist()
        pylab.plot(bxs,hrs,'g',alpha=.2)
        hrs=self.smooth(hrs,10)
        bxs=bxs[10:len(hrs)+10]
        pylab.plot(bxs,hrs,'b')
        pylab.title("Heart Rate")
        pylab.xlabel("Time (minutes)")
        pylab.ylabel("HR (bpm)")

    def graphPoincare(self):
        #POINCARE PLOT
        pylab.plot(self.rris[1:],self.rris[:-1],"b.",alpha=.5)
        pylab.title("Poincare Plot")
        pylab.ylabel("RRI[i] (sec)")
        pylab.xlabel("RRI[i+1] (sec)")

    def graphFFT(self):
        #PSD ANALYSIS
        fft=numpy.fft.fft(numpy.array(self.rris)*1000.0)
        fftx=numpy.fft.fftfreq(len(self.rris),d=1)
        fftx,fft=fftx[1:len(fftx)/2],abs(fft[1:len(fft)/2])
        fft=self.smoothWindow(fft,15)
        pylab.plot(fftx[2:],fft[2:])
        pylab.title("Raw Power Sprectrum")
        pylab.ylabel("Power (ms^2)")
        pylab.xlabel("Frequency (Hz)")

    def graphFFT2(self):
        #PSD ANALYSIS
        fft=numpy.fft.fft(numpy.array(self.rris)*1000.0)
        fftx=numpy.fft.fftfreq(len(self.rris),d=1)
        fftx,fft=fftx[1:len(fftx)/2],abs(fft[1:len(fft)/2])
        fft=self.smoothWindow(fft,15)
        for i in range(len(fft)):
            fft[i]=fft[i]*fftx[i]
        pylab.plot(fftx[2:],fft[2:])
        pylab.title("Power Sprectrum Density")
        pylab.ylabel("Power (ms^2)/Hz")
        pylab.xlabel("Frequency (Hz)")

    def graphHisto(self):
        pylab.hist(self.rris,bins=20,ec='none')
        pylab.title("RRI Deviation Histogram")
        pylab.ylabel("Frequency (count)")
        pylab.xlabel("RRI (ms)")
        #pdf, bins, patches = pylab.hist(self.rris,bins=100,alpha=0)
        #pylab.plot(bins[1:],pdf,'g.')
        #y=self.smooth(list(pdf[1:]),10)
        #x=bins[10:len(y)+10]
        #pylab.plot(x,y)

    def saveBeats(self,fname):
        print "writing to",fname
        numpy.save(fname,[numpy.array(self.bx)])
        print "COMPLETE"

    def loadBeats(self,fname):
        print "loading data from",fname
        self.bx=numpy.load(fname)[0]
        print "loadded",len(self.bx),"beats"
        self.genRRIs(True)

def snd2txt(fname):
    ## SND TO TXT ##
    a=ECG()
    a.loadFile(fname)#,100000,4000)
    a.invertYs()
    pylab.figure(figsize=(7,4),dpi=100);pylab.grid(alpha=.2)
    a.graphTrace()
    a.findBeats()
    a.graphBeats()
    a.saveBeats(fname)
    pylab.show()

def txt2graphs(fname):
    ## GRAPH TXT ##
    a=ECG()
    a.loadBeats(fname+'.npy')
    a.removeOutliers()
    pylab.figure(figsize=(7,4),dpi=100);pylab.grid(alpha=.2)
    a.graphHRs();pylab.subplots_adjust(left=.1,bottom=.12,right=.96)
    pylab.savefig("DIY_ECG_Heart_Rate_Over_Time.png");
    pylab.figure(figsize=(7,4),dpi=100);pylab.grid(alpha=.2)
    a.graphFFT();pylab.subplots_adjust(left=.13,bottom=.12,right=.96)
    pylab.savefig("DIY_ECG_Power_Spectrum_Raw.png");
    pylab.figure(figsize=(7,4),dpi=100);pylab.grid(alpha=.2)
    a.graphFFT2();pylab.subplots_adjust(left=.13,bottom=.12,right=.96)
    pylab.savefig("DIY_ECG_Power_Spectrum_Weighted.png");
    pylab.figure(figsize=(7,4),dpi=100);pylab.grid(alpha=.2)
    a.graphPoincare();pylab.subplots_adjust(left=.1,bottom=.12,right=.96)
    pylab.savefig("DIY_ECG_Poincare_Plot.png");
    pylab.figure(figsize=(7,4),dpi=100);pylab.grid(alpha=.2)
    a.graphRRIs();pylab.subplots_adjust(left=.1,bottom=.12,right=.96)
    pylab.savefig("DIY_ECG_RR_Beat_Interval.png");
    pylab.figure(figsize=(7,4),dpi=100);pylab.grid(alpha=.2)
    a.graphHisto();pylab.subplots_adjust(left=.1,bottom=.12,right=.96)
    pylab.savefig("DIY_ECG_RR_Deviation_Histogram.png");
    pylab.show();

fname='publish_05_10min.snd' #CHANGE THIS AS NEEDED
#raw_input("\npress ENTER to analyze %s..."%(fname))
snd2txt(fname)
#raw_input("\npress ENTER to graph %s.npy..."%(fname))
txt2graphs(fname)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.SWHarden.com/blog/2009-08-14-diy-ecg-machine-on-the-cheap/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
<enclosure url="http://www.SWHarden.com/blog/images/scottecg.snd" length="1800000" type="audio/basic" />
		</item>
		<item>
		<title>Defibrillating My DIY ECG Project</title>
		<link>http://www.SWHarden.com/blog/2009-08-06-defibrillating-my-diy-ecg-project/</link>
		<comments>http://www.SWHarden.com/blog/2009-08-06-defibrillating-my-diy-ecg-project/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 16:35:43 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Circuitry]]></category>
		<category><![CDATA[DIY ECG]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.SWHarden.com/blog/?p=1406</guid>
		<description><![CDATA[I&#8217;ve done a lot of random things the last few months, but few things were as random, cool, or googled-for as my Do-It-Yourself Electrocardiography project .  My goal was to produce an effective ECG machine which interfaced the computer sound card for as little cost as possible. I started out small with an extremely [...]]]></description>
			<content:encoded><![CDATA[<p><b>I&#8217;ve done a lot of random things the last few months,</b> but few things were as random, cool, or googled-for as my <a href="http://www.swharden.com/blog/category/diy-ecg-home-made-electrocardiogram/" >Do-It-Yourself Electrocardiography project </a>.  My goal was to produce an effective ECG machine which interfaced the computer sound card for as little cost as possible. I started out small with an <a href="http://www.swharden.com/blog/images/diy_ecg5.jpg" >extremely simple circuit</a> which technically worked, but required <a href="http://www.swharden.com/blog/images/diy_ecg4.png" >a lot of custom-written software to do a ton of math</a> to decipher the ECG signal from the noise (such as <a href="http://www.swharden.com/blog/images/filtering.png" >inverse fast flourier transformations after band-stopping several bands of predictable, high-frequency noise</a>).  I later started building <a href="http://www.swharden.com/blog/images/bigsch.gif" >more complicated circuits</a> in an attempt to minimize the noise, which worked well but were much more difficult to construct.  For some reason, my nice ECG circuit died (burned? broke? don&#8217;t know why) right after I started to actually generate <a href="http://www.swharden.com/blog/images/murm2.png" >useful data about my occasional double-beats</a> (which apparently are common, normal, and even expected during basal physiological states).<br />
<b>UPDATE:</b> [2am, nextday]  Here&#8217;s some video of the prototype briefly demonstrating the concept of how to use a minimum of parts to generate a great ECG trace using digital signal processing on the PC side.<br />
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/6-zNMup_pgk&#038;hl=en&#038;fs=1&#038;color1=0x006699&#038;color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/6-zNMup_pgk&#038;hl=en&#038;fs=1&#038;color1=0x006699&#038;color2=0x54abd6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object><br />
<a href="http://www.SWHarden.com/blog/images/simple_ecg_circuit_output.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/simple_ecg_circuit_output-525x185.png" alt="simple_ecg_circuit_output" title="simple_ecg_circuit_output" width="525" height="185" class="aligncenter size-medium wp-image-1408" /></a></p>
<p><b>I&#8217;ve decided to revitalize this project</b> quickly and effectively, going back to its roots and focusing on cost-minimal solutions, and using software (rather than complicated analog circuitry) to eliminate the noise.  This will be a beautiful marriage of biomedical analog circuitry with software-based processing and linear data analysis, all on the cheap.  If there were ever a project that represented my early 20s life, this would be it.  Briefly, I built a circuit with only 3 components (!) which produces extraordinary results (above).  That&#8217;s the signal after minimal processing.</p>
<p><b>Check it out yourself!</b>  I&#8217;ll provide <a href="http://www.SWHarden.com/blog/images/ecg2.zip" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');">data file for this trace (snd2.zip)</a> along with the Python code to graph it (below) which requires <a href="http://numpy.scipy.org" onclick="javascript:urchinTracker ('/outbound/article/numpy.scipy.org');">numpy</a> and <a href="matplotlib.sourceforge.net">matplotlib</a> in addition to the <a href="http://www.python.org" onclick="javascript:urchinTracker ('/outbound/article/www.python.org');">Python scripting language</a>.  I&#8217;ll post the circuity along with some more intricate code when my project progresses a little further.</p>
<pre class="prettyprint python">
import numpy, pylab

def trim(data,degree=100):
    i,data2=0,[]
    while i&#038;ltlen(data):
        data2.append(sum(data[i:i+degree])/degree)
        i+=degree
    return data2

def genXs(length,trim=100,hz=44100):
    step = 1.0/(hz/trim)
    xs=[]
    for i in range(length):
        xs.append(step*i)
    return xs

data = numpy.memmap("ecg2.snd", dtype='h', mode='r')
data = trim(data)
pylab.grid(alpha=.2)
pylab.plot(genXs(len(data)),data)
pylab.title("Simplified ECG Circuit Output")
pylab.xlabel("Time (seconds)")
pylab.ylabel("Potential (Au)")
pylab.show()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.SWHarden.com/blog/2009-08-06-defibrillating-my-diy-ecg-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Losing&#8230; Energy&#8230; Fast&#8230;</title>
		<link>http://www.SWHarden.com/blog/2009-01-28-losing-energy-fast/</link>
		<comments>http://www.SWHarden.com/blog/2009-01-28-losing-energy-fast/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 23:09:19 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[DIY ECG]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.SWHarden.com/blog/?p=686</guid>
		<description><![CDATA[ Only a couple weeks into my self-induced crunch time (caused by the fact my thesis work is supposed to be completed in less than a month) I&#8217;m beginning to feel a little overwhelmed.  I still don&#8217;t feel it&#8217;s impossible, but I do feel like I&#8217;m making things better than they actually are in [...]]]></description>
			<content:encoded><![CDATA[<p> <b>Only a couple weeks into</b> my self-induced crunch time (caused by the fact my thesis work is supposed to be completed in less than a month) I&#8217;m beginning to feel a little overwhelmed.  I still don&#8217;t feel it&#8217;s impossible, but I do feel like I&#8217;m making things better than they actually are in my mind.  In what free time I do have, I work on side projects (like my homemade ECG machine).  Last night I recorded myself sleeping.  In the middle of the night I woke up and the electrodes were incredibly uncomfortable, so I ripped them off my chest and arms (ouch!) and threw them on the floor and went back to sleep.  I figured that I had at least several hours&#8217; worth of data, so I&#8217;d be fine.  The next morning when I woke up I examined the recordings, and apparently I had fallen asleep in under a minute, slept for 29 minutes, then woke up and (assuming it was several hours later) ripped off the electrodes.  That&#8217;s it!  A mere 29 minutes of recording.  One day I&#8217;ll get my whole sleep cycle recorded.  Just you wait.  </p>
<p> <a href="http://www.SWHarden.com/blog/images/ecg_goodie.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/ecg_goodie.png" alt="" title="ecg_goodie" width="500" height="377" class="alignnone size-full wp-image-687" align="center"/></a>  </p>
<p> <b>Here&#8217;s a little visual goodie</b> from that recording.  This data was processed in a new way &#8211; no Fourier transformation!  I integrated the original trace, smoothed it 3 times, identified peaks, and used the inverse peak-to-peak distance to determine heart rate.  The trace itself is not beautiful (see photo and compare it with previous traces) but if I&#8217;ll I&#8217;m determining is heartrate, it works!  If there&#8217;s a weird problem (missed beats, double beats, etc) it will show up as a spike on the heartrate trace and then I can use better tools to identify the trouble in the region affected.  </p>
<p> <b>Okay, it&#8217;s about time</b> I go do something.  I&#8217;m in the laboratory right now (go fig) but surprisingly I can&#8217;t do a whole lot.  I just got some new chemicals in today and am performing a trial run which will be completed tomorrow.  Until then, I just have to wait for 18 hours for a reaction to complete.  Maybe I&#8217;ll browse <a href="http://deviantart.com/" onclick="javascript:urchinTracker ('/outbound/article/deviantart.com');">DA</a> or try to draw something groovy in inkscape.  See ya!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.SWHarden.com/blog/2009-01-28-losing-energy-fast/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Signal Filtering with Python</title>
		<link>http://www.SWHarden.com/blog/2009-01-21-signal-filtering-with-python/</link>
		<comments>http://www.SWHarden.com/blog/2009-01-21-signal-filtering-with-python/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 20:25:04 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[DIY ECG]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.SWHarden.com/blog/?p=657</guid>
		<description><![CDATA[ It&#8217;s time for a lecture.  I&#8217;ve been spending a lot of time creating a DIY dlectrocardiogram and it produces fairly noisy signals.  I&#8217;ve spent some time and effort researching the best ways to clean-up these signals, and the results are incredibly useful!  Therefore, I&#8217;ve decided to lightly document these results in [...]]]></description>
			<content:encoded><![CDATA[<p> <b>It&#8217;s time for a lecture.</b>  I&#8217;ve been spending a lot of time creating a <a href="http://www.swharden.com/blog/category/diy-ecg-home-made-electrocardiogram/" >DIY dlectrocardiogram</a> and it produces fairly noisy signals.  I&#8217;ve spent some time and effort researching the best ways to clean-up these signals, and the results are incredibly useful!  Therefore, I&#8217;ve decided to lightly document these results in a blog entry.  </p>
<p> <b>Here&#8217;s an example of my magic!</b>  I take a noisy recording and turn it into a beautiful trace.  See the example figure with the blue traces.    How is this possible?  Well I&#8217;ll explain it for you.  <a href="http://www.SWHarden.com/blog/images/filtering.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/filtering-414x700.png" alt="" title="filtering" width="414" height="700" align="left" /></a> Mostly, it boils down to eliminating excess high-frequency <a href="http://en.wikipedia.org/wiki/Sine_wave" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">sine waves</a> which are in the original recording due to electromagnetic noise.  A major source of noise can be from the <a href="http://en.wikipedia.org/wiki/Alternating_current" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">alternating current</a> passing through wires traveling through the walls of your house or building.  My <a href="http://www.swharden.com/blog/images/opampecg.gif" >original ECG circuit</a> was highly susceptible to this kind of interference, but my <a href="http://www.swharden.com/blog/images/bigsch.gif" >improved ECG circuit</a> eliminates most of this noise.  However, noise is still in the trace (see the figure to the left), and it needed to be removed.  </p>
<p> <b>The key is the FFT (Fast Fourier Transformation) algorithm</b> which <a href="http://en.wikipedia.org/wiki/Fast_Fourier_transform" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">can get pretty intimidating</a> to research at first!  I&#8217;ll simplify this process.  Let&#8217;s say you have a trace with repeating sine-wave-shaped noise.  The output of the FFT transformation of the signal is the breakdown of the signal by frequency.  Check out <a href="http://www.swharden.com/blog/images/diy_ecg4.png" >this FFT trace of a noisy signal</a> from a few posts ago (top graph).  High peaks represent frequencies which are common.  See the enormous peak around 60 Hz? (Hz means &#8220;per second&#8221; by the way, so 60 Hz is a sine wave that repeats 60 times a second)  That&#8217;s from my AC noise.  Other peaks (shown in colored bands) are other electromagnetic noise sources, such as wireless networks, TVs, telephones, and your computer processor.  The heart produces changes in electricity that are very slow (the heartbeat is about 1 Hz, or 1 beat per second), so <i>if we can eliminate all of the sine waves with frequencies higher than what we want to isolate</i> we can get a pretty clear trace.  This is called a band-stop filter (we block-out certain bands of frequencies)  A band-pass filter is the opposite, where we only allow frequencies which are below (low-pass) or above (high-pass) a given frequency.  By eliminating each of the peaks in the colored regions (setting each value to 0), then performing an inverse fast Fourier transformation (going backwards from frequency back to time), the result is the signal trace (seen as light gray on the bottom graph) with those high-frequency sine waves removed!  (the gray trace on the bottom graph).  A little touch-up smoothing makes a great trace (black trace on the bottom graph).  </p>
<p> <b>Here&#8217;s some Python code to get you started in cleaning-up your noisy signals!</b>  The image below is the output of the Python code at the bottom of this entry.  This python file requires that <a href="http://www.SWHarden.com/tmp/test.wav" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');">test.wav (~700kb)</a> (an actual ECG recording of my heartbeat) be saved in the same folder.  Brief descriptions of each portion of the graph will follow.  </p>
<p> <a href="http://www.SWHarden.com/blog/images/sig.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/sig-500x375.png" alt="" title="sig" width="500" height="375" class="alignnone size-medium wp-image-659" /></a>  </p>
<p> <b>(A)</b> The original signal we want to isolate. (IE: our actual heart signal)  </p>
<p> <b>(B)</b> Some electrical noise. (3 sine waves of different amplitudes and periods)  </p>
<p> <b>(C)</b> Electrical noise (what happens when you add those 3 sine waves together)  </p>
<p> <b>(D)</b> Static (random noise generated by a random number generator)  </p>
<p> <b>(E)</b> Signal (A) plus static (D)  </p>
<p> <b>(F)</b> Signal (A) plus static (D) plus electrical noise (C)  </p>
<p> <b>(G)</b> Total FFT trace of (F).  Note the low frequency peak due to the signal and electrical noise (near 0) and the high frequency peak due to static (near 10,000)  </p>
<p> <b>(H)</b> This is a zoomed-in region of (F) showing 4 peaks (one for the original signal and 3 for high frequency noise).  By blocking-out (set it to 0) everything above 10Hz (red), we isolate the peak we want (signal).  This is a low-pass filter.  </p>
<p> <b>(I)</b> Performing an inverse FFT (iFFT) on the low-pass iFFT, we get a nice trace which is our original signal!  </p>
<p> <b>(J)</b> Comparison of our iFFT with our original signal shows that the amplitude is kinda messed up.  If we normalize each of these (set minimum to 0, maximum to 1) they line up.  Awesome!  </p>
<p> <b>(K)</b> How close were we?  Graphing the difference of iFFT and the original signal shows that usually we&#8217;re not far off.  The ends are a problem though, but if our data analysis trims off these ends then our center looks great.  </p>
<p> <b>Here&#8217;s the code I used to make the image:</b>  </p>
<pre name="code" class="prettyprint lang-py:collapse">
 import numpy, scipy, pylab, random  

 # This script demonstrates how to use band-pass (low-pass)  
 # filtering to eliminate electrical noise and static  
 # from signal data!  

 ##################  
 ### PROCESSING ###  
 ##################  

 xs=numpy.arange(1,100,.01) #generate Xs (0.00,0.01,0.02,0.03,...,100.0)  
 signal = sin1=numpy.sin(xs*.3) #(A)  
 sin1=numpy.sin(xs) # (B) sin1  
 sin2=numpy.sin(xs*2.33)*.333 # (B) sin2  
 sin3=numpy.sin(xs*2.77)*.777 # (B) sin3  
 noise=sin1+sin2+sin3 # (C)  
 static = (numpy.random.random_sample((len(xs)))-.5)*.2 # (D)  
 sigstat=static+signal # (E)  
 rawsignal=sigstat+noise # (F)  
 fft=scipy.fft(rawsignal) # (G) and (H)  
 bp=fft[:]  
 for i in range(len(bp)): # (H-red)  
     if i>=10:bp[i]=0  
 ibp=scipy.ifft(bp) # (I), (J), (K) and (L)  

 ################  
 ### GRAPHING ###  
 ################  

 h,w=6,2  
 pylab.figure(figsize=(12,9))  
 pylab.subplots_adjust(hspace=.7)  

 pylab.subplot(h,w,1);pylab.title("(A) Original Signal")  
 pylab.plot(xs,signal)  

 pylab.subplot(h,w,3);pylab.title("(B) Electrical Noise Sources (3 Sine Waves)")  
 pylab.plot(xs,sin1,label="sin1")  
 pylab.plot(xs,sin2,label="sin2")  
 pylab.plot(xs,sin3,label="sin3")  
 pylab.legend()  

 pylab.subplot(h,w,5);pylab.title("(C) Electrical Noise (3 sine waves added together)")  
 pylab.plot(xs,noise)  

 pylab.subplot(h,w,7);pylab.title("(D) Static (random noise)")  
 pylab.plot(xs,static)  
 pylab.axis([None,None,-1,1])  

 pylab.subplot(h,w,9);pylab.title("(E) Signal + Static")  
 pylab.plot(xs,sigstat)  

 pylab.subplot(h,w,11);pylab.title("(F) Recording (Signal + Static + Electrical Noise)")  
 pylab.plot(xs,rawsignal)  

 pylab.subplot(h,w,2);pylab.title("(G) FFT of Recording")  
 fft=scipy.fft(rawsignal)  
 pylab.plot(abs(fft))  
 pylab.text(200,3000,"signals",verticalalignment='top')  
 pylab.text(9500,3000,"static",verticalalignment='top',  
            horizontalalignment='right')  

 pylab.subplot(h,w,4);pylab.title("(H) Low-Pass FFT")  
 pylab.plot(abs(fft))  
 pylab.text(17,3000,"sin1",verticalalignment='top',horizontalalignment='left')  
 pylab.text(37,2000,"sin2",verticalalignment='top',horizontalalignment='center')  
 pylab.text(45,3000,"sin3",verticalalignment='top',horizontalalignment='left')  
 pylab.text(6,3000,"signal",verticalalignment='top',horizontalalignment='left')  
 pylab.axvspan(10,10000,fc='r',alpha='.5')  
 pylab.axis([0,60,None,None])  

 pylab.subplot(h,w,6);pylab.title("(I) Inverse FFT")  
 pylab.plot(ibp)  

 pylab.subplot(h,w,8);pylab.title("(J) Signal vs. iFFT")  
 pylab.plot(signal,'k',label="signal",alpha=.5)  
 pylab.plot(ibp,'b',label="ifft",alpha=.5)  

 pylab.subplot(h,w,10);pylab.title("(K) Normalized Signal vs. iFFT")  
 pylab.plot(signal/max(signal),'k',label="signal",alpha=.5)  
 pylab.plot(ibp/max(ibp),'b',label="ifft",alpha=.5)  

 pylab.subplot(h,w,12);pylab.title("(L) Difference / Error")  
 pylab.plot(signal/max(signal)-ibp/max(ibp),'k')  

 pylab.savefig("SIG.png",dpi=200)  
 pylab.show()  
 </pre>
]]></content:encoded>
			<wfw:commentRss>http://www.SWHarden.com/blog/2009-01-21-signal-filtering-with-python/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
<enclosure url="http://www.SWHarden.com/tmp/test.wav" length="725274" type="audio/x-wav" />
		</item>
		<item>
		<title>DIY ECG Detected an Irregular Heartbeat</title>
		<link>http://www.SWHarden.com/blog/2009-01-20-653-diy-ecg-detected-an-irregular-heartbeat/</link>
		<comments>http://www.SWHarden.com/blog/2009-01-20-653-diy-ecg-detected-an-irregular-heartbeat/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 17:15:59 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[DIY ECG]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.SWHarden.com/blog/?p=653</guid>
		<description><![CDATA[ Am I going to dlie?  It&#8217;s unlikely.  Upon analyzing ~20 minutes of heartbeat data (some of which is depicted in the previous entry) I found a peculiarity.  Technically this could be some kind of noise (a &#8216;pop&#8217; in the microphone signal due to the shuffling of wires or a momentary disconnect [...]]]></description>
			<content:encoded><![CDATA[<p> <b>Am I going to dlie?</b>  It&#8217;s unlikely.  Upon analyzing ~20 minutes of heartbeat data (some of which is depicted in the previous entry) I found a peculiarity.  Technically this could be some kind of noise (a &#8216;pop&#8217; in the microphone signal due to the shuffling of wires or a momentary disconnect from the electrodes or perhaps even a static shock to my body from something), but because this peculiarity happened only once in 20 minutes I&#8217;m not ruling out the possibility that this is the first irregular heartbeat I captured with my DIY ECG.  Note that single-beat irregularities are common, and that this does not alarm me so much as fascinates me.  Below is the section of the data which contains this irregular beat.  </p>
<p> <a href="http://www.SWHarden.com/blog/images/murm2.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/murm2-500x362.png" alt="" title="murm2" width="500" height="362" class="alignnone size-medium wp-image-651" /></a>  </p>
<p> <b>In the spirit of improvement</b> I wonder how much more interesting this project would be if I were to combine the already-designed ECG machine with a sensor to detect the physical effect of the heart&#8217;s beating on my vasculature.  in other words, can I combine my electrical traces with physical traces? (Blood pressure or blood flow)  I found an interesting site that shows how someone built a <a href="http://www.phoenix.tc-ieee.org/004_Piezo_Film_Blood_Flow_Sensor/Phoenix_PiezoPulse.htm" onclick="javascript:urchinTracker ('/outbound/article/www.phoenix.tc-ieee.org');">DIY blood flow meter</a> using a piezo film pulse sensor.  Pretty clever I must say&#8230; but I think I draw my limit at what I&#8217;ve done. Although blood flow would be interesting to analyze (does the murmur depicted above produce an alteration in normal blood flow?), it&#8217;s not worth the time, hassle or expense of building.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.SWHarden.com/blog/2009-01-20-653-diy-ecg-detected-an-irregular-heartbeat/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
<!-- You've been  LOGGED!-->
    
    
<!--

LOG DETAILS:
date: 2010-03-11
time: 16:16:52
vistor: 38.107.191.84
method: GET
request: /blog/category/diy-ecg-home-made-electrocardiogram/feed/
protocol: HTTP/1.1
referrer: -
agent: CCBot/1.0 (+http://www.commoncrawl.org/bot.html)

HTML LOG LINE:
38.107.191.84 - - "GET /blog/category/diy-ecg-home-made-electrocardiogram/feed/ HTTP/1.1" 200 - "-" "CCBot/1.0 (+http://www.commoncrawl.org/bot.html)"

 -->

 