Gas station without pumps

2017 December 18

EKG without amplifier

Filed under: Circuits course,Data acquisition — gasstationwithoutpumps @ 18:24
Tags: , , , ,

I have done a lot of EKG projects on this blog, mostly for the Applied Electronics course, where an EKG amplifier is Lab 12, but some just for fun. Today I decided to see whether one could do an EKG with just the Teensy LC board or just an Analog Discovery 2 USB oscilloscope.

The project was partly inspired by the Digilent post DIY ECG using a Analog Discovery 2 and LabVIEW, which I saw the title for and assumed that they were using just the USB oscilloscope.  It turns out that wasn’t what they meant—it is just a simple 6-op-amp EKG amplifier looked at with the USB oscilloscope.

The setup I tried was about as simple as you can get—I put on three electrodes wired up as Lead I (see earlier post for this configuration), connected the body electrode to ground, and the other two electrodes to the plus and minus leads of channel 1 of the Analog Discovery 2.

The signal I got was quite small (about 1mV) and buried in 60Hz noise:

The raw signal from the oscilloscope, sampling at 1200 Hz, shows some spiking from the pulse, but a lot of noise. The big R spike is only about 3 LSB, so quantization noise is a problem.

I ran the recording through a digital filter to bandpass filter it to 0.1Hz–100Hz and put in a notch from 58Hz to 62Hz. The 100Hz low-pass had the effect of averaging out the noise, producing a signal with much finer resolution than the raw ADC values:

After filtering, the EKG signal is fairly clear. I don’t recommend trying to use only a couple of the lower-order bits of an ADC, but it is surprising how much information can be recovered by the filter.

I also tried using a Teensy LC board running PteroDAQ, using the A10–A11 differential channel. I had to bias my body between 0V and 3.3V, so I used a pair of 120kΩ resistors (one to GND, one to 3.3V) to connect to the body electrode.

Once again the raw signal was not great:

The signal had less noise than the signal to the Analog Discovery 2, but the signal was smaller also, negating the value of the finer steps of the ADC on the Teensy LC.

Once again, digital filtering restored the signal:

The signal-to-noise ratio here looks a little worse than for the Analog Discovery 2, despite the raw signal looking cleaner.

I managed to get a cleaner signal for the Analog Discovery 2 by turning off the surge protector, so that there was no 60Hz current anywhere nearby. The results after filtering were no better (and possibly worse) than from the signal with the 60Hz interference, so I did not bother plotting them for this post.

My conclusion is that it is possible to get EKG signals without adding an amplifier, but you can only see the signal clearly if you do some filtering.  I’ll have to decide whether to recommend to students that they record signals directly from the EKG electrodes to get an idea what their amplifiers have to work with.

Advertisements

2015 June 3

Crude theremin

On Monday I again had 2 lectures: one in Banana Slug Genomics on the Burrows-Wheeler Transform and FM index, and one in applied electronics finishing up the EKG preparation and starting into optional material.

The BWT and FM-index lecture was a bit rough though I had prepped on the material for a fair amount of time over the weekend.  I think that the written presentations I’d used to prep from (which included the Li and Durbin paper on BWA) were better than my lecture, so I ended up pointing the students to them as well, hoping that my lecture would at least make them more willing to click through and read the paper.

In the electronics class, I provided some feedback on the lab reports (reminding students once again how to figure out the DC bias resistor for an electret microphone).  Over the weekend I had finally caught up on the grading, so of course Monday saw a huge stack of redone work being turned in—I did the prelab grading Monday night, but I did not have the heart to start on the redone work last night or tonight.

After the feedback, and questions from the class on the EKG lab, I gave the EKG demo (which had worked fine before cycling up the hill).  Needless to say, it did not work when I hooked everything up in front of a live audience.  But I turned this into a teachable moment by explaining what I thought the problem was (bad electrode connections, because touching the reference wire produced a change in the output), and getting out three new electrodes, adding a a little electrode gel, sticking them on next to the ones I was already wearing, and moving the clips over.  Luckily, that was the problem, so I was able to demonstrate debugging, even with no lab equipment.

