Introduction: ECG and Heart Rate Virtual User Interface

For this instructable, we will show you how to build a circuit to receive your heart beat and display it onto a virtual user interface (VUI) with a graphical output of your heartbeat and your heart rate. This requires a relatively simple combination of circuit components and the software LabView to analyze and output the data. 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.

Materials

Circuit:

LabView:

  • LabView software
  • DAQ board
  • Circuit wires
  • Isolated Analog Input
  • Function generator

Step 1: Determine What Filters and Amplifiers to Use

In order to represent an ECG signal, three different stages of the circuit were designed and implemented: an instrumentation amplifier, a notch filter, and a low-pass filter. The instrumentation amplifier amplifies the signal as when received from a subject is often very small and hard to see and analyze. The notch filter is used to remove noise at 60Hz because an ECG signal does not contain signals at 60Hz. Finally the low-pass filter removes higher frequencies to remove noise from the signal and in combination with the notch filter only allows in the frequencies that are represented in an ECG signal.

Step 2: Build Instrumentation Amplifier and Test It

The amplifier is required to have a gain of 1000 V/V and as it can be seen, the amplifier is made up of two stages. Therefore, the gain must be distributed evenly among the two stages, with K1 being the gain of the first stage and K2 being the gain of the second stage. We determined K1 to be 40 and K2 to be 25. These are acceptable values due to the fact that when multiplied together, a gain of 1000 V/V is obtained, 40 x 25 = 1000, and they are of comparable amount, with a variance of 15 V/V. Using these values for the gain, the proper resistances can then be computed. The following equations are used for these calculations:

Stage 1 Gain: K1 = 1 + 2R2R1 (1)

Stage 2 Gain: K2 = -R4R3 (2)

We arbitrarily picked a value of R1, in this case it was 1 kΩ, and then subsequently solved for the value of R2. Plugging in those previous values into the equation for the stage 1 gain, we get:

40 = 1 + 2R2*1000⇒R2 = 19,500 Ω

It is important to ensure that when choosing the resistances, they are in the kOhm range because of the rule of thumb that the larger the resistor is, the more power is can safely dissipate without suffering damage. If the resistance is too small and there is too large of a current, there will be damage to the resistor and furthermore the circuit itself will not be able to function. Following the same protocol for stage 2, we arbitrarily picked a value of R3, 1 kΩ, and then solved for R4. Plugging in the previous values into the equation for the stage 2 gain, we get: 25 = -R4*1000 ⇒R4= 25000 Ω

The negative sign is negated as resistances cannot be negative. Once you have these values, build the following circuit pictured. Then test it!

The Agilent E3631A DC Power Supply powers the operational amplifiers with an output of +15 V and -15 V going to pins 4 and 7. Set the function generator to output a Cardiac Waveform with a frequency of 1 kHz, a Vpp of 12.7 mV, and an offset of 0 V. This input should be to pin 3 of the operational amplifiers in the first stage of the circuit. The output of the amplifier, coming from pin 6 of the operational amplifier of the second stage, is displayed on channel 1 of the oscilloscope and the voltage peak-to-peak is measured and recorded. In order to ensure that the instrumentation amplifier has a gain of at least 1000 V/V, the voltage peak-to-peak should be at least 12.7 V.

Step 3: Build Notch Filter and Test It

The notch filter is required to remove 60 Hz noise from the biosignal. In addition to this requirement, because this filter does not need to include any further amplification, the quality factor is set to 1. As with the instrumentation amplifier, we first determined the values for R1, R2, R3, and C using the following design equations for a notch filter:
R1= 1/(2Q⍵0C)

R2= 2Q/(⍵0C)

R3= R1R/(2R1 + R2)

Q = ⍵0/β

β= ⍵c2 -⍵c1

Where Q = quality factor

⍵0= 2πf0= center frequency in rad/sec

f0= center frequency in Hz

β = bandwidth in rad/sec

⍵c1, ⍵c2= cutoff frequencies (rad/sec)

We arbitrarily picked a value of C, in this case it was 0.15 µF, and then subsequently solved for the value of R1. Plugging in the previous values listed of the quality factor, center frequency, and capacitance, we get:

R1= 1/(2(1)(2π60)(0.15x10-6))= 1105.25 Ω

As mentioned above when discussing the design of the instrumentation amplifier, it is still important to make sure that when solving for the resistances that they are in the kOhm range so no damage is done to the circuit. If when solving for the resistances, one is too small, a value should be altered, such as the capacitance, to ensure that this does not occur. Similarly to solving the equation for R1, R2 and R3can be solved:

R2= 2(1)/[(2π60)(0.15x10-6)]= 289.9 kΩ

R3= (1105.25)(289.9x103)/[(1105.25) + (289.9x103)]= 1095.84 Ω

Additionally, solve for the bandwidth in order to have it as a theoretical value to compare to the experimental value later:

1 = (2π60)/β⇒β = 47.12 rad/sec

Once you know the resistance values build circuit on the breadboard.

