Projects Research & Design Hub

Small Signal Sampling

Figure 1 The heart is actually two pumps in one. The right side is responsible for pumping blood into the pulmonary circuit, which transports blood to the lungs, where it picks up oxygen and delivers carbon dioxide for exhalation. The pulmonary circuit then returns blood back to the left side of the heart. The left side is responsible for pumping blood to the systemic circuit, which transports oxygenated blood to virtually all the tissues of the body. The systemic circuit then returns deoxygenated blood and carbon dioxide to the right side [1].
Written by Jeff Bachiochi

In a Heartbeat

A small (3-electrode) heart rate monitoring system using the Sparkfun AD8232 Heart Monitor module is simple but effective in monitoring heart physiology.

  • How to make a small (3-electrode) heart rate monitor?

  • How does the human heart work?

  • What is an electrocardiogram (ECG)?

  • How to measure ECG?

  • How to take analog heart rate samples?

  • How are the electrodes placed?

  • What are the abnormalities in heart rhythms?

  • Sparkfun AD8232 Heart

  • Monitor module

  • Arduino MEGA 2560

  • Analog-to-digital converter (ADC)

I don’t have an Apple watch, but the one I wear does monitor heart rate and oxygen sensing. Since I enjoy running outside when the weather is comfortable, I thought it would be fun to monitor those parameters during my jaunts around Crystal Lake, where I live year round. I have to admit that right now I am on hiatus, while watching people out on the lake ice fishing. This season, as in the past, I find my weight rises a good (bad) 20 pounds from my normal summer weight. I don’t belong to a gym, and winter—along with the festive seasonal food—take a toll on my body every year.

I was disappointed to find that once I had worked up a sweat, my watch was not so effective in taking my vitals. Whodathunk! I’ve done projects in the past on recording brain waves, and know that the body has a lot of electrical activity going on inside, besides brain activity. One area I’ve not toyed with is heart monitoring. Non-laboratory-grade test equipment for personal use is becoming popular, and I see a future in which we all have some kind of equipment in our homes that can monitor body parameters and transmit them to a physician during a virtual house call.

In this month’s project, I make a small (3-electrode) heart rate monitor, using the Sparkfun AD8232 Heart Monitor module, which is based on the Analog Devices AD8232—a dedicated electrocardiogram front end.

HOUSE CALL

When I was a youngster, a doctor visited our home to diagnose illness and prescribe medicine. It didn’t take long for doctors to realize they could see more patients if the patients came to the doctor’s office. We are now beginning to see that evolve further into virtual visits. While this may or may not be a response to COVID-19, I believe it will quickly evolve into a powerful tool, if medical test equipment keeps up with this demand.

Any insight we can gain into how our bodies are functioning can be a step in the right direction. While any surgery has a potential for unexpected complications, the success rate continues to climb, as what were once unthinkable procedures are now all but routine. Getting a diagnosis has become a bigger factor than the operation itself. A life-saving operation can never succeed if the patient has not been diagnosed correctly.

One of the first things doctors do during a visit is listen to your heart. They can tell from the “lub-dub” heart sounds if its rhythm is consistent and within normal parameters. If anything sounds questionable they can order an electrocardiogram (ECG), which shows the electrical activity of the heart. Let’s take a quick look at how our ticker operates, before we look into measuring its activity.

— ADVERTISMENT—

Advertise Here

BIOLOGY

The heart is a hollow, muscular organ. Its interior is separated into left and right sides, each of which has an upper chamber (atrium) and lower chamber (ventricle). The atria receive blood from veins, and the ventricles pump blood into arteries (Figure 1).

Figure 1 The heart is actually two pumps in one. The right side is responsible for pumping blood into the pulmonary circuit, which transports blood to the lungs, where it picks up oxygen and delivers carbon dioxide for exhalation. The pulmonary circuit then returns blood back to the left side of the heart. The left side is responsible for pumping blood to the systemic circuit, which transports oxygenated blood to virtually all the tissues of the body. The systemic circuit then returns deoxygenated blood and carbon dioxide to the right side [1].
Figure 1
The heart is actually two pumps in one. The right side is responsible for pumping blood into the pulmonary circuit, which transports blood to the lungs, where it picks up oxygen and delivers carbon dioxide for exhalation. The pulmonary circuit then returns blood back to the left side of the heart. The left side is responsible for pumping blood to the systemic circuit, which transports oxygenated blood to virtually all the tissues of the body. The systemic circuit then returns deoxygenated blood and carbon dioxide to the right side [1].