The EKG demo concluded the required material for the course, and so I asked students for suggestions on what I should cover next.  I suggested the electronics of the nanopore and nanopipette labs, and asked them for other ideas. One student wanted me to explain how theremins work, and a couple of others agreed that would be an interesting topic.  So I finished Monday’s lecture on the nanopore electronics (basically telling them it was just a transimpedance amplifier, but engineered for high gain and very low noise, and talking a bit about the copper boxes around the stations to reduce capacitive coupling), and told them I’d try to talk about theremins on Wednesday.

Tuesday’s lab went fairly smoothly, but I was kept busy helping students debug their designs—most often the problem was miswiring, but some students had electrodes that weren’t making good contact.  I had on a set of working electrodes, so that we could swap the leads to my electrodes to see if the problem was the electrodes or their boards.  A lot of the students had a lot more 60Hz noise pick up (even with my electrodes) than I was getting, and I could not always determine why. In some cases it was simply long wires on the breadboard.  They’ll be soldering up their EKGs on Thursday, and the wiring should be much more compact there.

Tuesday night I read up on a bunch of analog circuits relevant to Theremin design, and in today’s class I presented

  • a block diagram for a theremin (two oscillators—one with an antenna, a mixer, and a low-pass filter to pass only the difference frequency)
  • I showed them a rather crude theremin that they could implement from what they already knew: two relaxation oscillators using Schmitt triggers, an XOR gate, and an RC low-pass filter. (Only the XOR gate was new to them.)
  • I then talked about mixers, presenting a ring modulator (which they probably didn’t understand, as we’ve not done transformers except in passing), a simple two-resistors plus a diode non-linear mixer, and a synchronous decoder using a switch to change an op amp gain from +1 to –1.  I mentioned a couple of Wikipedia articles they could look up for other mixer designs (Gilbert Cell and frequency mixer).
  • I then introduced the notion of a sine-wave oscillator as a loop with gain exactly 1 and a phase change of 2πn for some integer n.
  • The first oscillator I showed them was a Wien oscillator using an op amp, for which I derived that at \omega RC = 1 the phase change of the positive feedback was 0 and the gain was 1/3, so we could set the positive gain to 3 to satisfy the requirements.  I mentioned the first Hewlett-Packard oscillator, and the trick of using an incandescent light bulb to control the gain and avoid clipping.  I showed them a plot of the amplitude and phase change for the feedback circuit, using gnuplot functions that they are familiar with from their own modeling.
  • Next I showed them an LC tank circuit, and derived the infinite impedance resonance \omega^2 LC = 1.
  • I then got to a Colpitts oscillator, showing them a possible circuit using an op amp, and how to model it as cascaded voltage dividers using gnuplot.  I showed them that the phase change of the feedback was 180° and that the phase change moved away from 180° very fast.  I was running out of time, so I briefly mentioned the Hartley oscillator and the Clapp oscillator, but didn’t really go into them.

On Friday, I plan to cover one-transistor amplifiers (common emitter with emitter degeneration and common collector—I probably won’t do common base), as those seem to be popular in theremin designs.

Tonight, since I was not willing to face grading, I decided to try out the crude relaxation oscillator Theremin.  Here is the circuit I ended up with (not including the bypass capacitors):

I used the potentiometer on the second oscillator to do crude pitch matching for the two oscillators, just looking at the period on an oscilloscope.  The emitter-follower amplifier was used to get enough current to drive the loudspeaker.

I used the potentiometer on the second oscillator to do crude pitch matching for the two oscillators, just looking at the period on an oscilloscope. The emitter-follower amplifier was used to get enough current to drive the loudspeaker.

The crude theremin only sort-of works.  I could get high-pitched theremin-like noises from it, but when the difference frequency dropped to 500Hz, the two oscillators phase-locked and the speaker went silent (often with very irritating on-off stuttering). The phase lock occurred even though the oscillators were on different chips at opposite ends of the breadboard, and I had 10µF ceramic bypass capacitors on each Schmitt trigger package and a 470µF electrolytic on the middle of the power bus.  Everything was powered to 5V with the USB power from my MacBook Pro.

I also often got 60Hz modulation of the signal, often as a on/off square wave, when the frequency difference was close to the point where the oscillators phase locked.