Only this stage of the circuit is to be tested at this point, so it should not be connected to the instrumentation amplifier. The Agilent E3631A DC Power Supply is used to power the operational amplifier with an output of +15 V and -15 V going to pins 4 and 7. The function generator is set to output a sinusoidal waveform with an initial frequency of 10 Hz, a Vpp of 1 V, and an offset of 0 V. The positive input should be connected to R1and the negative input should be connected to ground. The input should also be connected to channel 1 of the oscilloscope. The output of the notch filter, coming from pin 6 of the operational amplifier is displayed on channel 2 of the oscilloscope. An AC sweep is measured and recorded by varying the frequency from 10 Hz to 100 Hz. The frequency can be increased by increments of 10 Hz until reaching a frequency of 50. Then increments of 2 Hz are used until 59 Hz. Once 59 Hz is reached, increments of 0.1 Hz should be taken. Then, after 60 Hz is reached, the increments can once again be increased. The Vout/Vin ratio and phase angle is to be recorded. If the Vout/Vin ratio is not less than or equal to -20 dB at 60 Hz, the resistance values need to be altered to ensure this ratio. A frequency response plot and phase response plot is then constructed from this data. The frequency response should look like that in the graph, which proves that frequencies around 60Hz are removed, which is what you want!

Step 4: Build Low-pass Filter and Test It

The cutoff frequency of the low-pass filter is determined as 150 Hz. This value was chosen because you wantto retain all of the frequencies present in the ECG while removing the excess noise, specifically found at higher frequencies. The frequency of the T wave lies in the range from 0-10 Hz, the P wave in the range from 5-30 Hz, and the QRS complex in the range 8-50 Hz. However, abnormal ventricular conduction is characterized by higher frequencies, typically above 70 Hz. Therefore, 150 Hz was chosen as the cutoff frequency in order to ensure that we can capture all frequencies, even the higher frequencies, while cutting off high frequency noise. In addition to the 150 Hz cutoff frequency, the quality factor, K, is set to 1 because no further amplification is required. We first determined the values for R1,R2, R3, R4, C1, and C2 using the following design equations for a low-pass filter:

R1= 2/[⍵c[aC2+sqrt([a^2 + 4b(K -1)]C2^2 - 4bC1C2)]]

R2= 1/[bC1C2R1⍵c^2]

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

R4= K(R1+R2)

C2 about 10/fc uF

C1 < C2[a2 + 4b(K -1)]4b

Where K = gain

⍵c= cutoff frequency (rad/sec)

fc= cutoff frequency (Hz)

a = filter coefficient = 1.414214

b = filter coefficient = 1

Because the gain is 1, R3 is replaced by an open circuit and R4is replaced by a short circuit which makes it a voltage follower. Therefore, those values do not have to be solved. We first solved for the value of C2. Plugging in the previous values into that equation, we get:

C2 = 10/150 uF=0.047 uF

Then, C1 can be solved using the value of C2 .

C1 < (0.047x10^-6)[1.414214^2 + 4(1)(1 -1)]/4(1)

C1 < 0.024 uF= 0.022 uF

Once the capacitance values have been solved for, R1 and R2 can be computed as follows:

R1= 2(2π150)[(1.414214)(0.047x10-6)+([1.4142142 + 4(1)(1 -1)]0.047x10-6)2 - 4(1)(0.022x10-6)(0.047x10-6))] R1= 25486.92 Ω

R2= 1(1)(0.022x10-6)(0.047x10-6)(25486.92)(2π150)2= 42718.89 Ω

With the right resistances build the circuit seen in the circuit diagram.

This is the last stage of the overall design and should be built on the breadboard directly to the left of the notch filter with the output of the notch filter and the input voltage for the low-pass filter. This circuit is to be constructed using the same breadboard as previously, with the correctly computed resistances and capacitances, and one operational amplifier. Once the circuit is built using the circuit diagram in figure 3, it is tested. Only this stage is to be tested at this point, so it should not be connected to either the instrumentation amplifier or the notch filter. Therefore, the Agilent E3631A DC Power Supply is used to power the operational amplifier with an output of +15 and -15 V going to pins 4 and 7. The function generator is set to output a sinusoidal waveform with an initial frequency of 10 Hz, a Vpp of 1 V, and an offset of 0 V. The positive input should be connected to R1and the negative input should be connected to ground. The input should also be connected to channel 1 of the oscilloscope. The output of the notch filter, coming from pin 6 of the operational amplifier is displayed on channel 2 of the oscilloscope. An AC sweep is measured and recorded by varying the frequency from 10 Hz to 300 Hz. The frequency can be increased by 10 Hz increments until reaching the cutoff frequency of 150 Hz. Then, the frequency should be increased by 5 Hz until reaching 250 Hz. Higher increments of 10 Hz can be used to finish the sweep. The Vout/Vin ratio and phase angle is recorded. If the cutoff frequency is not 150 Hz, then the resistance values need to be altered to ensure this value is in fact the cutoff frequency. The frequency response plot should look like the picture where you can see that the cut-off frequency is around 150Hz.

Step 5: Combine All 3 Components and Simulate Electrocardiogram (ECG)

Connect all three stages by adding a wire between the last circuit component of the previous component to the beginning of the next component. The full circuit is seen in the diagram.

