Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
test-and-measurement:analog-discovery-studio:ecg-demo:start [2022/09/12 19:56] – changed forum.digilentinc.com to forum.digilent.com, and some type-o's Jeffreytest-and-measurement:analog-discovery-studio:ecg-demo:start [2024/04/16 21:00] (current) – title case Arthur Brown
Line 1: Line 1:
 +====== DIY ECG with Analog Discovery Studio and LabVIEW ======
 +{{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:labview_in_use.png?nolink&600 |}}
 +**Note:** //This is NOT a medical device. Should be used for educational purposes only.//
 +----
  
 +===== Overview =====
 +<WRAP group>
 +This demo uses the Analog Discovery Studio's Oscilloscope to measure the natural electrical potential generated by the heart. As the measured signal is of very low amplitude, it first needs to be amplified with external circuitry, which can be built on the Breadboard Canvas and supplied from the Analog Discovery Studio Power Supplies. With the help of WaveForms VIs, the received data is sent to LabVIEW, where the postprocessing is done.
 +</WRAP>
 +----
 +
 +===== Inventory =====
 +=== Software ===
 +<WRAP group>
 +  * A computer with the latest version of [[software:waveforms:waveforms-3:start]] and [[https://www.ni.com/ro-ro/shop/labview/select-edition/labview-community-edition.html/|LabVIEW Community]] installed
 +  * WaveForms VIs (check this guide: [[test-and-measurement:guides:getting-started-with-labview]])
 +  * [[https://www.ni.com/en-us/support/downloads/software-products/download.labview-biomedical-toolkit.html|Biomedical Toolkit]] and [[https://www.ni.com/en-us/support/downloads/software-products/download.labview-advanced-signal-processing-toolkit.html#346230|Advanced Signal Processing Toolkit]]
 +  * {{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:ecg_vi.zip |ECG VI}}
 +</WRAP>
 +
 +=== Hardware ===
 +<WRAP group>
 +  * [[https://digilent.com/shop/analog-discovery-studio-a-portable-circuits-laboratory-for-every-student/|Analog Discovery Studio]] with Breadboard Canvas and MTE cables
 +  * Analog parts and wires (all found in the [[https://digilent.com/shop/analog-parts-kit-by-analog-devices-companion-parts-kit-for-the-analog-discovery/|Analog Parts Kit]])
 +    * 1 x [[https://www.analog.com/media/en/technical-documentation/data-sheets/OP282_482.pdf|OP 482 quad operational amplifier]]
 +    * 2 x [[https://www.vishay.com/docs/85622/1n914.pdf|1N914 diode]]
 +    * 1 x 47 nF capacitor (473)
 +    * 4 x 4.7 KΩ resistor (yellow-purple-red-gold)
 +    * 1 x 10 KΩ resistor (brown-black-orange-gold)
 +    * 2 x 20 KΩ resistor (red-black-orange-gold)
 +    * 3 x 100 KΩ resistor (brown-black-yellow-gold)
 +    * 1 x 150 KΩ resistor (brown-green-yellow-gold)
 +    * 2 x 470 KΩ resistor (yellow-purple-yellow-gold)
 +    * Jumper wires
 +  * 3 x Alligator clips
 +  * 3 x Surface electrodes
 +
 +**Note:** //The ECG design can still be viewed and run in software without all of the hardware, through the use of an imported data file. See //Testing Without External Circuitry//, in the [[#testing|Testing]] section, below.//
 +</WRAP>
 +----
 +
 +===== Setup and Use Instructions =====
 +
 +==== Circuit Setup ====
 +<WRAP group>
 +This section will go through each stage of the ECG circuit. There is a diagram of the completed circuit, as well as a wiring diagram made in Fritzing, at the last step, if you wish to skip to that step.
 +</WRAP>
 +
 +<WRAP group>
 +=== Building the Amplifier Circuit ===
 +<WRAP column half>
 +The amplitude of the potential difference on the skin is just in the millivolt or microvolt range, so it has to be amplified. To amplify the signal an instrumentation amplifier is built using OP482. The gain is set to 500 (A = (1 + 2 * R2/R1) * R3/R4). The **+** input should be connected to the right leg, above the ankle, the **-** input to the right hand, on the wrist. Between the surface electrodes and the inputs of the instrumentation amplifier 100 kΩ resistors are connected to limit any current circulating towards the body (in case of faulty operation).
 +</WRAP><WRAP column half>
 +{{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:amplifier_standard_schem.png?600 |}}
 +</WRAP></WRAP>
 +<WRAP group><WRAP column half>
 +The output of the amplifier can be visualized with the help of the //Oscilloscope// instrument in WaveForms.
 +</WRAP><WRAP column half>
 +{{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:amplified.png?600 |}}
 +</WRAP></WRAP>
 +
 +<WRAP group>
 +=== Filtering Out the Common Mode Signal ===
 +<WRAP column half>
 +It can be seen, that the measured signal is too noisy, the heart signal can't be recognized. To correct this, the common mode signal from the output of the first amplifier stage is amplified and inverted using the fourth operational amplifier in OP 482 (A = - R6/R5). The amplified and inverted common mode signal (**G**) is connected to a current limiting resistor, then to the left wrist. Two antiparallel diodes are connected between the **G** surface electrode and the device's ground to limit the signal between around -0.6 V and +0.6 V, to prevent electrocution.
 +</WRAP><WRAP column half>
 +{{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:feedback_standard_schem.png?600 |}}
 +</WRAP></WRAP>
 +<WRAP group><WRAP column half>
 +The signal becomes periodic and less noisy, but it has a large offset.
 +</WRAP><WRAP column half>
 +{{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:filtered.png?600 |}}
 +</WRAP></WRAP>
 +
 +<WRAP group>
 +=== Eliminating the DC Component ===
 +<WRAP column half>
 +The offset of the signal can be easily eliminated using a small decoupling capacitor between the output of the instrumentation amplifier and the oscilloscope probe.
 +</WRAP><WRAP column half>
 +{{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:decoupling_standard_schem.png?600 |}}
 +</WRAP></WRAP>
 +<WRAP group><WRAP column half>
 +On the power spectrum of the signal the DC component disappears. As the 50 Hz sine signal from the mains can be found on the skin, high power spectral components appear at multiples of 50 Hz. However, these can be eliminated easier using high order digital filters in LabVIEW, than with analog filters.
 +</WRAP><WRAP column half>
 +{{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:decoupled.png?600 |}}
 +</WRAP></WRAP>
 +
 +<WRAP group>
 +=== Wiring diagram in Fritzing ===
 +<WRAP column half>
 +In the picture to the right, the wiring diagram of the same circuit is presented, but built in Fritzing, in case that is easier to follow.
 +</WRAP><WRAP column half>
 +{{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:breadboard.png?600 |}}
 +</WRAP></WRAP>
 +----
 +
 +==== User Interface ====
 +<WRAP group><WRAP column half>
 +Download, unzip and open the ECG VI attached at [[#inventory|Inventory]]. On the front panel, to control the data acquisition and the post-processing, four elements are available: a drop-down list for selecting the Oscilloscope channel, an input field for entering the number of seconds for which data is acquired, a drop-down list for selecting the mains frequency, which will be filtered out later, and a **Stop** button, which stops the measurement (after pressing the button, the current acquisition is finished, then the program is stopped).
 +
 +Below the control elements, a plot pane is placed, where the electrocardiograph signal is displayed. Below the plot pane, a slider and a numeric indicator shows the calculated heart rate, the slider being green when the heart rate is considered normal (between 50 and 100 bpm) and red otherwise. On the right part, a column is placed, where all the data acquired from the ECG feature extractor block is displayed (see: [[http://zone.ni.com/reference/en-XX/help/373696B-01/lvbiomed/bio_ecg_extractor/|ECG Feature Extractor VI]]).
 +</WRAP><WRAP column half>
 +{{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:front_panel.png?nolink&600 |}}
 +</WRAP></WRAP>
 +----
 +
 +==== Data Flow ====
 +=== Data Aquisition ===
 +<WRAP group><WRAP column half>
 +The block diagram of the ECG VI is divided at six parts with different decorational elements and structures. The first two parts are responsible for initializing the //Oscilloscope// instrument and receiving data from it. In the first part the used Test and Measurement device is set to be the Analog Discovery Studio, the scope channel is selected with the help of the respective control element on the front panel, the probe attenuation is set to 1 (because MTE cables are used), the vertical coupling is set to AC, the offset to 0 and the range from -1.5V to +1.5V (this doesn't matter as autoscale can be turned on on the plot pane).
 +
 +Acquisition mode of the scope is set to sampling with a 1000 sample rate for the time specified with the help of the control element on the front panel. After the initialization, the instrument handle and the error signal are sent in a while loop, where data acquisition starts and continues until the **Stop** button is pressed.
 +</WRAP><WRAP column half>
 +{{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:block_diagram_1.png?nolink&600 |}}
 +</WRAP></WRAP>
 +
 +=== Postprocessing ===
 +<WRAP group><WRAP column half>
 +The acquired signal is still as noisy as seen on the //Oscilloscope// in WaveForms, so it needs filtering. After the DC component is estimated and subtracted from the signal to remove any offset (some might remain after the decoupling), the data enters a moving average filter, its parameters depending on the utility frequency. This filter eliminates almost completely the 50 Hz or 60 Hz component in the power spectrum, as well as its harmonics. The exiting signal is smoothed. As it can be seen on the power spectrum at [[test-and-measurement:analog-discovery-studio:ecg-demo:start#circuit_setup|Circuit Setup]], the most significant components of the signal are below 50 Hz, so filtering out everything above that should not damage the useful signal. However, as the QRS wave (the high amplitude part of the ECG signal) has a rise time of around 15 ms, a 25 Hz threshold should be considered, the cutoff frequency of the low-pass filter becoming 75 Hz.
 +
 +After proper filtering, the maximum point of the data set is acquired and, with a peak detector, all the data points above 75% of this maximum and 10 ms wide are found (the P - preceding QRS - and T - proceeding QRS - signals of the should not reach that amplitude). The location of these points are multiplied with the time derivative of the signal and summed with the starting time to get the exact time of each peak. Time between two consecutive peaks is calculated and converted to frequency, then multiplied with 60 to get the number of beats (peaks) per minute.
 +</WRAP><WRAP column half>
 +{{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:block_diagram_2.png?nolink&600 |}}
 +</WRAP></WRAP>
 +
 +=== Results and Cleanup ===
 +<WRAP group><WRAP column half>
 +The filtered signal is connected to the plot pane and to the ECG feature extractor to visualize the signal itself as well as the data about it. The calculated heart rate is also visualized with the help of the slider, but also evaluated and if it is lower than 50 bpm, or higher than 100 bpm, the fill color of the slider is changed to red (otherwise it is green).
 +
 +The while loop is exited only if the stop button is pressed or if there is an error, but in both cases the current data acquisition is finished first. After exiting the loop, the //Oscilloscope// instrument is stopped and closed to make the Analog Discovery Studio available for other programs. The errors are also handled here: if there was any error, the respective message is displayed.
 +</WRAP><WRAP column half>
 +{{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:block_diagram_3.png?nolink&600 |}}
 +</WRAP></WRAP>
 +----
 +
 +==== Testing ====
 +<WRAP group><WRAP column half>
 +To test the device, build the circuit on the Breadboard Canvas, turn on the Analog Discovery Studio and connect it to a PC. Open the ECG VI. Place one surface electrode on the inner side of your left wrist, one on the inner side of your right wrist and one on the inner side of your right ankle. With the alligator clips, connect the circuit to the electrodes, as shown in the image to the right. Start the VI with the play button. If you stay still for a few seconds, you will see on the plot pane your ECG signal and the estimated heart rate.
 +</WRAP><WRAP column half>
 +{{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:limb_leads.png?nolink&200 |}}
 +</WRAP>
 +{{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:running.png?nolink&600 |}}
 +</WRAP>
 +
 +--> Testing Without External Circuitry #
 +<WRAP group><WRAP column half>
 +If you don't have the necessary hardware for this project, you can still test the VI, using Analog Discovery Studio and an other Test and Measurement Device (called transmitter in the following). Connect the transmitter's analog output to the Analog Discovery Studio's analog input pins: transmitter yellow wire to ADS orange wire and transmitter black wire to ADS orange-white wire. Open WaveForms connect it to the transmitter device and open the //Waveform Generator// instrument. Set signal type to **Custom**, download, unzip and import the following file: {{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:recorded_ecg.zip |Recorded ECG}}. Leave every setting on default. The file contains several seconds of recorded ECG signal, which can simulate the signal measured with the amplifier circuit. Start the //Wavegen// and start the ECG VI with the Play button. You can observe the heart signal on the plot pane and the calculated data right to it, as well as the appearing noise at certain times.
 +</WRAP><WRAP column half>
 +{{ reference:test-and-measurement:analog-discovery-studio:ecg-demo:import_recorded.png?600 |}}
 +</WRAP></WRAP>
 +<--
 +----
 +
 +===== References =====
 +<WRAP group>
 +  * [[https://www.instructables.com/id/Electrocardiogram-ECG-Circuit/|Electrocardiogram (ECG) Circuit]]
 +  * [[https://www.instructables.com/id/DIY-ECG-Using-a-Analog-Discovery-2-and-LabVIEW/|DIY ECG Using Analog Discovery 2 and LabVIEW]]
 +  * [[http://zone.ni.com/reference/en-XX/help/373696B-01/lvbiohowto/design_bmt_ecg_ext_2/|Designing an ECG Feature Extractor Part 2]]
 +  * [[http://www.learningelectronics.net/circuits/ecg-amplifier-by-tlc274.html|ECG Amplifier By TLC274]]
 +  * [[https://www.pinterest.com/pin/412783122081218597/|4 lead ECG placement]]
 +</WRAP>
 +----
 +
 +===== Final Notes =====
 +For more guides and example projects for your Analog Discovery Studio, please visit its [[test-and-measurement:analog-discovery-studio:start|Resource Center]].
 +
 +For more information about how to use the software featured in this demo, please visit its respective guide: [[test-and-measurement:guides:getting-started-with-labview]].
 +
 +For technical support, please visit the [[https://forum.digilent.com|Digilent Forums]].
 +
 +{{tag>project analog-discovery-studio}}