I’m not sure how the oscillators are getting coupled so that they phase lock when the difference frequency is small, so I’m not sure how to fix the problem.  The 60Hz sensitivity is almost inherent in the relaxation oscillator design, since the thresholds for the hysteresis on the Schmitt trigger remain fixed, but the hand near the antenna couples in 60Hz interference.  I suppose that over the summer I should try building a theremin with Colpitts oscillators or Clapp oscillators, to see if that works any better.

2015 May 29

Two lectures: Jellyfish and EKG

Filed under: Circuits course — gasstationwithoutpumps @ 20:01
Tags: , , ,

I gave two lectures today: the first in Banana Slug Genomics on the k-mer counting program Jellyfish, the second in my Applied Electronics course on 2-op-amp instrumentation amps and EKGs.

The Jellyfish lecture went reasonably smoothly.  I rather like the program, because it is very old school.  It uses clever bit-hacking techniques to minimize memory usage in a straight-forward hash-table approach to kmer counting, rather than sophisticated and inscrutable data structures. It also take advantage of the CAS instruction (compare and save) to do lock-free parallel updates to the hash table. It is a computer engineering solution to kmer counting, rather than a computer science one.

The electronics lecture also went fairly well. I presented the internals of the instrumentation amp that they have been using:

The 2-op-amp instrumentation amp has a fairly simple design that is easy to remember.

The 2-op-amp instrumentation amp has a fairly simple design that is easy to remember.

In class we derived the gain equation by using three ideas:

  • Negative feedback amplifiers keep the op-amp inputs at the same voltage, so V1=Vin+ and V3=Vin–.
  • Kirchhoff’s current law ensures that all the currents out of V1 sum to 0, and all the ones into V1 sum to 0.
  • R1=R4 and R2=R3.

We can write down the two current-law equations, and add them to cancel the terms involving V2.  That leaves us with an equation that can be rearranged to get the gain equation V_{out}-V_{ref} = R_{1}\left(1/R_{1} + 1/R_{2} + 2 R_{gain}\right).  The students will have to build their own instrumentation amp as part of the EKG circuit for next week’s lab.  They won’t be able to match the resistors as exactly as the INA126P’s laser-trimmed resistors, but their op-amps have higher input impedance and rail-to-rail output, so the resulting instrumentation will be fine for them.  They can’t use much gain in it anyway, since the input ±1mV EKG signal can have as much as 200–300mV DC bias, so that they can’t use a large gain in the first stage without risking saturation of the amplifier.

After the instrumentation amp, I talked a bit about action potentials and ion channels and tried to give them an idea of how a wave moving through the heart gives rise to a voltage dipole, which is what we actually measure.  I still don’t have a crystal-clear view of that in my head that I can present on a chalkboard.  Perhaps I should look around for a video to point the students to.

I had originally planned to demo the EKG in class today, so I put on electrodes after my morning shower, but I decided to test the EKG boards I had before going in to work, and none of them functioned.  Since all of them had worked in the past, I attributed this to a failure of the electrodes, but I had no time to debug in the morning.  When I got home, I decided to try to debug the circuit.  Needless to say, when I hooked up the leads to the electrodes, the circuit worked just fine:

With 480Hz sampling, a moderate amount of capacitively coupled 60Hz interference can be seen.

With 480Hz sampling, a moderate amount of capacitively coupled 60Hz interference can be seen.

A bandpass filter and pair of  notch filters remove the DC offset and most of the 60Hz and 120Hz interference.

A bandpass filter and pair of notch filters remove the DC offset and most of the 60Hz and 120Hz interference.

The only explanation that I’ve come up with (and the one my wife came up with without knowing any electronics), is that I was sweaty by the end of the day. If the electrodes had dried up a bit, then they might not have been very conductive. The sweat may have reduced my skin resistance and the resistance of the electrodes, giving a stronger signal (and a better Vref connection for the third electrode). I can anticipate this problem for Monday’s demo, by putting a dab of electrode gel on the electrodes before attaching them. The disposable electrodes aren’t supposed to need electrode gel, but it is a simple solution. I bought a tube of electrode gel earlier this year precisely in anticipation of needing it for dried-out electrodes.