If you’ve ever walked across the rug and touched a door knob you’ve probably gotten a little shock from the static electricity generated. When this happens your muscles twitch. Any kind of electrical shock can cause your muscles to contract. The heart’s cardiac muscle tissue, or myocardium, contains cells that expand and contract in response to electrical impulses. The heart actually receives small electrical impulses from pacemaker cells, located in the sinoatrial (SA) node in the right atrium.

A relaxed right atrium accepts oxygen-poor blood from the body. Meanwhile, its exit door, the tricuspid valve, is closed, preventing this blood from leaving. A heartbeat is the reaction of an electrical signal that contracts the right atrium, forcing the oxygen-poor blood to move through the open tricuspid valve into the right ventricle. During this time, the right ventricle is relaxed and its exit door, the pulmonary valve, is shut, preventing blood from leaving. Now the right atrium is relaxing and the tricuspid valve closes, keeping the blood in the right ventricle from going back into the right atrium. Finally, the pulmonary valve opens as the right ventricle contacts, forcing blood out of the heart and to the lungs, where it will be oxygenated.

A relaxed left atrium accepts oxygen-rich blood from the lungs. Meanwhile, its exit door, the mitral valve is closed, preventing this blood from leaving. The same electrical signal from the SA node contracts the left atrium, forcing the oxygen-rich blood to move through the mitral valve and into the left ventricle. During this time the left ventricle is relaxed and its exit door, the aortic valve, is shut, preventing blood from leaving the left ventricle. Now the left atrium is relaxing and the mitral valve closes, keeping the blood in the left ventricle from going back into the left atrium. Finally, the aortic valve opens as the left ventricle contracts, forcing blood out of the heart and to the whole body to distribute oxygen.

The “lub” is the sound of the atria contracting and the “dub” is the sound of the ventricles contracting. In its relaxed state, a muscle is polarized. The SA node excites both atria to the depolarized state, and the there is an exchange of sodium ions into a cell, causing a change in potential and muscle contraction. It is fascinating to see how a small nerve impulse can become a strong muscular force, but this is beyond the scope of this project. Feel free to delve more deeply into this phenomenon.

ELECTROCARDIOGRAM (ECG)

It is this polarization and depolarization of the heart muscle that can be measured on the skin’s surface, using an ECG. Infants can have heart rates of 80 to 130 beats per minute, whereas once you approach the age of 21 years, it has slowed a bit to 60 to 100 beats per minute. Realize that these are some rather wide ranges, and your actual heart rate will depend on other factors, such as your present physical activity, temperature and humidity level, emotional state, any medications that you take and the use of caffeine and nicotine.

An ECG shows much more than your heart rate. It can also show how efficiently your heart pumps blood, and since it is usually taken over some period of time, whether there are any irregularities in its pattern. When taken in a laboratory, it usually consists of 10 electrodes, six in a particular pattern across the chest area and four more on the extremities. This gives the clinician 12 calculated perspectives of the heart. It takes years of training to interpret the graphs that pour out of an ECG, an example of which is shown in Figure 2. Our project will use just three electrodes and give a single perspective.

I’ve chosen to use the Analog Devices AD8232 as the signal-gathering front end. This integrated signal conditioning block was designed specifically to obtain, amplify, and filter small biopotential signals, such as ECGs. It allows an external A/D converter (ADC) to sample the processed signal.

A simplified schematic diagram for the AD8232 is shown in Figure 3. This device runs on 2V to 3.5V, making it a good choice for battery-operated circuits. Since it runs on a single supply, a virtual reference ground must be created (A3). The Instrumentation Amplifier (IA) does the heavy lifting (signal amplification). Op-Amp A2 is used to create a driven electrode, which can be injected to help cancel the common-mode signal present at IA’s inputs. Output amplifier A1 not only buffers the output, but also can be used to add a low-pass filtering and gain. Op-Amps C1 and C2 are used to signal that a lead is not properly connected to the body. This can come in two varieties: DC detection—when using the third driven lead, LOD+ and LOD- are active; or AC detection—when using only two input leads only LOD+ is active.

— ADVERTISMENT—

Advertise Here

The Sparkfun AD8232 Heart Monitor module makes it simple to experiment with the AD8232, because it is a small, 4mm, 20-lead SMT part. Besides +3.3V and ground, four other connections are required from your micro. I used an Arduino MEGA for this project (Figure 4), and mounted the AD8232 module on a shield prototype board.

Figure 2 An electrocardiogram records the electrical signals in your heart. It’s a common and painless test used to quickly detect heart problems and monitor your heart’s health. Ten electrodes are required to produce a 12-lead ECG. A lead is a perspective of the electrical activity between particular electrodes [2].
Figure 2
An electrocardiogram records the electrical signals in your heart. It’s a common and painless test used to quickly detect heart problems and monitor your heart’s health. Ten electrodes are required to produce a 12-lead ECG. A lead is a perspective of the electrical activity between particular electrodes [2].
Figure 3 Simplified schematic of the inner workings of the AD8232, an integrated signal conditioning block for ECG and other biopotential measurement applications. It is designed to extract, amplify, and filter small biopotential signals in the presence of noisy conditions, such as those created by motion or remote electrode placement. The output signal is easily sampled by an external analog-to-digital converter (ADC) or an embedded microcontroller [3].
Figure 3
Simplified schematic of the inner workings of the AD8232, an integrated signal conditioning block for ECG and other biopotential measurement applications. It is designed to extract, amplify, and filter small biopotential signals in the presence of noisy conditions, such as those created by motion or remote electrode placement. The output signal is easily sampled by an external analog-to-digital converter (ADC) or an embedded microcontroller [3].
Figure 4 The Sparkfun AD8232 Heart Monitor is mounted on an Arduino proto shield mounted on my Arduino MEGA 2560 microcontroller. The red, blue, and black wires have adhesive electrodes attached. Best practice is to clean and dehair the area where you plan on placing the electrodes for the best contact possible.
Figure 4
The Sparkfun AD8232 Heart Monitor is mounted on an Arduino proto shield mounted on my Arduino MEGA 2560 microcontroller. The red, blue, and black wires have adhesive electrodes attached. Best practice is to clean and dehair the area where you plan on placing the electrodes for the best contact possible.
TAKING ANALOG SAMPLES

It’s not often that the code used for a project is as simple as this one. That’s because we only have one function to accomplish—sampling a single ADC channel. Arduino’s analog command will convert a specific channel from input voltage to a 10-bit integer that will indicate where the voltage falls between ground and Vcc (5.5V). Since the AD8232 has a maximum operating voltage less than 5.5V, we’re using 3.3V. You may wish to connect the Vref input to 3.3V. You can then instruct the MEGA to use this as the reference voltage via the command:

analogReference(EXTERNAL);

If you do this, you can increase the resolution from 5V / 1,024 = 0.0049V (4.9mV) to 3.3V / 1,024 = 0.0032V (3.2mV). So let’s get this code started (Listing 1).

Listing 1
This minimum Arduino sketch requires no libraries and uses just 3 pins, 2 digital inputs, and 1 analog input. The digital inputs detect a problem with the electrodes and cause an exclamation point to be sent out to the serial port. Otherwise, the voltage is read at the analog input, and its converted value is sent out to the serial port. A short delay of 10ms determines the sampling rate.

#define OUTPUT_Pin A0		// sample output pin
#define LO+_Pin 10		// leads off detection LO + output pin
#define LO-_Pin 11		// leads off detection LO - output pin
//
void setup()
{
 	// initialize the serial communication:
 	Serial.begin(115200);
 	pinMode(LO+_Pin, INPUT); 	// Setup for leads off detection LO +	
 	pinMode(LO-_Pin, INPUT); 	// Setup for leads off detection LO -
}
//
void loop()
{
 	if((digitalRead(LO+_Pin) == 1)||(digitalRead(LO-_Pin) == 1))	// if any open leads
 	{
  		Serial.println(‘!’);	// print error
 	}
 	else
 	{
  		// send the value of analog input 0:
  		Serial.println(analogRead(OUTPUT_Pin));	// print sample value
 	}
 	//Wait for a bit to keep serial data from saturating
 	delay(10);
}

You probably won’t enjoy the multitude of output values scrolling by, using the “Serial Monitor” display. But thanks to another tool in the Arduino “Tools” drop-down menu, you can have a much more meaningful view of the streaming data.

ELECTRODE PLACEMENT

If your doctor has ever scheduled an ECG for you, then you know the lengths the technician goes through to prep and clean all areas that will have electrodes placed on them. The body’s oils and even hair follicles interfere with the contact between the electrodes and the skin’s surface. Each electrode’s position has been carefully identified and placed according to strict specifications. With similar placement on every patient, output graphs will consistently contain the same information. This way, the professional interpreting the charts will know what to look for.

For this project, we will get one slice of the pie. With the limited number of electrodes, we will be seeing one point of view; however, it will be enough for you get a good idea of what is happening with the heart you will monitor. I’m not a guinea pig, but I’ll be playing one for this project.

You can purchase the module, a three-wire sensor cable and disposable electrodes from Sparkfun for around $35. The electrodes are disposable, because the electrode’s metal contact is surrounded with sticky foam. When you peel off the protective sheet, you expose the adhesive and a bit of electrode gel on the contact. Once it’s placed on the skin, the adhesive holds the gel-covered electrode against the skin for a firm bond. When removed, some of the gel remains on the body, and the adhesive becomes slightly contaminated. You may be able to reattach the protective sheet to the electrode, but the next time you want to use it, it may not stick as well, and there might not be enough get to make acceptable contact. A lab would never use these more than once. NOTE: You can get washable electrodes, electrode gel in quantity, and replacement adhesive pads. If you will be doing a lot of experimentation, this might be a reasonable consideration.

Figure 5 shows the placement of the three color-coded leads. You may already know that the body uses electrical impulses for many purposes. The brain is a plethora of electrical activity, the nervous system is constantly passing electrical information, and the heart’s sinus node doles out electrical signals to control heart rhythm. So, you shouldn’t be surprised to find that the best place to monitor activity is closest to the source. As electrodes are moved away from the source of interest, they can pick up other activity that adds to the signal of interest. Although some smart filtering can lower some interference, activity in the same frequency range can obfuscate your samples.

My first samples are shown in Figure 6. After look through a bit of noise, you can see a reoccurring pattern, but how does this relate to my heart activity? The first large spike begins around sample number 22550. The second large spike begins around sample number 22670. This is a difference of 120 samples. From the program, we see that samples are taken approximately every 10ms. 120 x 10ms = 1,200ms or 1.2 seconds. To find beats per minute (bpm), 1.2 sec per beat, 60/1.2=50 bpm. This only describes my heart rate. We have to examine the wave shape to determine other factors. I’m not going to try and diagnose my heart’s condition but let’s at least see how this ECG chart relates to the heart’s pumping progress.

A heartbeat actually begins before the large spikes. The process can be described by dividing the actions into time periods. Figure 7 shows how the heart’s electrical activity can be broken down into the progress of the SA node’s impulse as it moves through the heart. Once the relaxed (depolarized) left and right atria are filled with blood from the body and the lungs, the SA node’s impulse causes these to contract or repolarize (P wave). After a short delay (time PR), the ventricles (QRS complex wave) receive and react to the impulse. They contract (repolarize), pushing the blood out of the heart to the body and lungs, while the atria are depolarizing. Shortly thereafter, both ventricles relax or depolarize (T wave). Every phase of the heart’s rhythm has been its own “normal” characteristics.

Figure 5 Suggested positioning of the three color-coded electrodes on a patient’s body. The areas should be cleaned and free from body hair before applying the electrodes.
Figure 5
Suggested positioning of the three color-coded electrodes on a patient’s body. The areas should be cleaned and free from body hair before applying the electrodes.
Figure 6 The current project’s first output graph. Arduino’s Serial Plotter is great for a fast look at your sampled data. The samples are taken about every 10ms. The period of one of my heartbeats seems to be about 120 samples or ~50bpm.
Figure 6
The current project’s first output graph. Arduino’s Serial Plotter is great for a fast look at your sampled data. The samples are taken about every 10ms. The period of one of my heartbeats seems to be about 120 samples or ~50bpm.
Figure 7 The relationship between the heart’s electrical activity, muscular activity, blood pressure, and volume. In the past, a stethoscope was the only way to determine heart health by listening to the heart sounds [4].
Figure 7
The relationship between the heart’s electrical activity, muscular activity, blood pressure, and volume. In the past, a stethoscope was the only way to determine heart health by listening to the heart sounds [4].

PR interval = 0.12 – 0.20 sec

QRS width = 0.08 – 0.12 sec

QT interval 0.35 – 0.43 sec

Note that even the maximum timings of this process do not add up to the heart rate. The heart rate consists of the PQRST function plus a delay or time of rest between beats.

— ADVERTISMENT—

Advertise Here

ARRHYTHMIAS

An electrocardiogram can point out abnormalities in a heart’s rhythm. They include any phase of the rhythm that is missing or falls outside of the normal parameters. Some abnormalities in heart rhythms are listed below [5].

  • Atrial fibrillation, or AFib, occurs when many unstable electrical impulses misfire, and may result in the atria quivering out of control.
  • Atrial flutter (AFL) typically occurs in the right atrium. However, it may occur in the left atrium as well.
  • Bradycardia means you have a slow heart rate (less than 60bpm). Bradycardia generally occurs when the electrical signals traveling from the atria to the ventricles become disrupted.
  • Tachycardia means that your heart is beating too fast. For example, a normal heart beats 60 to 100 times per minute in adults. Tachycardia is any resting heart rate over 100bpm.
  • A premature contraction may be faint, early or extra, and may occur in the upper or lower heart chambers.
  • Ventricular fibrillation (VF) can stop the heart from beating and cause cardiac arrest. It occurs in the ventricles, which are unable to pump blood out of your heart to the body and brain due to the irregular heartbeat.

