Circuit for Human ECG to Improve Signal Quality

by viviennefranke in Circuits > Arduino

267 Views, 1 Favorites, 0 Comments

Circuit for Human ECG to Improve Signal Quality

IMG_3028.jpeg

We designed a circuit that would optimize the human ECG from the test subject though amplifications and filters. Additionally, using Arduino circuits and code we plotted the output and the automated BPM readout. We did this to achieve the optimal ECG output for reading by medical personnel.

Supplies

  • Breadboard
  • Resistors
  • 1k ohm (3)
  • 1.6k ohm (2)
  • 18k ohm (2)
  • 22k (2)
  • 27k (3)
  • 390k (1)
  • Capacitors
  • .1 µF (2)
  • .22 µF (1)
  • .068 µF (1)
  • .033 µF (1)
  • 741 Op Amp (5)
  • Lots of extra wires
  • Function Generator
  • Power Generator
  • Oscilloscope
  • Cables and adapters
  • BNC to BNC (1)
  • BNC to alligator clip (2)
  • BNC cable splitter
  • B&K cable with alligator clip (3)
  • Arduino to USB (1)
  • Power cable for ECG machine
  • Arduino circuit (1)
  • Computer (that can run Arduino)
  • ECG preamp
  • Leads
  • Electrode pads

Formation of Instrumentation Amplifier

Screen Shot 2022-04-29 at 10.30.49 AM.png
Screen Shot 2022-04-29 at 11.22.03 AM.png

We first started with the design of an instrumentation amplifier (INA) that fit the criteria needed for that of an ECG signal. According to Equation 1 shown below, we were able to calculate the necessary resistor values for each one used in the circuit. Because we wanted a gain of 1000, we set the ratio of Vout / Vin equal to 1000 and plugged in resistor values that satisfied this relation. We attempted to make the ratio of R1 and R2 as close as we could to the ratio of R3 and R4.


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

Equation 1. Finding resistor values for the INA circuit


After finding the correct values, the circuit was constructed in LTSpice, as shown above, to model the function of our circuit using the component values.


After testing that the circuit was working as expected using LTSpice, we then constructed the circuit on a breadboard. Some key aspects of the construction that allowed us to use the breadboard most efficiently were making each of the outside rows equal to Vin, Vout, and the ground. We used a power supply to our op amps of +/- 15 V throughout the course of all circuit builds. Our circuit construction can be seen above.


The circuit was then tested for its ability to amplify a test signal with a gain of 1000 using the function generator first. The positive end of the cable from the function generator was connected to the input node of the circuit and the negative end was connected to the row designated as the ground on the breadboard. 

Formation of Notch Filter

Screen Shot 2022-04-29 at 10.31.01 AM.png
Screen Shot 2022-04-29 at 11.21.32 AM.png

We next designed a notch filter to follow the INA in sequence. The goal was to have it pinpoint a signal of 60 Hz and eliminate only that frequency, as there is a large amount of noise at that frequency from the power supply. This was used as the center frequency when calculating for the necessary resistors using Equations 2-4 shown below. We also used a value of 8 for the quality factor and calculated using capacitor values we knew to be common in the lab.


R1 = 1/2QωC

Equation 2. Finding Resistor 1


R2 = 2Q/ωC

Equation 3. Finding Resistor 2


R3 = R1R2/(R1 + R2)

Equation 4. Finding Resistor 3



The LTSpice schematic that we used to model the outcomes of our circuit is shown above. We modeled the circuit design and inputted our calculated resistor values. 


After these were calculated, the circuit was built beside the INA on the breadboard while keeping the input from the INA separate for the time being. The circuit build can be seen above.


The filter was then tested on its own using a theoretical input from the function generator to test its effectiveness at eliminating a frequency of 60 Hz. The positive end of the cable from the function generator was connected to the input node of the filter and the negative end was connected to the universal ground row of the breadboard.

Formation of Low Pass Filter

Screen Shot 2022-04-29 at 10.31.14 AM.png
D6F06AC6-653B-4E98-BFCD-4D1DDAB3381A.png

Finally, we designed a low pass filter to be in sequence to the other two that would cut off any frequencies of the ECG signal greater than between 150-250 Hz, because this is the typical maximum frequency of the ECG signal when disregarding noise. We calculated the necessary resistors and capacitors needed for the circuit to meet this criteria. The values for a, b, and K within the equations were 1.414214, 1, and 1 respectively. Capacitor 2 was first decided using a resistor we knew would be available and the others were calculated using the equations below. The equations were used in the following respective order, as the previously calculated variables were used to find the others. 


C1 = C2((a2+4b)(K - 1))/4b

Equation 5. Formula to find Capacitor 1


R1 = 2/(ω(aC2 + sqrt(a2 + 4b(K - 1)C2^2 - 4bC1C2)))

Equation 6. Formula to find Resistor 1


R2 = 1/(bC1C2R1ω^2)

Equation 7. Formula to find Resistor 2


R3 = K(R1 + R2)/(K - 1)

Equation 8. Formula to find Resistor 3


R4 = K(R1 + R2)

Equation 9. Formula to find Resistor 4


Because we wanted a gain of 1, represented by the value of 1 for K, Resistor 3 was replaced with an open circuit and Resistor 4 was replaced by a short circuit. Using these assumptions and the calculated component values, we drafted an LTSpice schematic as shown above that could simulate the outcome of our circuit.


After our design was tested for accuracy, we built the circuit on the breadboard beside the notch filter, again not connecting the two in sequence quite yet. This circuit segment can be seen in the image above.


The physical circuit was tested to check that we were receiving the correct expected output using a theoretical signal from the function generator. We connected the positive end to the input node of the low pass filter and the negative end to the universal ground.

Testing All in Sequence With a Human ECG

Screen Shot 2022-04-29 at 10.54.21 AM.png

Once all of the three individual circuits had been verified to be successful with a simple signal of which it was easy to interpret results, we connected the three in series and prepared to test a human ECG signal through the system. We attached the leads to the right arm, right leg and left leg of the test subject as shown in the image above. The other end of the leads were connected using alligator clips to the necessary locations on the circuit for what the location on the body was representing. The corresponding locations on the test subject are shown in Table 1 below. 


Table 1. ECG setup with corresponding lead to circuit placement

Location on the test subject .......Where it attached on circuit

Left leg ..................................................Input 1

Right arm ..............................................Input 2

Right leg ................................................Ground


The input to the first circuit segment was the ECG signal from these three leads and the output end on the third circuit signal was leading to the oscilloscope after the signal had run through our circuit setup. When the test subject was sitting as still as possible, the power supply was turned on to power the op amps, and the signal was read through the oscilloscope in hopes of obtaining a smooth ECG signal through means of our circuit design.

Modifying and Testing Arduino Code

Screen Shot 2022-04-29 at 11.04.46 AM.png

Next, we tested a human ECG signal through Arduino code in an attempt to achieve a smooth signal. We left the same ECG setup on the test subject in place. However, we unattached the leads from the circuit. We instead obtained an ECG preamp and connected the leads to the machine according to Table 2 below.


Table 2. ECG setup with corresponding lead to preamp placement

Location on the test subject .....Where it attaches on the preamp converter

Left leg ...............................................G1

Right arm ...........................................G2

Right leg .............................................COM


An Arduino was also obtained, and we connected the positive and negative ends of the ECG preamp output onto the corresponding locations on the Arduino for the input and ground. We connected the input to A0 and the ground to COM, as shown in the image above. Using the given Arduino code, we ran the human ECG signal through the Arduino software and viewed the output graph on the computer. We then made any necessary modifications to the threshold values in the code and ran it over again until we obtained a clean plot of the ECG signal obtained from the subject.


We were also interested in a beats per minute (BPM) reading from the subject. This could be obtained by making further modifications to the code depending on the values contained within the QRS waves when the heartbeat would be measured. The version of code that allowed us to achieve both objectives can be seen below. 


int UpperThreshold = 60;  //Thresholding of where to read "beats" based on your signal input

  int LowerThreshold = 50;

  int reading = 0;

  int BPM = 0;

  bool IgnoreReading = false;

  bool FirstPulseDetected = false;

  unsigned long FirstPulseTime = 0;

  unsigned long SecondPulseTime = 0;

  unsigned long PulseInterval = 0;

  void setup(){

   Serial.begin(74880);

  }

  void loop(){

   reading = analogRead(A0); 

   // Heart beat leading edge detected.

   if(reading > UpperThreshold && IgnoreReading == false){

    if(FirstPulseDetected == false){

     FirstPulseTime = millis();

     FirstPulseDetected = true;

    }

    else{

     SecondPulseTime = millis();

     PulseInterval = SecondPulseTime - FirstPulseTime;

     FirstPulseTime = SecondPulseTime;

    }

    IgnoreReading = true;

   }

   // Heart beat trailing edge detected.

   if(reading < LowerThreshold && reading > 2){

    IgnoreReading = false;

   } 

   BPM = (1.0/PulseInterval) * 60.0 * 1000;

   //Serial.println(A0);

   Serial.print("BPM = ");

   Serial.println(BPM);

 delayMicroseconds(3900); 

 {

 // read the input on analog pin 0:

 int sensorValue = analogRead(A0);

 // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):

 float voltage = sensorValue;{

 // read the input on analog pin 0:

 //int sensorValue = analogRead(A0);

 // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):

 

 // print out the value you read:

 Serial.println(voltage);

};

 // print out the value you read:

 Serial.println(voltage);

}

  }