2015 March 18

Freshman design projects moderately successful

I just finished grading this year’s freshman design projects. I think that the projects were more successful this year than last year, in part because I kept the students focussed on electronics and programming (for which they had lab access and which I could help them debug), and in part because the projects were somewhat less ambitious.

There were two groups doing EKGs and 4 groups doing blood pressure meters.  Both EKG groups managed to demonstrate their projects working, as did one of the blood-pressure groups.  (I’m being fairly generous here about what “working” means—they had to get their electronics to work, capture the data, and plot the waveforms, but further interpretation or software was not required.)  The other three blood pressure groups did not manage to demonstrate their projects, but one of them managed to plot waveforms for the pressure measurements (without getting their high-pass filter and amplifier working for the pulse measurements).

Some things I learned for next year:

  • Tell the students what op amp to get.  A number of students picked op amps that turned out to be rather old-fashioned ones with very low input impedance (as low as 2MΩ), rather limited output ranges, and external nulling circuits. The cheap MCP6002 or MCP6004 chips would have worked better at lower cost.  In fact, I gave one group that seemed to have a good schematic (but couldn’t get their circuit to work) an MCP6002 chip, which they wired in place of the op amp they had been using, and their circuit worked immediately.  I would have done the same for other groups, but the others with poorly chosen op amps were about a week behind and did not have circuits that were that close to being functional.
  • Warn students sooner not to use FedEx.  My son’s and my experience with FedEx this year has been that they are ludicrously slow. At least one group was burned by a ridiculously long delivery time, having ordered with FedEx delivery just hours before I warned the class about them.  (The US Post Office is faster and cheaper for lightweight electronics orders from Digi-Key.)
  • Students who never ask questions in class probably don’t understand much that is going on—all the groups that successfully demonstrated their projects had at least one active participant in class.
  • Students who fail to turn in their progress report are almost certainly not going to complete the project on time—I need to be more assertive in getting them moving and demanding that they show me their schematics.  Almost everyone had errors in their schematics on their first design (and one of the successful groups went through 4 incorrect designs before getting to one that worked).  Students that are afraid to show me incorrect or incomplete work don’t get the feedback they need to correct the problems—I need to normalize errors more and insist on seeing stuff, even if it is wrong.
  • The MXP5050DP pressure sensors are very easy for students to use, though a bit pricey at $16 each.  The built-in amplifier makes doing pressure measurements with an Arduino fairly trivial (hook up the three wires of the sensor to A0, +5V, and GND).  They were a good choice for the freshman design seminar, though I’ll continue to use MPX2053DP sensors without an integrated amplifier for the applied circuits class—that assignment is intended to get students to design with an instrumentation amp and to understand a bit about strain gauges.
  • Get the students to plot stuff earlier in the quarter. One group tried installing gnuplot on a Mac in the lab in the last few hours, which did not go well for them.  They did eventually find a plotting program that they could install and run, but then did not have time to run the data they collected through the filtering program I’d written for the class.  Their signals were pretty clean, though, and the plots they produced were good even with just the RC high-pass filter in their amplifier, without digital filtering.
  • The students seemed (for the most part) pretty excited about the projects—even those whose projects didn’t quite work seem to have gotten a lot out of the lab times.  I should look in a couple of years to see how many have stuck with engineering majors (I suspect that some might switch to computer science or computer engineering, rather than sticking with bioengineering, but that’s ok).

2014 July 18

How to sell a widget

SparkFun has a tutorial on how to sell “widgets” through them at How to Sell Your Widget on SparkFun – Learn.SFE:

Have an awesome electronic widget that you want to get to market? Great! We are always listening for new ideas from our customers and the community. We get many inquires on this topic, so read this tutorial carefully to keep your product pitch from getting lost in the shuffle.

We’re lucky, here at SparkFun, to have an amazingly creative and talented group of customers. Not only can they identify gaps in the catalogs of electronics suppliers, they can create a gizmo that fills that hole. But, going beyond a prototype or even a limited-quantity production run, often the hardest task in getting your world-altering product out there is producing, marketing, and/or selling it to the masses. That’s where we come into the picture.

