Creating an EKG Reader From Basic Components
by CC2015 in Circuits > Arduino
520 Views, 1 Favorites, 0 Comments
Creating an EKG Reader From Basic Components
Our team made an EKG reading circuit using resistors, operational amplifiers, capacitors, and an Arduino Uno R3 board. This circuit amplifies the wearer's raw EKG signals, filters out a 60Hz noise found from input impedance, and also filters out all signals above 135 Hz. The output of the circuit is then relayed to an Arduino that is connected to a computer to display output for BPM reading and plots the peaks viewed from the filtered EKG signal. This project is insightful as it provides a deep understanding of what each stage does and why this configuration was used.
Supplies
Among general supplies needed:
- Breadboards
- Agilent 33220A Function Generator
- Agilent DSO6014A Oscilloscope
- Agilent E3631A Power Supply
- Two 9V Batteries
- Arduino Uno R3 and respective connecting cables
- ECG Electrodes and respective connecting wires
- Operational Amplifiers (Op-Amps)
- Connecting wires
Number and type of resistors needed:
- One 180 Ω
- Two 820 Ω
- Two 470 Ω
- Two 82 kΩ
- Two 27kΩ
- Three 15 kΩ
Number and type of capacitors needed:
- One 0.22 μF
- Five 0.1 μF
Note: If some of the resistors or capacitors can't be found, use the equations featured in the photos for the "Supplies" section to form new resistor and capacitor values based on a gain of Vout/(Vin2-Vin1) = 1000 for the instrumentation amplifier. The cut-off frequency (fo) is equivalent to 60Hz. Lastly, the low-pass filter cuts out any frequencies above 125Hz.
Building the Instrumentation Amplifier
Build the circuit using the circuit schematic found in the figure above where R1 is 180 Ω, R2 is 820 Ω, R3 is 470 Ω, and R4 is 82 kΩ. After building the circuit, test the circuit by running a sine wave of 1mV into the input and connecting the output to the oscilloscope. Don't forget to connect the Op-Amps to 9V batteries, where the positive end of one 9V battery is connected to V+ and its negative end is connected to the ground, while the negative end of another 9V battery is connected to V- and its positive end is connected to ground. Connect the grounded components from the circuit into the Earth Ground of a Power Supply through connecting wires. Also use a cable splitter to connect the output of the function generator to the oscilloscope, so a comparison that shows that the output wave has been amplified by 1000 times is seen.
One of the figures featured in this section shows you the layout of the Op-Amp ports, this allows you to be able to build the figure found on the breadboard shown together with the figures.
Build the Notch Filter
Build the circuit using the circuit schematic found in the figure above where R1 is 27 kΩ, R2 is 27 kΩ, R3 is 15 kΩ, C is 0.1 μF, and 2C is 0.22 μF. After building the circuit, test the circuit by running a sine wave of 1V into the input and connecting the output to the oscilloscope. Don't forget to connect the Op-Amps to 9V batteries, where the positive end of one 9V battery is connected to V+ and its negative end is connected to the ground, while the negative end of another 9V battery is connected to V- and its positive end is connected to ground. Connect the grounded components from the circuit into the Earth Ground of a Power Supply through connecting wires. Also use a cable splitter to connect the output of the function generator to the oscilloscope, so a comparison can be seen where the voltage is reduced at 60Hz.
To further analyze the notch filter, you can test the circuit using inputs of different frequencies to show a frequency response plot by plotting the Voltage output by the circuit vs the frequency used in the input (Vout [V] vs Frequency [Hz]) in Microsoft Excel.
One of the figures featured in this section shows you the layout of the Op-Amp ports, this allows you to be able to build the figure found on the breadboard shown together with the figures.
Build the Lowpass Filter
Build the circuit using the circuit schematic found in the figure above with a gain of 1 in mind, where R1 is 15 kΩ, R2 is 15 kΩ, C1 is two 0.1 μF put in series to form a 0.05 μF, and C2 is 0.1 μF. After building the circuit, test the circuit by running a sine wave of 1V into the input and connecting the output to the oscilloscope. Don't forget to connect the Op-Amps to 9V batteries, where the positive end of one 9V battery is connected to V+ and its negative end is connected to the ground, while the negative end of another 9V battery is connected to V- and its positive end is connected to ground. Connect the grounded components from the circuit into the Earth Ground of a Power Supply through connecting wires. Also use a cable splitter to connect the output of the function generator to the oscilloscope, so a comparison can be seen where the voltage output is reduced at any frequency above 125Hz.
To further analyze the lowpass filter, you can test the circuit using inputs of different frequencies to show a frequency response plot by plotting the Voltage output by the circuit vs the frequency used in the input (Vout [V] vs Frequency [Hz]) in Microsoft Excel.
One of the figures featured in this section shows you the layout of the Op-Amp ports, this allows you to be able to build the figure found on the breadboard shown together with the figures.
Taking a Human EKG Signal
Now, take the three circuits you have built in Steps 1 to 3 and connect the output of the Instrumentation Amplifier (INA) to the input of the Notch Filter and the output of the Notch Filter to the input of the Lowpass Filter. This creates a circuit that amplifies the input signal from a raw human EKG by 1000, cuts off noise generated at specifically 60Hz, and cuts off any background noise that is about 125Hz.
Now, attach the electrode pads to a person, attaching one of them to the left wrist, right ankle, and left ankle of the person. The electrode attached to the left wrist will be connected to Vin1 and the electrode attached to the right ankle will be attached to Vin2. The grounded component will be connected to the electrode that is connected to the left ankle instead of the Earth Ground input of the Power Supply. The output of this entire circuit will still be connected to the oscilloscope.
Then, turn on the oscilloscope and view the resulting waveform, which should resemble a repeating PQRST waveform seen in one of the figures above in this section. If the resulting waveform is not seen, debugging the circuit at this point is ideal.
Debugging can be finding faulty components or finding errors in calculation fo the components used.
Hook It All Up to an Arduino
Instead of connecting the output to an oscilloscope, connect it to the Arduino board like in the figure above. The output will go to the A0 port on the Arduino and the grounding wire will go to the port labeled GND. This Arduino board will then be connected to your computer and be used to display the resulting waveform in the Arduino application on your computer.
Assuming you have already downloaded the software for Arduino onto your system,
copy the code below into your console.
###########################################
int UpperThreshold = 120; //Thresholding of where to read "beats" based on your signal input int LowerThreshold = 40; 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); } }
####################################
Verify and run the program onto the Arduino board. Go to "Tools" in the application and find "Serial Plotter" along with "Serial Monitor " under the taskbar. "Serial Plotter" allows you to plot out the resulting waveform output and "Serial Monitor" shows the BPM measurement the Arduino board is reading.
Do not forget to use a Baud Rate of 74880.
Results and End
The Figures above should show up or something similar to the figures provided here.
This signifies the waveform of the EKG wave and shows the capability of these basic components to form a decently functioning EKG reader.