Figure 1: Board setup for ECG data collection
This lab consisted of two parts:
(1) Building a circuit using a dual op-amp and an instrumentation amplifier that could manipulate data coming from a person's body
(2) Interpreting the recorded data from the circuit using MATLAB code. MATLAB enables the user to visualize the data and make conclusions about ECG activity.
Figure 2: Schematic of final ECG amplifier circuit
Figure 3: A portion of the schematic in figure 2. This is the voltage follower segment of the circuit
This portion of the circuit creates a voltage follower that supplies a stready 2.5 V to the rest of the circuit. This is an important component because it provides a reference voltage to compare the ECG signals to. The voltage follower is also important because it prevents attenuation of the input signal by having a high input impedence and a low output inpedence. The LM358 chip provides a 2.5 V singal with a gain of unity (1) by effectively creating a voltage divider with the two 6.8 kOhm resistors.
Figure 4: A portion of the schematic in figure 2. This is the instrumentation amplifier within the circuit.
The AD623 chip is used as an instrumentation amplifier to amplify the voltage difference between the leads coming from the patient (positive lead to inverting input, negative lead to non-inverting input). This is helpful because for an ECG we want to focus on the difference in electrical activity between two points, not the electrical activity at one or two individual points. The difference between the two nodes is amplified with respect to the reference voltage and the signal proceeds to the bandpass filter.
Figure 5: A portion of the schematic in figure 2. This shows the low-pass and high-pass filters along with the voltage amplifier.
The voltage coming from the AD623 intrumentation amplifier first passes through the high-pass filter (Ci and Ri). The capacitor allows high-frequency signals to pass through with a cutoff frequency of 21.28 Hz. The signal then passes through the low-pass filter (Cf and Rf in series). The capacitor Cf forces low frequency signals to pass through the resistor in series, with a cutoff frequency of 174.07 Hz. The combination of the low- and high-pass filters effectively creates a bandpass filter, which allows the OP2 LM358 chip to amplify the cardiac signals we care about. Without the bandpass filter, interferences from contracting muscles, environmental noise, and baseline signal drift would prevent us from analyzing the ECG data. After the bandpass filter, the OP2 LM358 chip amplifies the voltage.
Figure 6: Bode plot of the band-pass filter showing the low-pass and high-pass frequencies. The combination of a low- and high-pass filter creates a bandpass filter that allows frequencies between 21.27Hz and 147.06Hz to pass through.
As part of the lab, we developed MATLAB code to parse through the output signals and determine if a spike in electrical activity could be counted as a heartbeat. First, the code reads the data from the csv file into MATLAB. A vector is created from the second column of data (which is voltage activity) and a "beats" variable is initialized to zero. Inside the forloop, the "beats" variable is incremented if certain criteria are met when the algorithm comes across a spike in voltage (spike exceeds threshold and is greater than surrounding peaks). The threshold criterion is set based off of observations of the graphs. After the total number of beats is counted, the program divides the number of beats by the number of minutes passed (beats/min) and prints the result to the screen.
data = csvread('4yoC.csv', 0, 3, [0, 3, 2499, 4]);
y = data(:,2);
threshold = 2.9;
beats = 0;
for j = 2:length(y)-1
if ((y(j) >= y(j+1)) && (y(j) > threshold) && (y(j) >= y(j-1)))
beats = beats+1;
end
end
y_scaled = data(55:2189,2);
Hz = 1000;
time_seconds = length(y_scaled)/Hz;
time_minutes = time_seconds/60;
Pulse = beats/time_minutes;
message = "BPM is: " + Pulse;
f = msgbox(message);