Using the function generator, simulate another ECG signal by If the components were built and connected successfully, your output on the oscilloscope should look like that in the picture.

Step 6: Setup DAQ Board

Above the DAQ board can be seen. Connect it to the back of the computer to power it up and place the Isolated Analog Input in channel 8 of the board (ACH 0/8). Insert two wires into the holes labelled ‘1’ and ‘2’ of the Isolated Analog Input. Set up the function generator to output an ECG signal of 1Hz with a Vpp of 500mV and an offset of 0V. Connect the output of the function generator to the wires placed in the Isolated Analog Input.

Step 7: Open LabView, Create a New Project and Setup the DAQ Assistant

Open the LabView software and create a new project and open a new VI under the file drop down menu. Right click on the page to open a component window. Search for ‘DAQ Assistant Input’ and drag it onto the screen. This will automatically pull up the first window.

Select Acquire Signals > Analog Input > Voltage. This will pull up the second window.

Select ai8 because you put your Isolated Analog Input in channel 8. Select Finish to pull up the last window.

Change the Acquisition Mode to Continuous Samples, the Samples to Read to 2k and the Rate to 1kHz. Then Select Run at the top of your window and an output like that seen above should show up. If the ECG signal is inverted, simply switch the connections from the function generator to the DAQ board around. This shows that you are successfully acquiring an ECG signal! (Yay!) Now you need to code it to analyze it!

Step 8: Code LabView to Analyze Components of ECG Signal and Calculate the Heartbeat

Use the symbols in the picture in LabView

You have already placed the DAQ Assistant. The DAQ Assistant takes the input signal, which is an analog voltage signal, either simulated by a function generator or received directly from a person hooked up to appropriately placed electrodes. It then takes this signal and runs it through an A/D converter with continuous sampling and parameters of 2000 samples to be read, a 1 kHz sampling rate and with max and min voltage values being 10V and -10V respectively. This acquired signal is then output on a graph so that it can be visually seen. It also takes this converted waveform and adds 5, to ensure it accounts for a negative offset and is then multiplied by 200 to make the peaks more distinct, larger and easier to analyze. It then determines the max and min value of the waveform within the given window of 2.5 seconds through the max/min operand. The max value calculated needs to be multiplied by a percentage that can be changed but is usually 90% (0.9). This value is then added to the min value and sent into the peak detect operand as the threshold. As a result every point of the waveform graph that exceeds this threshold is defined as a peak and saved as an array of peaks in the peak detector operator. This array of peaks is then sent to two different functions. One of these functions receives both the peak array and the waveform output by the max value operator. Within this function, dt, these two inputs are converted to a time value for each of the peaks. The second function consists of two index operators which take the location outputs of the peak detection function and indexes them separately to obtain the locations of the 0th peak and the 1st peak. The difference between these two locations is calculated by the minus operator and then multiplied by the time values obtained from the dt function. This outputs the period, or the time between two peaks in seconds. By definition, 60 divided by the period gives BPM. This value is then run through an absolute operand to make sure the output is always positive and is then rounded to the nearest whole number. This is the final step in calculating and finally outputting the heart rate onto the same screen as the waveform output. As the end this is what the block diagram should look like the first image.

After completing the block diagram, if you run the program you should get the output pictured.

Step 9: Combine the Circuit and the LabView Components and Hook Up to a Real Person

Now for the fun part! Combining your beautiful circuit and the LabView program to acquire a real ECG and calculate its heart rate. In order to modify the circuit to comply with a human and produce a viable signal, the gain of the instrumentation amplifier must be reduced to a gain of 100. This is due to the fact that when connected to a person, there is an offset which then saturates the operational amplifier. By lowering the gain, this will reduce this issue. First, the gain of the first stage of the instrumentation amplifier is altered to a gain of 4 so that the overall gain is 100. Then, using equation 1, R2is set to 19.5 kΩ, and R1is found as follows:

4 = 1 + 2(19,500)R1⇒R1= 13 kΩ Then, the instrumentation amplifier is modified by changing the resistance of R1to 13 kΩ as shown in step 2 on the previously built breadboard. The entire circuit is connected and the circuit can be tested using LabView. The Agilent E3631A DC Power Supply powers the operational amplifiers with an output of +15 V and -15 V going to pins 4 and 7. The ECG electrodes are connected to the subject with the positive lead (G1) going to the left ankle, the negative lead (G2) going to the right wrist, and the ground (COM) going to the right ankle. The human input should be to pin 3 of the operational amplifiers in the first stage of the circuit with the positive lead connected to pin 3 of the first operational amplifier and the negative lead connected to pin 3 of the second operational amplifier. The ground connects to the ground of the breadboard. The output of the amplifier, coming from pin 6 of the low-pass filter, is attached to the DAQ board. Be sure to be very still and quiet and you should get an output in LabView that looks similar to the one in the picture.

This signal is obviously far more noisy than the perfect signal simulated by the function generator. As a result your heart rate will jump around a lot but should fluctuate with a range of 60-90 BPM. And there you have it! A fun way of measuring our own heart rate by building a circuit and coding some software!