Introduction: Recording Bioelectric Signals: ECG and Heart Rate Monitor
NOTICE: This is not a medical device. This is for educational purposes only using simulated signals. If using this circuit for real ECG measurements, please ensure the circuit and the circuit-to-instrument connections are utilizing proper isolation techniques.
An electrocardiogram (ECG) is a test in which surface electrodes are placed on a subject in a specified manner to detect and measure the electrical activity of the subject’s heart . An ECG has many uses and can function to aid in diagnosis of heart conditions, stress tests, and observation while in surgery. An ECG can also detect changes in heart beats, arrhythmias, a heart attack, and many other experiences and diseases  also described in the problem statement above. The cardiac signal measured by an ECG produces three distinct waveforms that depict a live feed of the functioning heart.These are shown in the image above.
The objective of this project is to create a device that can obtain the ECG signal from an output generator or human and reproduce the signal while eliminating noise. The output of the system will also calculate the BPM.
Let's get started!
Step 1: Gather All Materials
In order to create this ECG, we will be creating a system that consists of two major parts, the circuit and the LabVIEW system. The purpose of the circuit is to make sure we are getting the signal that we want. There is a lot of ambient noise that can drown out our ECG signal, so we need to amplify our signal as well as filter out any noise. After the signal has been filtered and amplified through the circuit, we can send the refined signal to a LabVIEW program which will display the waveform as well as calculate the BPM. The following materials are necessary for this project:
-Resistor, capacitor, and operational amplifier (op-amps - UA741 were used) electrical components
-Solderless breadboard for building and testing
-DC power supply to provide power to op-amps
-Function generator to supply bioelectric signal
-Oscilloscope to view input signal
-DAQ board to convert signal from analog to digital
-LabVIEW software for observation of output signal
-BNC and variable end lead cables
Step 2: Designing the Circuit
As we just discussed, it is necessary to both filter and amplify our signal. In order to do this, we can set up 3 different stages of our circuit. First, we need to amplify our signal. This can be done by utilizing an instrumentation amplifier. In this way, our input signal can be seen much better in the final product. We need to then have a notch filter in series with this instrumentation amplifier. The notch filter will be used to eliminate the noise from our power source. After that, we can have a low pass filter. Since ECG readings are usually of low frequency, we want to cut off all frequencies that are at a frequency that is out of our ECG reading bounds, so we use a low pass filter. These stages are explained in more detail in the following steps.
If you are having trouble with your circuit, it is best to simulate your circuit in an online program. This way, you can check to see if your calculations for resistor and capacitor values are correct.
Step 3: Designing the Instrumentation Amplifier
To observe the bioelectric signal more efficiently, the signal needs to be amplified. For this project, to gain to achieve overall is 1000 V/V. To reach the specified gain from the instrumentation amplifier, resistance values for the circuit were calculated by the following equations:
(Stage 1) K1 = 1 + ((2 * R2) / R1)
(Stage 2) K2 = -R4 / R3
Where each of the stages are multiplied to calculate the overall gain. Resistor values chosen in order to create a gain of 1000 V/V are R1 = 10 kOhms, R2 = 150 kOhms, R3 = 10 kOhms, and R4 = 330 kOhms. Use the DC power supply to give a voltage range of +/- 15 V (keeping the current limit low) to power the op-amps of the physical circuit. If you are wanting to check true values of the resistors, or wanting to achieve this gain before building, you can simulate the circuit using a program like PSpice or CircuitLab online, or use an oscilloscope with a given input signal voltage and check for the true gain after building a physical amplifier. Connect the function generator and oscilloscope to the amplifier to run the circuit.
The photo above depicts what the circuit looks like in simulation software PSpice. To check that your circuit is working properly, supply a 1 kHz 10 mV peak-to-peak sine wave from the function generator, through the circuit, and to the oscilloscope. A 10 V peak-to-peak sine wave should be observed on the oscilloscope.
Step 4: Designing the Notch Filter
A specific problem when dealing with this circuit is the fact that a 60 Hz noise signal is produced by power supply lines in the United States. To remove this noise, the input signal into the circuit has to be filtered at 60 Hz, and what better way to do that than with a notch filter!
A notch filter (the circuit depicted above) is a certain type of electrical filter that can be used to remove a specific frequency from a signal. To remove the 60 Hz signal, we calculated the following equations:
R1 = 1 / (2 * Q * w * C)
R2 = (2 * Q) / (w * C)
R3 = (R1 * R2) / (R1 + R2)
Q = w / B
B = w2 - w1
Using a quality factor (Q) of 8 to design a decently accurate filter, a capacitance (C) of 0.033 uFarads for easier assembly, and a center frequency (w) of 2 * pi * 60 Hz. This successfully calculated values for the resistors R1 = 5.024 kOhms, R2 = 1.2861 MOhms, and R3 = 5.004 kOhms, and successfully created a filter to remove a 60 Hz frequency from the input bioelectric signal. If you are wanting to check the filter you can simulate the circuit using a program like PSpice or CircuitLab online, or use an oscilloscope with a given input signal voltage and check for the removed signal after building a physical amplifier. Connect the function generator and oscilloscope to the amplifier to run the circuit.
Performing an AC sweep with this circuit over a range of frequencies from 1 Hz to 1 kHz at a 1 V peak-to-peak signal should yield a “notch” type feature at 60 Hz in the output plot, which is removed from the input signal.
Step 5: Designing the Low Pass Filter
The final stage of the circuit is the low pass filter, specifically a Second Order Butterworth Low-pass filter. This is used to isolate our ECG signal. ECG waveforms are usually within the frequency bounds of 0 to ~100 Hz. So, we calculate our resistor and capacitor values based on the cutoff frequency of 100 Hz and an quality factor of 8, which would give us a relatively accurate filter.
C1 <= C2[a^2+4b(K-1)]/4b
The values that we calculated ended up being R1 = 81.723kOhms, R2 = 120.92kOHms, C1 = 0.1 microFarads, and C2 = 0.045 microFarads. Power the op-amps with a DC voltage of + and - 15V. If you are wanting to check the filter you can simulate the circuit using a program like PSpice or CircuitLab online, or use an oscilloscope with a given input signal voltage and check for the removed signal after building a physical amplifier. Connect the function generator and oscilloscope to the amplifier to run the circuit. At the cutoff frequency, you should see a magnitude of -3 dB. This indicates that your circuit is functioning correctly.
Step 6: Setting Up LabVIEW
Now that the circuit has been created, we want to be able to interpret our signal. To do this, we can utilize LabVIEW. A DAQ assistant can be used to acquire the signal from the circuit. After opening LabVIEW, set up the circuit as shown in the diagram above. The DAQ assistant will take this input reading from the circuit and the signal will go to the waveform graph. This will allow you to see the ECG waveform!
Next we want to calculate the BPM. The set up above will do this for you. The program functions by first taking the maximum values of the incoming ECG signal. The threshold value lets us detect all the new values that are coming in which reach a percentage of our maximum value (in this case, 90%). The locations of these values are then sent to the indexing array. Since indexing begins at 0, we want to take the 0th and 1st point and calculate the change in time between them. This gives us the time between beats. We then extrapolate that data to find the BPM. Specifically, this is done by multiplying the output from the dt element and the output of the subtraction between the two values in the indexing arrays, and then dividing by 60 (since we are converting to minutes).
Step 7: Connect It All and Test It Out!
Connect the circuit to the input of the DAQ board. Now the signal that you input will go through the circuit to the DAQ board and the LabVIEW program will output the waveform and the calculated BPM.
We have a be nice policy.
Please be positive and constructive.