ECG Circuit

by mtredway02 in Circuits > Arduino

395 Views, 2 Favorites, 0 Comments

ECG Circuit

Screen Shot 2022-04-27 at 6.44.15 PM.png

Biosignal acquisition is a term that encompasses the medical procedures that read electrical or magnetic signals from the body to make a conclusion about its function. The most common examples are electroencephalograms (EEGs) which read electrical signals in the brain, electromyograms (EMGs) which read electrical signals in the muscles, and electrocardiograms (ECGs) which measure electrical signals in the heart [1]. The following procedures will focus on the function of the electrocardiogram.

An ECG records the electrical signals controlling the contraction and dilation of the heart. This system of electrical signals begins in the sinoatrial (SA) node and spreads throughout the heart muscle, causing contraction of the atria and ventricles in a specific sequence known as the cardiac cycle [2]. 

A normal electrocardiogram has a distinct five-wave pattern. These are called the P, Q, R, S, and T waves, and each wave corresponds to a specific electrical event in the heart.

The P wave shows the depolarization of the atria that causes the atria to contract. The Q, R, and S waves are typically referred to as one unit known as the QRS complex. This complex shows the ventricular depolarization that corresponds to ventricular contraction. The T wave represents repolarization of the ventricles. All of these electrical occurrences can be measured on the surface of the skin, making an ECG a noninvasive procedure. A standard 12-lead ECG involves six electrodes on the chest, then one on each forearm and calf [2]. Electrocardiograms are commonly used to diagnose heart attacks, arrhythmias, tachycardia, bradycardia, and aneurysms [3]. 


Cardiac electrophysiology is believed to have originated in 1842 when Dr. Carlo Matteucci detected electrical current through the heart of a frog with every beat [4]. Later, the first human electrocardiogram was published by British physiologist Augustus Waller [4]. This device used electrodes on the chest and back. Further improvements were made to the electrometer, and Dutch physiologist Dr. Willem Einthoven eventually produced a five-wave pattern which he dubbed the ABCDE waves [4]. After adjusting once more, the signal became the recognizable ECG pattern known today, which Einthoven renamed the PQRST waves. He coined the term “electrocardiogram” in 1893 [4]. Since then, continual adjustments have been made to improve signal accuracy, accessibility, and size of the device (Einthoven’s first ECG weighed six hundred pounds) [4].


The electrocardiogram has come very far since the 19th century. One example of an ECG on the market today is the Omni ECG C120, a 12-channel resting ECG device, which has a touch screen, a printer, and an “ultra high common mode rejection ratio to ensure clear and stable waveforms” [5]. It is built with low pass and baseline drift filters to further eliminate noise [5]. While this is most commonly used in hospital settings, there are also currently options for personal use. For example, the Eko DUO ECG + Digital Stethoscope is a $349 handheld ECG that connects to the user’s smartphone and can detect issues such as tachycardia, bradycardia, and arrhythmias, according to the manufacturer [6].


Like the Omni ECG, our electrocardiogram design will have a high common mode rejection ratio and several filters to remove noise from and amplify the signal. The following procedures will outline how this is tested and achieved.


[1] https://www.frontiersin.org/articles/10.3389/fcomp.2021.557608/full

[2] https://www.ncbi.nlm.nih.gov/books/NBK536878/

[3] https://medlineplus.gov/lab-tests/electrocardiogram/

[4] https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3714093/

[5] https://www.medicalexpo.com/prod/lepu-medical-technology/product-95737-1031916.html

[6] https://shop.ekohealth.com/products/duo-ecg-digital-stethoscope


Supplies

Agilent E3631A DC Power Supply

Agilent 33220A Function Generator

Agilent DSO6014A Oscilloscope

ECG Preamp (Grass ICP511)

ECG Electrodes

ArduinoCreateAgent

ArduinoBoardUno

Breadboard with connecting wires

4x LM741 Op Amp Chips

2x 510k resistor

2x 12k resistor

2x 22k resistor

1.8k resistor

2x 1.6k resistor

390k resistor

13.8k resistor

62.5k resistor

2x .1μF capacitor

.22μF capacitor

.01μF capacitor

.047 μF capacitor

BNC to BNC

t-adaptor

2x BNC to grabber

2x Alligator clips to power supply

Create LTspice Schematic of Instrumentation Amplifier

Screen Shot 2022-04-27 at 4.41.47 PM.png

The ECG is made up of three major components, an instrumentation amplifier, a notch filter, and a low-pass filter. In order to make troubleshooting easier, each component should be made and tested separately before combining. The first component of the ECG, the instrumentation amplifier, should amplify the ECG from 1 mV to 1 V, resulting in a gain of 1000. The formula used to calculate the instrumentation amplifier resistor values is:

Vout/ Vin2-Vin1=(1+2R2/R1)(R4/R3)

