Gas station without pumps

2014 June 3

EKG lab not quite done

Filed under: Circuits course — gasstationwithoutpumps @ 21:13
Tags: ,

Students came to lab prepared today! Only one of the five groups came to lab without a complete schematic and layout.  The other four groups all breadboarded their circuits and confirmed that they would work as designed (the only changes I suggested were changing from electrolytic capacitors to ceramic capacitors in the high-pass filter and perhaps lowering the corner frequency of the low-pass to remove more of the 60Hz noise—and I made those suggestions only after students had their circuits working).

One group had spent a lot of time debugging their circuit and not making any progress—they never saw anything except 2mV 60Hz noise.  I helped them debug and tracked down the problem fairly quickly: they had plugged their wires into the wrong set of headers on the KL25Z board, so were not delivering any power to the board.  I had not noticed this by looking at the wiring, but by trying to measure the power at the op amp and instrumentation amp, checking for loose wires on the breadboard.  When neither had power, I got suspicious and looked at the other end of the power wires.  Once power was delivered to the board, everything worked fine. (I made the same mistake this evening when I tried doing another recording at home, but it only took me a minute or two of wondering why I had no signal to realize my mistake.)

I wore EKG electrodes myself today, so that students having trouble getting a signal could check to see if their amplifiers worked with my electrodes (which I’d tested with my own board). A few students had problems with their electrodes, and confirmed that their amplifiers were working by using my electrodes, after which they managed to get their electrodes working.  I believe that 4 out of 5 groups managed to record signals from themselves, but no one got the soldering finished.

I’m going to suggest to groups that they might want to make EKG boards for both members of the team, so that they can take them home and demonstrate them to friends or relatives—it is a kind of cool thing to be able to make. It looks like I’m going to be missing the undergrad poster symposium on Thursday anyway, helping the group that came to lab unprepared today, so the students might as well have the opportunity to make another EKG to take home. (I’ll bring in some extra op-amp chips, if they need them, though there should be enough extras in all the kits, since I ordered enough for each student to work alone all quarter, if necessary.)

One student had an unusual EKG pattern in both leads I and II, but had had EKGs done professionally fairly recently and they found nothing wrong. I pointed the student to a simple book on EKGs (Ken Grauer’s A 1st Book on ECGs—2014) that I just had the library buy, for help in figuring out what the signals meant.

One thing I played with while they were putting their circuits together was doing digital filtering of the waveform to remove low frequency baseline drift and to reduce 60Hz noise.  I used scipy.signal.iirfilter and scipy.signal.filtfilt, pretty much as I did for looking at oscillometric blood pressure measurements.  The 60Hz noise was larger in the lab than at home (a lot more stuff plugged in), but didn’t really need to be filtered out:

Signal from EKG protoboard in the lab, with no digital filtering.

Signal from EKG protoboard in the lab, with no digital filtering. (sorry about the oversize bounding box: I’m not sure how to fix it and keep the grid square)

Same signal, filtered with bandpass 0.1Hz–88.2Hz followed by notch filter 57Hz—63Hz.  (5th order Bessel filters, applied forwards and backwards with filtfilt)

Same signal, filtered with bandpass 0.1Hz–88.2Hz followed by notch filter 57Hz—63Hz. (5th order Bessel filters, applied forwards and backwards with filtfilt)

The filtering cleans things up a little, but it is not worth the trouble of implementing the digital filters and giving them to the students. Of course, some of the students were getting a lot more 60Hz pick up than I was, perhaps because of their location in the room, perhaps because of higher gain (everyone ended up with gains between 1000 and 2000, though, so that probably isn’t the problem), perhaps coupled through their wiring (though people were pretty good about twisting their leads together).

Here is the quick-and-dirty script I used for filtering:

#!/usr/bin/env python2.7

from __future__ import print_function, division

import argparse
import sys
import numpy as np
from itertools import izip
import scipy
import scipy.signal

sampling_freq = 20	# if not read from input

for line in sys.stdin:
    if line.startswith('#'):
    	print (line.rstrip())
        if line.startswith('# Recording every'):
           # extract from input: # Recording every 0.05 sec (20.0 Hz)
           fields = line.split('(')
    fields = map(float, line.split())
    if len(fields)==2:

high_pass_cutoff = 0.1	# Hz
hp_over_Nyquist = high_pass_cutoff/(0.5*sampling_freq)

# low_pass_cutoff = 0.49*sampling_freq
low_pass_cutoff = min(100, 0.49*sampling_freq)
lp_over_Nyquist = low_pass_cutoff/(0.5*sampling_freq)

bess_b,bess_a = scipy.signal.iirfilter(5, 
filtered = scipy.signal.filtfilt(bess_b,bess_a,values)

mains_freq = 60.0 # Hz
if sampling_freq> 2*mains_freq:
    mains_over_Nyquist = mains_freq/(0.5*sampling_freq)

    bess_b,bess_a = scipy.signal.iirfilter(5, 
			Wn=[mains_over_Nyquist*0.95, mains_over_Nyquist*1.05],
    filtered = scipy.signal.filtfilt(bess_b,bess_a,filtered)

print("# Bessel bandpass filtered to {:.3g}Hz to {:.3g}Hz".format(high_pass_cutoff, low_pass_cutoff))
print("# followed by notch {:.3g}Hz -- {:.3g}Hz".format(mains_freq*0.95, mains_freq*1.05))

for t,n in izip(times,filtered):

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a free website or blog at

%d bloggers like this: