By Katherine Reiss
You may be familiar with an ECG machine from first hand experience, or maybe you have seen it featured in popular TV dramas such as Grey's Anatomy. I can recall a few episodes when the patient's electrical signal flatlines before miraculously showing some deviation after a few long and dramatic moments coupled with a faint "beep... beep... beep...." to break the silence. Back when I watched the show in high school, I knew what a flat line on this machine signified but always wondered what it really meant. After constructing an ECG from its fundamental components, it is evident how its internal workings are able to read and output information from the patient's body.
The human heart is an extremely strong organ. Think about it, a healthy heart never stops beating as long as that person lives. The heart works as a pump to circulate blood around the body. This circulation is induced with contraction and relaxation events of the muscle itself. These contractions are a result of electrical signals that begin at one side of the heart and travel to the other side. As the electrical signal travels, the muscles of the heart contract in a specific path, outlined in Figure 1, causing the chambers to release or accept blood.[1] This electrical signal is constantly fired off from pacemaker cells in the heart.[2] In some cases, the pacemaker cells in one's heart may not function properly. Luckily, with the use of modern technology, an artificial pacemaker can be inserted into the patient's chest in order to create the necessary electrical signal to contract the heart muscle at appropriate intervals of time. The heart functions by the means of electrical signals of a measurable voltage over a duration of time, which ultimately allows the use of Electrocardiography. Electricity travels through conductive material. Therefore, the conductive nature of human skin allows the signal to be read by electrodes attached to the skin. This interaction between the human body and the electrodes can be intensified with the use of conductive gel, which increases the ability of the electricity to travel from patient's skin to the electrode.[3]
Figure 1: Path of the electrical signals travelling through the heart[1]
Figure 2: Oscilloscope output of a 1mV peak-to-peak wave
Let's break down the word "Electrocardiography". "Electro-" implies electricity, "cardio-" suggests something about the heart (think cardiac arrest, or cardio exercises) and "-graphy" indicates the resulting plot of the changing voltage over time. In essence, an ECG machine just outlines the change of electrical signals in the heart, though this process is a little more complicated than attaching two probes of a digital multimeter to the electrodes of the patient's body. Despite the readability of the electrical signal, it is too small for us to physically see the deviation from the baseline on the monitor. Without any amplification, the signal has a voltage amplitude of about 0.5mV, or 1mV peak-to-peak. When this signal is viewed on the oscilloscope, it resembles something similar to the output in Figure 2.
Figure 3: Output with an inverting operational-amplifier
This being said, it is necessary to amplify the signal, that is to increase its output voltage. We are able to do this with the help of an inverting operational amplifier. The term inverting implies that the operational amplifer uses a negative feedback loop. In other words, it feeds the output back into the negative input pin. This negative feedback loop regulates the input voltage. Here, the input voltage is 2.5V. The inverting op-amp is important for an ECG because it keeps the input data at a steady 2.5V. We use this value as opposed to 0V so that we can see the voltage values dropping below the baseline. With this component included in the circuit, we get the output depicted in Figure 3. Though we are now able to see the deviation of the wave from the baseline, we can amplify the voltage even further to more clearly understand what is going on. In order to do so, we will add another operational amplifer to the circuit.
Figure 4: Output with two operational amplifiers
Figure 4 to the left shows the oscilloscope output when another operational amplifier is included in the circuit. The input voltage of these op-amps are able to be amplified by a ratio called the gain of the circuit. Different types of operational amplifiers have different gain equations. The first op-amp used for this circuit is the LM358. To find the voltage gain resulting from this circuit, the following equation is used.[4]
G = –Rf/Ri
The second op-amp in this circuit is the AD623. The equation used to find the voltage gain that resulted from this op-amp is below.[4]
G = 1 + (100 kΩ/RG)
The overall gain of the circuit is equal to the product of the gain from the first operational amplifier and the gain from the second. The calculated total gain for the circuit used in this project was found to be 988.46. This calculation is shown below.
G = –Rf/Ri
G = -(100kΩ/4.7kΩ) = -21.28
G = 1 + (100 kΩ/RG)
G = 1 + (100 kΩ/2.2 kΩ) = 46.45
Total Gain = -21.28 * 46.45 = -988.46
This means that the ratio between the voltage coming out of the circuit to the voltage coming into the circuit was 988.46:1. This extreme amplification of the voltage output is what allows us to view, interpret, and understand the data. There are a couple more components that must be added to the circuit to create a functional ECG. It is important to consider that the desired frequency of a wave might be affected by frequencies coming from interfering sources. To account for this, there are a couple additions we must make to the circuit. Low-pass and high-pass filters are assemblies of circuit components that result in the filtration of unwanted noise. While low-pass filters filter out high frequency noises, high-pass filters ensure that the circuit outputs steady data around the baseline.[5] Using both of these filters on the ECG circuit results in an undisturbed output of only the differential voltage received from the electrodes. Filtering out noise is especially important for an ECG filter because the purpose of the ECG is to identify the pattern of heartbeats, and interfering frequencies would alter this data. The calculations for the cut-off frequencies and the bode plot for the bandpass filter are shown below.
As the calculations and bode plot represent, the high and low pass filters of the circuit filter out frequencies below 2.13Hz and above 147.06Hz. This filtration ensures that the onlly frequencies affecting the data are those between these two values. Figure 5 below resembles the complete circuit used in this lab, before attaching the ECG electrodes.
Figure 5: Complete ECG circuit before replacing compenents with ECG electrodes
Once the construction of the circuit was complete, the creation of a program was necessary to transfer the data from the ECG output to a running list of BPM values detected from the patient's body. For this part of the project, electrodes were attached to three locations on the patient. One on the left arm, one on the right arm and one on the wrist. The wrist electrode enters the circuit through the reference pin on the AD623 op-amp while the arm electrodes enter the input pins of this op-amp. By using the wrist as a reference, the outputted data will show only the deviation caused by the heartbeat while ignoring other measurements that could be taken in the body relative to ground.[6] By connecting these electrodes to the patient's skin, the conductive nature of the skin and the electrodes themselves allowed for a reading to be executed. The data entering pin A0 on the Arduino was taken into the program code and upon the program's completion, the output on an LCD displayed the patient's BPM. The following pseudocode represents the steps taken to complete this code.
Include appropriate libraries: Wire.h and LiquidCrystal_I2C.h
Declare variables: AnalogValue, LiquidCrystal_I2C lcd(0x27,16,2), signal threshold, firstPulse, secondPulse, firstPulseTime, secondPulseTime, BPMVal, pulseInterval
void setup(){
Connection to serial
Connection to LCD (use 16, 2)
Initialize the LCD and begin backlight
}
void loop(){
Initialize the AnalogValue to read A0 input
if the AnalogValue is greater than threshold and the first pulse is not found yet (false)
then firstPulseTime = millis(),
firstPulse is now found (set to true)
delay of 0.025s (250ms) (so that the code waits until the next peak to measure the seconds)
else if the AnalogValue is greater than thresholdand and the first pulse is already found (true)
then secondPulseTime = millis(),
pulseInterval is equal to the difference between the pulse times,
firstPulseTime can now be equal to the secondPulseTime
secondPulse can be declared found (true)
if both pulses have been found (true)
then BPM = (1.0/pulseInterval) * 60.0 * 1000;
set the LCD cursor and print BPM values
print BPM values to Serial
set the pulses back to not found (false)
}
Essentially, the code above works by finding the millisecond value when the input is first greater than the threshold value (firstPulse). Then, the program delays and the next time it crosses the threshold, it measures the milliseconds again (secondPulse). Finally, the last loop will calculate the BPM of the patient by finding pulseInterval, the difference between the two pulse times, and running a calculation to convert this into beats per minute. This value is then displayed on the LCD and the Serial and the two pulses are set back to unfound (or false). Another way to display the BPM of the patient is to analyze the data after taking it. The pseudocode of the code that was run on MATLAB to find the BPM values after the data collection is shown below.
Read the data sheet
Initialize sampling rate (for this experiment ts = 0.001)
Initialize frequency
Define x and y variables inside the data
Use 'findpeaks' call to find the local maximums in the data set using a threshold
Loop through the indices of the peaks
Define pulse interval to be the difference in time between two of the peaks
Define BPM to be 60 divided by the pulse interval to convert to beats per minute instead of beats per seconds
Print the BPM values for each trial
One important factor to consider is the fundamental properties of a heart beat. There are multiple spikes in the electrical signal of a heart as displayed in Figure 6, the oscilloscope output with an arbitrary ECG signal created by a function generator.
Figure 6: Output of an arbitrary ECG signal from a function generator
As seen above, there is not just one spike that represents the heart beat. The heart creates several spikes due to the mechanics involved in the electrical pulse that results in the muscle contraction. In this project, we are looking to measure the BPM using information about the highest voltage in the ECG signal output. Therefore, we needed to create some threshold value so that the program could differentiate between finding the difference between the correct peaks, with ones that did not indicate the completion of a cycle. After this threshold was discovered, this gave us only one accurate value for the beats per minute. This value varied based on the breathing patterns of the patient as well as the amount of physical activity done by the patient at the time of taking the measurements. This was to be expected as the heart will need to circulate the blood faster when the body is active, and slower when the body is still and calm.
The final steps of this project were to analyze the data. Using MATLAB, we are able to break down the data to look for patterns or even to look at the cycle of just one heartbeat. Understanding how to interpret the ECG monitor is very important as deviations or abnormalities in the data can indicate an underlying health condition.
When connecting the electrodes to a person, three electrodes are used. The first electrode connects from the Reference pin on the AD623 to the person's wrist, the second electrode connects from the positive input of the AD623 to the right arm, and the third electrode connects from the negative input of the AD623 to the left arm. The following figure represent the ECG set-up with the electrodes connected (white wires).
Figure 7: ECG with electrodes attached
Three trials were run for this project. The ECG electrodes were connected to the subject's wrist. For the first trial, the subject sat still and her resting heartrate was measured. In the second trial, the subject held her breath. Finally, for the last trial, the subject did 100 jumping jacks and her heart rate was measured. The figures below show the change in heart rate when the subject is in all three trials. In the first, the resting heart is steady. In the second, when the subject held her breath, her BPM decreased while in the third, her BPM increased.
Figure 8: Resting heart rate
Figure 9: Heart rate when holding breath
Figure 10: Heart rate after exercise
Using the MATLAB pseudocode outlined previously, we can find the average BPM values. It is important to note that the oscilloscope output was not used as this data for this specific experiment, though it can be used. For this experiment, data analysis was run on Bridget Barsanti, a fellow classmate's data collection. Technical difficulties in the instrumentation prevented data collection with the arduino code and LCD monitor for the Arduino pictured in this article. Despite this, we can observe the output from Bridget's data below.
Average heart rate...
While resting: 80.7 BPM
While holding breath: 49.14 BPM
After exercise: 144.06 BPM
As seen by the oscilloscope output and the average BPM values, it is evident that the subjects' heart beats slowed down while holding their breath and spead up after exercising relative to their resting heart rate.
In building circuits, organization is very important. A project can become confusing and overwhelming very quickly, if the correct procedures are not followed.
Color-coding the wires on your breadboard will help you to keep everything in order. Using conventional color-codes will also help. For example, black may go to ground while red represents power. This makes it easy to follow the current flow in the circuit.
When building a circuit, I would recommend constructing it piece-by-piece. This will help when it comes to debugging or finding an issue that may come up in the circuit. In this particular project, there are many components and it can be really difficult to understand what went wrong, if it does not run properly.
Jumper wires can become very difficult to work with when there are too many involved in a small space. The solution to this could be to cut wires to a length that will sit level with the breadboard. That way, these wires will provide the connections without the hassle.
While it can be hard to memorize the different pins of the operational amplifiers, it is important to have a general idea of the function of each pin on this component. Understanding this will help to debug the circuit, as many times, the circuit will not work properly if even just one pin is out of place.
[1]“Heart Conduction System PI - UpToDate,” accessed October 29, 2020, https://sso.uptodate.com/contents/image?imageKey=PI%2F71235.
[2]“How the Heart Works | NHLBI, NIH,” accessed October 29, 2020, https://www.nhlbi.nih.gov/health-topics/how-heart-works.
[3]“What Is ECG and How Does It Work?,” imotions, accessed October 29, 2020, https://imotions.com/blog/what-is-ecg/.
[4]"EGR 311 Week 8 Lab B", accessed October 29, 2020
[5]"EGR 311 ECG PROJECT", accessed November 4, 2020
[6]“AD623.Pdf,” accessed November 1, 2020, http://users.ece.utexas.edu/~valvano/Datasheets/AD623.pdf.