Designing an ECG: Extra Cool Gizmo

by ds105 in Circuits > Arduino

231 Views, 1 Favorites, 0 Comments

Designing an ECG: Extra Cool Gizmo

IMG_20220429_140415.jpg
Screenshot 2022-04-29 165204.png
Screenshot 2022-04-29 165235.png

Biosignals in general are any signal in living organisms that vary over time and can be monitored or measured quantitatively or qualitatively. Biolectrical signals are a subset of these and refer to the change in current from the potential difference across an organism’s tissue. This includes electrocardiograms (ECG) which measure the electrical activity of the heart. Electrocardiography can teach us about the structure and function of the heart in its failure modes and acts as a diagnostic tool for disease detection.

Exploration into the electrical activity of the heart and electrocardiography began around the 1840s. ECG is a method of measuring the changes in electrical activity of the heart over time throughout the cardiac cycle. The change in voltage over time measured by an ECG can be represented as an ECG waveform; segments of the waveform correspond to atrial and ventricular depolarization and repolarization.

ECG is measured by placing electrodes on the surface of the skin, typically in bipolar limb lead positions, and measuring the potential difference between the electrodes.

The device that we are creating is a physical circuit with three stages that is then integrated with an Arduino microcontroller to create digital output through analog/digital conversion. The first stage of the physical build is an instrumentation amplifier to amplify the biological signal to make it more easily detectable; this is important because the electrical activity from the heart is a relatively low-level signal and variations in the signal would be difficult to detect without amplification. The second stage is a notch filter with a notch frequency (bandstop) of roughly 60Hz in order to filter out the line-level noise from an outlet AC voltage, which typically has a frequency of 60Hz. The third stage is a low-pass filter to remove higher frequency noise that is unlikely to be part of the biological signal we want to measure; the expected ECG signals are roughly 1mV, so higher frequency signals are likely to be noise and can be removed in order to simplify the measured signal.

Types of ECG devices on the market today include resting ECG devices, stress ECG devices, implantable loop recorders, and smart wearable ECG monitors, among other types of devices. These devices can use up to 12 leads but 3-lead devices are most common, and resting ECG devices are also most common. There is an incredible diversity of companies producing ECG devices on the market, and some notable companies with devices for both personal and clinical use include GE Healthcare, Medtronic, and Philips Healthcare. Some examples include the MAC VU360 Resting ECG from GE Healthcare for clinical settings, the 1200HR High-Resolution stress ECG device from Norav Medical, the Reveal LINQ implantable loop recorder from Medtronic, and the Smart Wearable ECG Monitor from QardioCore.

Supplies

Necessary materials include LM471 operational amplifiers, DC power supply supplying +9V and -9V, 2 9V batteries, 3 ECG electrodes, breadboard, jumper wires, LTSpice software, oscilloscope, function generator, and alligator clips. We used the following resistance values (in Ohms) in our design: four 100k, two 1k, 1659, 22222, 424628, 1652.5, 16800, 26700. Smaller resistor values were sometimes combined in series to achieve the desired equivalent resistance. We also used the following capacitors (in microfarads) in our design: two 0.1, 0.03335, 0.0667.

System Flow Chart

Screenshot 2022-04-29 165330.png

This is a flow chart of the system.

Procedure

For the analog circuit, first built an instrumentation amplifier. Calculate the resistor values using a gain of 1000. Connect the op amps to a designated negative rail and a positive rail, and then pass -9V and +9V to the corresponding rail. Ground the circuit. To verify the instrumentation amplifier works, connect the input to the function generator and the output to the oscilloscope. Pass a sine wave through the circuit and verify that the output has a gain of 1000. Next, build a notch filter. Calculate the resistor values so that the center frequency is 60 Hz. Connect the op amps to the negative and positive rails and then pass -9V and +9V to the corresponding rail. Ground the circuit. To verify that the notch filter works, connect the input to the function generator and the output to the oscilloscope. Pass a signal through only the notch filter and verify that it’s attenuated at 60 Hz and nowhere else. Next, build a low pass filter. Calculate the resistor values so that the cut-off frequency is 150 Hz. Connect the op amps to the negative and positive rails and then pass -9V and +9V to the corresponding rail. Ground the circuit. To verify that the low-pass filter works, connect the input to the function generator and the output to the oscilloscope. Pass a signal through only the low-pass filter and verify that the cut-off frequency is 150 Hz. Finally connect the instrumentation amplifier to the notch filter, and the notch filter to the low-pass filter, and connect 9V batteries to the positive and negative rails. Make sure the circuit is grounded. Connect the input to electrodes attached to a person.

For A/D conversion, use either the oscilloscope or an Arduino board. For the oscilloscope, connect the output of the circuit to the oscilloscope and adjust the signal. The oscilloscope will display the electrocardiogram results. For the board, connect the output of the circuit to an Arduino board and ground the circuit on the Arduino board. Connect the board to a computer and upload the program to the board. This will allow the Arduino to output an electrocardiogram. 

To program the Arduino microcontroller, follow these steps. The full program that was run using the Arduino microcontroller can be found in the Appendix. Essentially, this program performed the following key steps in order to automate the plotting and BPM readout of the ECG signal from the human subject:

  1. Define constants and initial values including estimates for the upper and lower thresholds for determining the peak of the QRS complex. These values are estimated based on the signal input and tell the program what values to read as “beats.”
  2. Other values to initialize include the pin from which to read the input signal, the calculated BPM value, and booleans that determine whether there is currently a QRS peak and whether the first pulse has been detected.
  3. Setup function to set the baud rate or the rate at which measured data is stored. This can be thought of as the number of data points stored per second.
  4. Within a loop that runs indefinitely:
  5. If the reading is within the upper threshold, convert the first pulse time to milliseconds and detect the first pulse.
  6. Otherwise, convert the second pulse time to milliseconds, detect the second pulse, and calculate the pulse interval as the duration of the QRS complex (difference between first and second pulse time). Reset the first pulse time to be at the location at the second pulse time so that the next consecutive QRS complex can be detected.
  7. Calculate the BPM as follows: 

(1 / pulse interval in milliseconds) * 60 seconds per minute *1000 milliseconds per second

  1. Print the most recent BPM calculation to display in the serial monitor.
  2. Convert the analog reading to a voltage and display in the serial monitor.

Equations, Key Measures, Calculations

Instrumentation Amplifier

VoutVin2 - Vin1 = (1+ 2R2R1)(R4R3)

We chose to produce an overall gain (output voltage / input voltage) of 1000. We selected resistor values of R2 = 100k Ω, R3 = 1k Ω, and R4 = 100k Ω. Then we solved for R1.

1000 = (1+ 2* 100kΩR1)(100kΩ1kΩ)

R1 = 22222 Ω

Notch Filter

R1 = 12QoC

R2 = 2QoC

R3 = R1R2R1+R2

Q = o

= c2 - c1

The center frequency was fo = 60 Hz. This was the target for the center frequency because when you plug something into an outlet, the outlet has an AC voltage that fluctuates around roughly 50-60Hz. If the measurement device is not built correctly, the 50-60Hz signal can bleed into the physiological measurement. We use a notch filter to eliminate this range of frequency while retaining other frequencies. So, the center frequency in rad/sec was =2fo = 2(60 Hz) = 376.8 rad/sec. The quality factor Q was 8. We chose capacitor values of 0.1 μF. Using these values, we were able to solve for the resistor values.

R1 = 12QoC = 12*8 *376.8 rad/sec * 0.1 μF = 1659 Ω

R2 = 2QoC = 2* 8376.8 rad/sec * 0.1 μF = 424628 Ω

R3 = R1R2R1+R2 = 1659 Ω * 424628 Ω1659 Ω + 424628 Ω = 1652.5 Ω

C2 = 2C1 = 2 *  0.1 μF = 0.2 μF

Low-Pass Filter

R1 = 2c[aC2 + (a2+4b(K-1)C22-4bC1C2]

R2 = 1bC1C2R1c2

C1 C2[a2+4b(K-1)]4b

C2 = 10 / fc μF

We wanted a gain of K = 1, so R3 is replaced with an open circuit and R4 is replaced with a short circuit. The filter coefficients a and b were a = 1.414214 and b = 1. The cutoff frequency was 150 Hz, or =2fc = 2(150 Hz) = 942 rad/sec. 150 Hz was chosen as the cutoff frequency because the electrical signal we are trying to isolate from the heart is very low (~1mV or less), so filtering out higher frequencies from the incoming signal will help to eliminate frequencies that are not meaningful to us.

C2 = 10 / 150 Hz = 0.0667 μF

C1 C2[a2+4b(K-1)]4b 0.0667 μF[1.4142142+4*1(1-1)]4*1 = 0.03335 μF

R1 = 2942 rad/sec[1.414214 * 0.0667 μF + (1.4142142+4* 1(1-1)0.0667 μF2-4* 1 * 0.03335 μF *0.0667 μF] = 12861.5 Ω

R2 = 1bC1C2R1c2 = 11*0.0667 μF*0.03335 μF*12861.5 Ω*942 rad/sec2 = 39389 Ω

LTSpice Schematics for Analog Circuitry

Screenshot 2022-04-29 154729.png
Screenshot 2022-04-29 161647.png
Screenshot 2022-04-29 161713.png

The analog signal from the circuit was converted to a digital signal using an Arduino microcontroller. This allowed us to automate the plotting and BPM readout of the ECG signal instead of using the oscilloscope to visualize the voltage over time and manually calculate the BPM. From right to left are LTSpice schematics of the instrumentation amplifier, notch filer, and low-pass filter respectively.

A/D Conversion

The analog signal from the circuit was converted to a digital signal using an Arduino microcontroller. This allowed us to automate the plotting and BPM readout of the ECG signal instead of using the oscilloscope to visualize the voltage over time and manually calculate the BPM.

Potential Pitfalls

There are several potential pitfalls of this procedure. The electrode placement needs to be consistent between each placement and each trial of the experiment, and accurate as it needs to be positioned in the best location on the skin to measure the desired potential difference. The electrodes need to have optimal contact with the surface of the skin (without dust interfering or the adhesive drying out) and need to be pressed firmly against the skin. The subject should also be sitting and remaining still and relaxed in order to measure ECG at resting state. Electrical signals from skeletal muscle contraction could interfere with the electrical signal from the heart that we want to isolate. Our notch frequency for the notch filter was also slightly lower than the intended notch frequency (59.5Hz compared to 60Hz); this could have allowed slightly more line-level noise to pass through to the output signal than if we had created a notch filter with a notch frequency of 60Hz.