Nearly everyone will experience an abnormal heart rhythm from time to time, which might feel like your heart is racing or fluttering. Arrhythmias are common and usually harmless, but some are problematic. Since an arrhythmia interferes with blood flow to your body, it can damage your organs over time. Be safe and have this checked out by your physician.

Myocardial infarction, also known as a heart attack, is a life-threatening condition that occurs when blood flow to the heart muscle is abruptly cut off, causing tissue damage. This is not a heart rhythm problem because it is usually the result of a blockage in one or more of the coronary arteries. A blockage can develop due to a buildup of plaque, a substance mostly made of fat, cholesterol, and cellular waste products or due to a sudden blood clot that forms on the blockage. Since it interrupts the flow of blood to your heart, the heart can’t do its job.

PERIODIC ISSUES

Although an ECG is a quick and painless test, sometimes it doesn’t detect any changes in your heart rhythm because you’re hooked up to the machine for only a short time. A Holter monitor may be able to spot occasionally abnormal heart rhythms that an ECG missed, and may be used if you have a heart condition that increases your risk of an abnormal heart rhythm.

The Holter is actually a wearable electrocardiograph and recording device. It uses the same electrodes as an ECG, but allows you to go about your regular daily routine while it continually records data. Hopefully it will record some abnormal episode so a clinician can diagnose you correctly.

Some interesting animated examples of a normal beating heart and various arrhythmias are available online [6].

CONCLUSION

This project is an easy way to investigate your own heart rhythms for just a few dollars. Obviously, with a bit of intelligence, we could break down the ECG samples into their individual components and determine whether the data falls within predictable parameters. While today this is a job for a professional clinician, it won’t be long until AI allows a sample to be compared to a library of patient samples to accurately determine a diagnosis without further professional intervention.

I don’t want to lose the personal connection I have with my physician, but I feel there are tools right around the corner that can save time for them. We can’t afford to have good doctors and nurses leaving due to job burnout. Too much to learn, too little time. 

Additional materials from the author are available at:
www.circuitcellar.com/article-materials
References [1] to [6] as marked in the article can be found there.

RESOURCES
Analog Devices | www.analog.com
Arduino | www.arduino.cc
[1] Heart anatomy
https://www.texasheart.org/heart-health/heart-information-center/topics/heart-anatomy/
[2] Normal 12-Lead Electrocardiogram. https://commons.wikimedia.org/w/index.php?curid=77817932
[3] Analog Devices
Single-Lead, Heart Rate Monitor Front End – AD8232 Data Sheet
www.analog.com/media/en/technical-documentation/data-sheets/ad8232.pdf
[4] Heart Sounds and the Cardiac Cycle (Figure 19.3.3)
https://open.oregonstate.education/aandp/chapter/19-3-cardiac-cycle/
[5] Examples of cardiac arrhythmias.
https://www.healthline.com/health/arrhythmia#types
[6] Interactive Cardiovascular Library: Arrhythmias
https://watchlearnlive.heart.org/index.php?moduleSelect=arrhyt

PUBLISHED IN CIRCUIT CELLAR MAGAZINE • JUNE 2022 #383 – Get a PDF of the issue

Keep up-to-date with our FREE Weekly Newsletter!

Don't miss out on upcoming issues of Circuit Cellar.


Note: We’ve made the May 2020 issue of Circuit Cellar available as a free sample issue. In it, you’ll find a rich variety of the kinds of articles and information that exemplify a typical issue of the current magazine.

Would you like to write for Circuit Cellar? We are always accepting articles/posts from the technical community. Get in touch with us and let's discuss your ideas.

Sponsor this Article
Website | + posts

Jeff Bachiochi (pronounced BAH-key-AH-key) has been writing for Circuit Cellar since 1988. His background includes product design and manufacturing. You can reach him at: jeff.bachiochi@imaginethatnow.com or at: www.imaginethatnow.com.

Supporting Companies

Upcoming Events


Copyright © KCK Media Corp.
All Rights Reserved

Copyright © 2022 KCK Media Corp.

Small Signal Sampling

by Jeff Bachiochi time to read: 15 min