with Vout / Vin2 - Vin1 equating to 1000. The calculations show that R1 = 1.8 kΩ, R2 = 510 kΩ, R3 = 12 kΩ, and R4 = 22 kΩ. After calculating the resistor values, the values should be tested in LTspice to ensure an output voltage of 1 V is obtained.  

Create LTspice Schematic of Notch Filter

Screen Shot 2022-04-27 at 4.42.40 PM.png

The next component of the ECG is the notch filter. The notch filter should reject 60 Hz noise that often appears in ECGs due to power lines. The center frequency of the notch filter (in rad/sec) can be calculated by:

w0=2pi* 60Hz

The center frequency equates to 376.99 radians/seconds. For the notch filter, a quality factor of 8 was chosen and a capacitor value of .1μF was selected. Thus, the resistor values of the notch filter can be calculated.

R1=1/2Qw0C, R2=2Q/w0C, R3=R1R2/R1+R2

The resistor values for the notch filter are R1 = 1.6 kΩ, R2 = 390 kΩ, and R3 = 1.6 kΩ. The notch filter should be tested in LTspice with the calculated values to ensure that noise around 60 Hz is filtered out of the ECG.

Create LTspice Schematic of Low-pass Filter

Screen Shot 2022-04-27 at 4.43.25 PM.png

The last component of the ECG is a low pass filter. A typical ECG produces filters from 1-250Hz, so the low pass filter should have a cutoff frequency of 250Hz. The low pass filter should have a gain of 1, so there will be two resistors and two capacitors used. The equations used to find the capacitor values are as follows:

C1<=C2[a2+4b(K-1)]/4b, C2=10fc

with a = 1.414214, b = 1, and K = 1 (gain). C2 equates to .047 μF, and C1 equates to .01 μF. Once the capacitor values are found, the two resistor values can be calculated using the following set of equations:

R1=2c(aC2+a2(C22-4bC1C2)), R2=1bC1C2R1c2

R1 equates to 13.8 kΩ, and R2 equates to 62.5 kΩ. The low pass filter should be tested in LTspice to ensure that frequencies over 250 Hz are filtered out of the ECG.  


Combine LTspice Circuits

Screen Shot 2022-04-27 at 4.43.58 PM.png

Once each LTspice circuit is working, all three components should be put together and tested.  The results should show a combination of all three of the results from each separate component.



Build INA Stage

Screen Shot 2022-04-27 at 4.44.37 PM.png

First, build the INA on the far left side of the breadboard. Establish a rail for the positive Vcc input, negative Vcc input, and ground. These rails will be used for each component of the ECG. Start by placing three LM741 Op Amp Chips on the breadboard with three rails between each one. Pin 4 of each op amp should be connected to the negative rail and pin 7 of each op amp should be connected to the positive rail. The first op amp will represent the top op amp in the LTspice schematic. In pin 2, connect a 510k resistor. The end of the 510k should go to an empty rail. Then, connect the 510k resistor to a wire that connects to pin 6 of that same op amp. On the same node as the wire and 510k resistor, connect a 12k resistor that ends in pin 2 of the third op amp. Also on op amp one, connect a 1.8k resistor to pin 2 that ends at pin 2 of the second op amp. Connect pin 3 on the first op amp to the ground rail. For the second op amp, connect a 510k resistor to pin two that ends in an empty node. In that node, connect a wire that ends in pin 6 of the second op amp. In the same node as that wire and 510k resistor, connect a 12k resistor that ends in pin 3 of the third op amp. The second op amp should have a wire in pin 3 that will be connected to the Agilent 33220A Function Generator. In the third op amp, add a 22k resistor in pin 2 that will connect to pin 6. Also, add another 22k resistor in pin 3 that will connect to ground. Finally, add a wire in pin 6 that will connect to the Agilent DSO6014A Oscilloscope to display the output. The final circuit should look similar to the circuit shown in the figure.

Once the circuit is built, add a positive 15V input voltage to the positive input rail and a negative 15V input voltage to the negative input rail using the Agilent E3631A DC Power Supply. Connect the ground of the power supply to the ground rail. Then, set the function generator to display a sine wave with an amplitude of 1V and a frequency of 20mV. Connect the function generator to the oscilloscope using a t-adaptor with a BNC to BNC cable. In the other end of the t-adaptor, use a BNC to grabber cable to connect the positive end of the function generator to the wire in pin 3 of the second op amp, and connect the negative end of the function generator to ground. Finally, use a BNC to grabber cable to connect the oscilloscope to the output wire connected to pin 6 of the last op amp. The final result on the oscilloscope should show the input signal being amplified. Once the INA works properly, move on to the notch filter, but leave the INA on the breadboard for later use.




Build Notch Filter

Screen Shot 2022-04-27 at 4.45.32 PM.png

Referring to the LTspice schematic for the notch filter, the physical notch filter can be built. Leave space between the INA and notch filter to differentiate between the two phases of the ECG. First, place a wire in an empty node to be used as the input voltage. Then, connect a 1.6k resistor and a .1μF capacitor in the same node as the input voltage. The 1.6k resistor should end in a node with a .22μF capacitor and 390k resistor. The .22μF capacitor will be connected to ground. The 390k resistor will be connected to pin 3 of the LM741 Op Amp Chip. The .1μF will be connected to a node with a second 1.6k resistor and a second .1μF capacitor. The second 1.6k resistor will end in pin 6 of the op amp. The second .1μF capacitor will end in pin 3 of the op amp. A wire should be connected from pin 2 to pin 6 of the op amp. Pin 4 of the op amp should be connected to the negative rail and pin 7 of the op amp should be connected to the positive rail. In pin 6 of the op amp, add a wire to be used to measure the output signal. The final circuit should appear similar to the circuit shown in the figure.

After the circuit is built, test the notch filter by powering the op amp with +/-15V using the power supply. The notch filter should filter out noise around 60 Hz. Test this by setting the function generator to produce a sine wave with an amplitude of 1V and a frequency of 60Hz. Connect the positive end of the function generator to the wire in the node with the .1μF capacitor and 1.6k resistor. Connect the negative end of the function generator to the ground rail. Connect a BNC to grabber cable to the oscilloscope and the output of the notch filter. Collect data at frequencies around 60 Hz to ensure that the 60 Hz noise is filtered out successfully. If 60 Hz is not being filtered out, adjust resistor and capacitor values until 60 Hz is filtered out successfully.




Build a Low-pass Filter

Screen Shot 2022-04-27 at 4.46.26 PM.png

Lastly, on the far right end on the same breadboard, build the low pass filter. Refer to the LTspice schematic for the low-pass filter to build the circuit. First, place a wire in an open node for the input voltage. At that node connect a 13.8k resistor that will end in an open node. In that node, connect a .047μF capacitor and a 62.5k resistor. The .047μF capacitor will end in pin 6 of the op amp. The 62.5k resistor will end in an open node. In this node, connect a .01μF capacitor that will end in the ground rail. In the node with the 62.5k and the .01 μF capacitor add a wire that will end in pin 3 of the op amp. In pin 2 of the op amp connect a wire that will end in pin 6. Also in pin 6, add a wire that will be used to measure the output signal. Connect pin 7 of the op amp to the positive input rail and pin 4 of the op amp to the negative input rail. The final circuit should look similar to the circuit shown in the figure.

Once the circuit is built, connect the +/- 15V from the power supply to the appropriate rail. Set up the function generator to generate a sine wave with an amplitude of 1V and a frequency around 250 Hz. The low-pass filter should have a cutoff frequency of 250 Hz, so it should be tested at a number of frequencies lower than and higher than 250 Hz. Connect the function generator to the wire connected to the 13.8k resistor. Use a BNC to grabber cable to connect the oscilloscope to the wire in pin 6 of the op amp. Make sure that the results on the oscilloscope show that the low pass filter has a cutoff frequency around 250 Hz.




Test Full Circuit With Human Subject

Screen Shot 2022-04-27 at 4.46.59 PM.png

When each individual stage of the circuit is working properly, the full ECG circuit can be tested. To test the whole circuit together, remove the wire used as the input for the notch filter and connect the output wire of the INA circuit to this position. Then, remove the input wire from the low pass filter and connect the output wire of the notch filter to this position. The final circuit should resemble the circuit in the figure. Have the human subject place an electrode on the inside of each ankle and the inside of the right wrist. Connect the left ankle to the ECG as the positive input. Connect the right ankle and right wrist to the ground rail. Use 9V batteries to power the op amps or the power supply with an appropriate current limit. Connect the output of the low-pass filter to display on the oscilloscope. The oscilloscope should show a clear ECG signal.


Arduino Code

Screen Shot 2022-04-27 at 4.49.27 PM.png
Screen Shot 2022-04-27 at 4.49.36 PM.png

Once the signal is stable, the arduino portion can be completed. Make sure ArduinoCreateAgent is downloaded on the device being used. Obtain an ArduinoBoardUno and connect the board into the laptop. Make sure the port in the laptop is selected to the Arduino board. The code used for Arduino is shown in the figures. Use the preamp to amplify the ECG signal. Using the same electrode placements as earlier, connect the electrodes to the preamp. To set up the preamp, adjust the gain to 1000x, the low filter dial to 1Hz, the high filter dial to 0.3 kHz, and flip the line filter to ‘in’. Make sure the preamp is plugged in correctly. Connect the arduino board to ground and pin A0 to the output of the preamp using a grabber to grabber cable. Turn on the preamp and observe the results.