The advice there is seems fairly reasonable.  They offer a choice of two models: make it yourself and have them sell for you, or have them make it and pay you royalties.  They tell you how to pitch products to them and how to design for them to be able to manufacture stuff.  Most of the stuff they sell is PCB boards, so they give quite a bit of advice about PCB design to fit their pipeline—they use Eagle, but ‘All parts are placed on a 0.005″ grid. If possible, use a .05″ grid.’ That must get irritating with modern parts that are convenient round metric numbers, not mils.   They also want version numbers in the bottom copper, which is reasonable for some designs, but not all.  They also encourage people to use their Eagle libraries, but my son and I have found their pad layouts to be very sloppy (putting silkscreen over SMD layers, getting the keep-out areas off by a little bit, not fixing the fonts on the “>NAME” and “>VALUE” labels to meet their own requirements, and so forth).

Still, it is good that they put out their design rules and provide clear guidelines to new designers.

I’ve thought a few times about putting out some of my designs through SparkFun or Adafruit Industries—perhaps an improved version of the blinky EKG as a kit.  SparkFun now sells EKG electrodes and snap leads for them, and even have a heart-rate monitor board (based on the AD8232 chip) and the “BITalino” biomedical board, so I suspect that they are interested in the market.

The BITalino is outrageously expensive and their EKG electrodes are about 3 times the price of buying them at Amazon, but the AD8232 chip actually looks like a nice one for building an EKG front-end and reasonably priced, so I’m not sure they’d have much interest in a through-hole part kit for do-it-yourself EKG that isn’t quite as good, unless it could be sold very cheaply or as an educational product (which is what the blinky EKG is aimed at, anyway).

I have some other ideas for products that I might be marketable, but I don’t know whether I have the time to refine them to the point of pitching them to SparkFun.  I can justify some time spent on doing electronics as a hobby, some as necessary learning for teaching my applied electronics course for bioengineers, and some as engineering-for-manufacture experience (something I never had any instruction in, despite my years as an engineering professor). But when the electronics work starts cutting into the time I need to spend on writing my book, teaching my classes, or doing collaborative research with other faculty, then I have to draw the line.  I’ve also got a lot of administrative responsibilities now (undergrad director and faculty adviser for two BS degrees, Program Chair for bioengineering, and Vice Chair for the Biomolecular Engineering Department), so writing time and research time have gotten doubly precious.

I do have one project this summer that I’m going to try to get fabricated for me—it is all SMD parts, including some that are hard to solder by hand (pads under the chips), so I don’t want to do it myself.  The project also calls for a lot of identical boards (20 to 50 of them), so a prototyping house seems like the way to go.

I’m looking currently at Smart Prototyping to do the PC board fabrication and assembly—they may not be the cheapest, but they have a comprehensible pricing scheme on their website, and they replied within 12 hours of my request for a quote. They also have a nearly turnkey system—I send them the Gerber files and the Bill of Materials (BOM), and they’ll make the boards, buy the parts, and assemble the boards.  They’ll even test them for an additional charge, though these boards are simple enough that I can test them myself at about 5 seconds a board, so their testing would not be worthwhile unless they guaranteed their assembly (which none of the prototype houses can afford to do with untested designs).

I also considered Elecrow, which has a similar service, but their pricing information on the web page is rather vague: “For BGA or IC with pads under IC, The quotation will be a little higher.” and “We will give a discount for the PCB assembly service according the some factors (assembly time,Hard or Easy to assemble or requirements etc.).” I prefer sites that have clear pricing even if it is slightly higher, so that there are no surprises. I suppose I could ask Elecrow for a quote and see if they respond as promptly as Smart Prototyping did.

Incidentally, my design does not follow all SparkFun’s guidelines—for one thing, I placed parts on a 0.5mm grid, not a 0.005″ gird, and the board is not rectangular.  Still, if the design I’m working on turns out well, I might pitch it to them, as I see some potential for it appealing to the open-source hardware market, and the violations of their design guidelines made good sense for this application.  Note: I’m deliberately not saying what the design is—I’ll reveal it once I’ve gotten a working prototype, when I’ve decided whether I want to commercialize it or not.

Next Page »

Blog at WordPress.com.

%d bloggers like this: