By Cameron King
Lab Partner: John Hobson
An electrocardiogram is a device that measures the electric signal from one's heart in order to detect problems and monitor the heart's condition [1]. The steps to build an ECG from basic circuit components are outlined below.
Figure 1: The final build of the ECG circuit is shown in the diagram above. The purpose of each operational amplifier is explained below. The circuit diagram was built using Circuit Lab [2].
The first step of building an electrocardiogram circuit is to build a voltage follower. The first operational amplifier, OA1, plays the role of a voltage follower in the ECG build. A voltage follower has unity gain, meaning that the input equals the output. The purpose of a voltage follower is to eliminate attenuation of the input signal.
The second step is to add an instrumental amplifier to the circuit to amplify the difference between skin voltages. Then this amplified voltage can easily be measured using an oscilloscope. The gain and amplification can be manipulated be changing the gain resistor, Rg. Decreasing the resistance of Rg will increase the gain and vice versa. In Figure 1, the instrumental amplifier is represented by OA2. the voltage divider in the form of R1 and R3 to reduce the voltage of the signal to undetectable levels.
Next, the combination of an active high-pass filter and an active low-pass filter is added to the circuit, creating a band-pass filter. Referring to Figure 1, the active low-pass filter is made from OA3, Rf, Cf, and Ri. The purpose of the low-pass filter is to filter out noise amplified by the instrumental amplifier. With the addition of Ci, the active high-pass component is added and a band-pass filter results. The purpose of the active high-pass filter is to prevent baseline drift of the ECG signal.
The last step is to setup the leads of the ECG, represented by VREF, V(+), and V(-) in Figure 1. The leads were connected to electrodes by alligator clips that will be placed on a patient. The electrodes corresponding to VREF, V(+), and V(-) were placed on the patient's inner right wrist, lower left bicep just above the elbow, and lower right bicep just above the elbow, respectively. It is important that all three electrodes have a strong connection with the skin to measure an accurate signal.
To calculate the total gain of the ECG circuit, first the gain of the individual amplifiers must be calculated. The formula for gain in an inverting op-amp or OA1 in Figure 1 is simply the input voltage over the output voltage. This calculation yields a gain of -21.28 for the first op-amp.
Next, the gain of an instrumental amplifier in the ECG circuit is calculated using the equation below.
Plugging in the value of Rg (2.2kO) from our circuit, a gain of 46.45 is obtained.
Multiplying this by the gain of the inverting op-amp gives the overall gain of the ECG circuit. The calculation is 46.45 x -21.28 = 988.55
To calculate the cutoff frequencies of the signal, the cutoff frequency of the active low-pass and high-pass filters must be found individually. The equation for calculating the gain of the active low-pass filter is displayed below.
In this equation, Rf and Cf correspond to the components in Figure 1. Plugging in Rf = 100kO and Cf = 68nF into the equation yields a lower cutoff frequency of 21.25Hz.
Next, the cutoff frequency of the high-pass filter is calculated using the following formula.
The Ri and Ci in the equation correspond to the circuit components before before OA3 in Figure 1. Plugging in Ri = 4.7kO and Ci = 10uF gives an upper cutoff frequency of 147.06 Hz.
Remember, the combination of these filters creates a band-pass filter in the ECG circuit, eliminating noise and baseline drift and creating a more accurate reading.
Figure 2: The bode plot of the ECG circuit is shown above.
The high-pass cutoff frequency (fc1) of the ECG signal is 21.28 Hz while the low-pass cutoff frequency (fc2) of the bode plot is 147.06 Hz. The cutoff frequencies correspond to -3dB attenuation from the total gain of the circuit. From the bode plot, it is evident that the combination of the active low-pass filter and the active high-pass filter create a band-pass filter that filters out both low and high frequencies.
Now that the ECG circuit is built, the next step is to calculate the pulse of the signal or the heartbeat. The pulse of a signal can be calculated in 10 easy steps, which are outlined below.
(1) aboveThresh = data_y (y-axis) > a value just below every peak in the ECG signal but not too low where it includes other parts of the signal
(2) d = diff(aboveThresh)
(3) d = abs(d)/2;
(4) beats = sum(d)
(5) N = length(data_y)
(6) seconds = N/fs
(7) minutes = seconds/60
(8) BPM = beats/minutes
(9) text_message = "BPM is: " + BPM
(10) f = msgbox(text_message)
(1) To measure the peaks in the signal or the beats, first the number of times the signal rises above a threshold voltage is found. The threshold voltage can be obtained by looking at the ECG signal. The value should be low enough to record every peak in a period but be high enough to leave out other parts of the signal. This step adds human error and if the pulse calculation algorithm gives unlikely results, this is where you should start troubleshooting. The aboveThresh calculation from (1) gives a vector for each data point where 0 indicates that data point was less than the threshold voltage and 1 indicates that the threshold voltage was reached.
(2) To simplify this vector to display a single 1 for each peak, the diff function is used. However, after performing this function, it was discovered that the resulting d vector had a 1 and a -1 for each heartbeat.
(3) For vector d to display a single 1 for every heartbeat, the absolute value of d divided by 2 must be calculated.
(4) The total number of heartbeats in the signal is calculated by summing the values in the d vector.
(5) The number of data points along the signal is calculated by finding the length of the data vector in the y-direction.
(6) The number of seconds is calculated by dividing the sampling frequency of the signal by the number of data points. The sampling frequency (fs) equals 1/ts where ts is the time interval of the sample.
(7) The minutes are calculated by dividing the seconds by 60.
(8) The beats per minute is now simply calculated by dividing the number of beats by the number of minutes.
(9), (10) The last two steps only output a display of the BPM. The BPM calculated in the prior steps is placed in a text message each time the code is run.
[1] Electrocardiogram (ECG or EKG). (2019, February 27). Retrieved April 1, 2020, from https://www.mayoclinic.org/tests-procedures/ekg/about/pac-20384983
[2] Online circuit simulator & schematic editor. (n.d.). Retrieved April 1, 2020, from https://www.circuitlab.com/