The personal website of Scott W Harden

ECG Success!

⚠️ Check out my newer ECG designs:

I kept working on my DIY ECG machine (I had to change the values of some of the resisters) and it looks like I'm getting some valid signals! By recording the potential using my sound card (the microphone port seems to be a nice analog to digital converter that every PC has) I was able record my ECG with sound recording software, smooth it, and this is what it looks like.

This was based on a circuit I made using a single op-amp (A LM324 from RadioShack $1.49). The op-amp amplifies micro-potential generated by my heart and outputs it in a way that I can connect it to a microphone jack. The signal is very noisy though. I'm thinking about making the more advanced circuit (with 6 op-amps) to aim for a better signal-to-noise ratio, but first I'll try coding my way out of the noise...

DIY ECG Attempt 1: Failure

⚠️ Check out my newer ECG designs:

I followed-through on yesterday's post and actually tried to build an ECG machine. I had a very small amount of time to work on it, so instead of building the fancy circuit (with 6 band-pass filtered op-amps and diodes posted in the previous entry) I built the most crude circuit that would theoretically work.

I used just one of the 4 available op-amps from a LM324. I built this, hooked it up to my sound card, and made electrodes by soldering wires to pennies. After a good lick, I attached the pennies to my chest with tape and tried recording. Every time the pennies made contact with my skin, I would see noise on the trace, but I couldn't seem to isolate a strong heartbeat signal. This is what I saw and the circuit I build to see it:

Perhaps this project will be working soon. Many techno-savvy people have made these DIY ECG machines, but not many describe how to interpret the data. Since I'm planning on building it, testing it, recording ECG data, and processing/analyzing it, I'll may have something unique on the internet.

DIY ECG?

⚠️ Check out my newer ECG designs:

Last night my wife put her head on my chest while we were watching a movie. A minute or two later I felt a light sinking feeling in my upper chest, and my wife looked up at me in horror. "Your heart stopped beating!" I assured her that everything was okay (it quickly resumed), and that it happens all the time. I feel the sinking feeling often, know it's because my heart is briefly beating irregularly, and assume it's normal. After all, your heart isn't a robot, it's a living organ doing the best it can. It's never perfectly regular, and presumably everybody has momentary irregularities, they just don't notice them. When I got in bed I began wondering how regular irregular heartbeats are. What would the chances be that I have some kind of arrhythmia? I've had a checkup not too long ago by a family practice physician who used a stethoscope on my back to listen to my heartbeat, and he didn't notice anything. Then again, how often does a quick listen with a stethoscope detect subtle or occasional arrhythmias?

I know that whatever problem I have is likely too small to cause any serious troubles, but at the same time I'm becoming obsessed as to determining exactly what my problem is. How many times a day does my heart skip beats? What about nighttime? If only there were some way to record heartbeat data, then I could analyze it and determine the severity of my problem. But wait, data? That would be hours of heartbeat recordings... that means... YES! An idea for a DIY hardware that produces large amounts of data requiring the writing of data analysis software!

Naturally, my thoughts began to overwhelm my reality as soon as Python entered the scene. I wondered how I could use my PC to record my heartbeat, without spending much money on hardware, and only using software I write myself. I pondered this on the way to work this morning, and came up with two possible methods:

Method 1: acoustic recordings. This would be the easiest way to record my heartbeat. I could tape a stethoscope to my chest, insert a small microphone in the earpiece, connect the microphone to my PC, and record sound data for several hours. Theoretically it would work, but it would be highly prone to noise from breathing, and I would have to lay perfectly still to avoid noise caused by movements. The data (trace) would have to be smoothed, processed with a band-pass filter (to eliminate interference), and heartbeats could be calculated. However, this would only give me heart beat time information...

Method 2: electrical recordings. This would be a little more complicated, but generate much more information. I could record the electrical activity of my heart, and the charts would look like the cool electrocardiograms (ECGs) that you see on TV shows. I did a little Googling and found that similar things have been done before with common electrical components. I think I'm going to follow the guide on this page and build the circuit seen below:

Supposedly, the data I can obtain looks something like the image below. I'd attach 3 electrodes to my body (chest, arm, and leg), hook them up to my little circuit, then connect to circuit to my PCs sound card. I'd record the trace (maybe while I sleep?) and analyze it with Python/Numpy/Matplotlib. There are several websites which demonstrate how to build DIY ECG recording devices, but none of these seem to go into depth _analyzing _the data they obtain. Hopefully I could fill this little niche on the internet. We'll see what happens. I have my thesis to work on, and a whole bunch of other stuff on my plate right now.

UPDATE: I found an much simpler ECG circuit I can make from parts I already have at my house. It has tons of noise, but maybe I can filter that out somehow?

Fixing Slow Internet in Ubuntu

I recently swapped my two main PCs in my house. The "headless" (no monitor) media PC (whose job consists of downloading, storing, and playing movies) connected directly to my TV, and our standard desktop PC which my wife uses most of the time. I decided to do the swap because the media PC was way nicer than our desktop PC, and since the media PC is just playing movies and downloading torrents, I figured the extra processing power / ram / video acceleration could be put to better use. Anyhow, I decided (in both cases) to completely start fresh by wiping hard drives clean and reinstalling Ubuntu linux (I'm using 8.10 currently). However, after the installation I noticed a peculiar problem. I'll quote it to emphasize it...

Browsing the internet was very slow. When I'd click a link on a website, it would take several seconds before it seemed to even try to go to the next page. The same thing would happen if I manually typed-in a new website. I tried disabling IPv6 in firefox's about:config and in the /etc/init.d/aliases file, but it didn't help!

The solution for me was simple, and since I spent a lot of time searching forums I know I'm not the only one with this problem. Disabling IPv6 was suggested in 99% of similar posts. My solution took a while to uncover, so I figured I'd write it here. The basic problem is that my DHCP (auto-configured IP address) settings were screwed up, and my manually setting them I fixed the problem. Here's what I did...

Start by right-clicking your network icon (wireless in my case) and selecting connection information

Check out your current configuration. Is a local address (192.168.*.*) set for the primary DNS server? If so, that's your problem! Note your secondary server. We'll set it as your primary...

Continue by right-clicking your network icon (wireless in my case) and selecting edit connections*. Open the tab corresponding to your internet connection (wired or wireless - wireless in my case), select your connection, and click __Edit__

Use this screen to manually enter the information from the information screen you saw earlier, but making sure not to list any local IP addresses as the DNS servers. Save your settings, close the windows, and the problem should be immediately corrected. Leave "search domains" blank, that's important too. Good luck!!!

⚠️ Warning: This article is obsolete.
Articles typically receive this designation when the technology they describe is no longer relevant, code provided is later deemed to be of poor quality, or the topics discussed are better presented in future articles. Articles like this are retained for the sake of preservation, but their content should be critically assessed.

Compress Strings and Store to Files in Python

While writing code for my graduate research thesis I came across the need to lightly compress a huge and complex variable (a massive 3D data array) and store it in a text file for later retrieval. I decided to use the zlib compression library because it's open source and works pretty much on every platform. I ran into a snag for a while though, because whenever I loaded data from a text file it wouldn't properly decompress. I fixed this problem by adding the "rb" to the open line, forcing python to read the text file as binary data rather than ascii data. Below is my code, written in two functions to save/load compressed string data to/from files in Python.

import zlib  

def saveIt(data,fname):  
    data=str(data)  
    data=zlib.compress(data)  
    f=open(fname,'wb')  
    f.write(data)  
    f.close()  
    return  

def openIt(fname,evaluate=True):  
    f=open(fname,'rb')  
    data=f.read()  
    f.close()  
    data=zlib.decompress(data)  
    if evaluate: data=eval(data)  
    return data  

Oh yeah, don't forget the evaluate option in the openIt function. If set to True (default), the returned variable will be an evaluated object. For example, [[1,2],[3,4]] will be returned as an actual 2D list, not just a string. How convenient is that?

page 1, page 2, page 3, page 4, page 5, page 6, page 7, page 8, page 9, page 10, page 11, page 12, page 13, page 14, page 15, page 16, page 17, page 18, page 19, page 20, page 21, page 22, page 23, page 24, page 25, page 26, page 27, page 28, page 29, page 30, page 31, page 32, page 33, page 34, page 35, page 36, page 37, page 38, page 39, page 40, page 41, page 42, page 43, page 44, page 45, page 46, page 47, page 48, page 49
All Blog Posts