Systematic Design and HRV Analysis of A Portable ECG System Using Arduino and LabVIEW For Biomedical Engineering Training

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

International Journal of Electronics and Electrical Engineering Vol. 5, No.

5, October 2017

Systematic Design and HRV Analysis of a


Portable ECG System Using Arduino and
LabVIEW for Biomedical Engineering Training
Mehdi Shokoueinejad, Michelle Chiang, Samual Lines, Fa Wang, Willis Tompkins, and John G. Webster
Department of Biomedical Engineering, University of Wisconsin-Madison, Madison WI 53706, USA
Email: [email protected], [email protected]

Abstract—This paper presents a systematic design for a the heart, gathered from the skin, are illustrative in
fully operational portable electrocardiogram (ECG) system determining the condition of the heart. If a patient is
for training and educational purposes in Biomedical suffering from abnormal heart pathology, the electrical
Engineering (BME) curriculum courses. The proposed signals generated by the patient are likely to differ from
ECG system also includes heart rate variability (HRV)
those of a normal individual. Therefore, studying the
analysis using LabVIEW, as well as step-by-step methods
for the hardware and software design consideration. The electrical signal generated by the heart can provide a
instrumentation is developed to interface as a shield for an useful means to diagnose patients non-invasively. From a
Arduino Uno. Furthermore, the study of the ECG signal technical standpoint, students and researchers will
includes acquisition of a real-time ECG signal, signal develop a useful toolkit for BME design. They will gain
filtering and processing. ECG feature extraction is based on important technical skills, such as how to acquire a real-
the wavelet transform for HRV analysis in LabVIEW. The time, biological signal and how to use hardware and
proposed system has been tested with the MIT-BIH software to process the signal. They will learn how to
arrhythmia database and was able to achieve a sensitivity of design and fabricate a Printed Circuit Board (PCB), how
93.5%. Researchers will develop a valuable toolkit in the
to use a microcontroller to develop a portable medical
process of designing this system, and if the system is further
developed to meet clinical standards, it could have major device system, and how to use LabVIEW for important
applications in less accessible areas.  ECG feature extraction.
Incorporating ECG design into BME curriculum can
Index Terms—ECG, physiological measurement system also be beneficial for society. This is because the
design, ECG signal processing, LabVIEW, Arduino, development of accessible, portable ECG systems has
engineering education real clinical applications worldwide. A portable ECG
system would provide a handy ambulatory monitoring
system that patients can carry around and have their heart
I. INTRODUCTION conditions continuously monitored. Cardiovascular
Cardiovascular Disease (CVD) is the number one disease is an extremely prevalent issue, ECG design is an
cause of death each year [1], [2]. Electrocardiography extremely relevant field of study, and the optimization of
(ECG) plays a central role in the diagnosis of the proposed system could contribute to mitigating the
cardiovascular disease by reading the electrical activity global issue of heart disease mortality.
of the heart in a non-invasive manner [3], [4]. ECG The purpose for this study is to create step-by-step
information is used for a variety of purposes, such as platform that equips students and researchers to develop
diagnosis of heart disease, monitoring of nominal heart physiological signal acquisition systems. The proposed
activity, and other recording applications. use for this platform includes various BME teaching and
The ECG is broadly used in clinics to examine patients’ research applications, such as medical instrumentation
heart conditions, and its effectiveness has been proven courses and undergraduate or graduate independent
through its extensive use in the diagnosis of heart research. An overall design specification is explained and
conditions. adopted in Section II.A. The hardware design is provided
The proposed system is a fully operational portable in Sections II.B and II.C. The software implementation is
electrocardiogram (ECG) system for training and then outlined in Sections II.D and II.E. The experiment
educational purposes in Biomedical Engineering (BME) results and statistics for the developed device are
curriculum courses. presented in Section III. Finally, Section IV provides
Incorporating ECG design into curriculum is largely further discussion of this study.
beneficial for students and researchers interested in BME.
From a biological standpoint, they will learn to II. MATERIALS AND METHODS
understand the electrical nature of arguably the most
important physiological organ. The electrical signals of A. Overall Design Specifications
We designed a two-channel ECG amplifier to allow
Manuscript received May 11, 2017; revised September 27, 2017. simultaneous ECG data recording for both lead I and

©2017 Int. J. Electron. Electr. Eng. 301


doi: 10.18178/ijeee.5.5.301-311
International Journal of Electronics and Electrical Engineering Vol. 5, No. 5, October 2017

lead II. The bandwidth was set to 0.05 to 150 Hz with an the microcontroller that connect to the PCB. The
anti-aliasing filter of greater than –100 dB/decade for the microcontroller itself is powered by a laptop via the USB
low-pass filter [5]. The range of frequency for power cable. The separation of the collective system into
measurement of this physiological measurement is at low these subsections allows for specifications to be verified
frequency in contrast to some other physiological during the development of the system. The relationship
circuitry application which can be in high frequencies between these circuit topologies is demonstrated in Fig. 1.
[6]-[8]. The portable ECG was constructed as a daughter
board for the Arduino Uno microcontroller, which was TABLE I. PORTABLE ECG SYSTEM SPECIFICATION AND FEATURES
programmed to sample the signal at 750 Hz [9]. All
analog circuitry was placed on a single dual layer Printed
Circuit Board (PCB) for shielding purposes. The analog
data can then be processed using a combination of
LabVIEW and Arduino based coding algorithms.
The Arduino takes care of the front end data collection
and correction. The digitized ECG signals are sent to the
computer for processing. LabVIEW handles the
processing and extrapolation of denoised ECG data for
varying degrees of measurement and interpretation. The
ECG feature extraction was based on the Daubechies
wavelet (db06) transform for its similarity to the QRS
wave of the ECG signal. After the wavelet transform, the
algorithm searched for the maximum positive point and
minimum negative point pair using the high frequency
scale [10], [11], which determined the R wave positions.
A search window was implemented to determine the P
wave and T wave at low frequencies. Based on the Pan-
Tompkins algorithm and ECG feature extraction R-R
intervals, P wave, QRS complex were determined, and
used in the LabVIEW’s HRV analysis suite. Using ten
sample ECG sets from the MIT-BIH arrhythmia database,
results of the LabVIEW HRV analysis were collected
and compared to information posted on the MIT-BIH
database.
B. Hardware - Analog Circuit Design
The analog circuitry consists of four primary signal
processing blocks that allow for amplification and
filtration of the raw ECG signal to meet the system
specification listed in Table I. The stages in order of
signal processing are a preamplifier, Band-Pass Filter
(BPF), low-pass filter and Programmable Gain Amplifier
(PGA). The complementary circuits used to aid in
functionality are the Analog Common Voltage (ACOM)
generator and the Driven Right Leg (DRL) circuit. Power
is supplied to each of these stages by the output pins on

Figure 1. Block diagram of the ECG lead amplifier.

©2017 Int. J. Electron. Electr. Eng. 302


International Journal of Electronics and Electrical Engineering Vol. 5, No. 5, October 2017

The gain of the whole system is equal to the product of Voffset. This is done by using a BJT connected to the
the gains of each circuit block, as demonstrated in (1). ACOM 2.5 V DC source at the emitter junction, and the
source collector connected to the side of the capacitor
𝐺𝑇 = 𝐺1 ∗ 𝐺2 ∗ 𝐺3 ∗ 𝐺4 (1) that is closest to the amplifier within that block. This is
activated by applying a voltage from the Arduino to the
In order to meet the specifications set in Table I, each base in order to forward bias the transistor (see Section
stage was designed to have a certain gain so that the II.D-1)).
product of all stages yielded a total gain, GT, equal to Within the feedback loop of this active filter is a low-
432-1728 V/V. Because the Sallen-Key filter is a unity pass filter. Since there is a total of five low-pass filters
gain filter, it does not change the gain of the system; within the system, (3) is no longer applicable to the
therefore, the total gain is dependent only on the gain of frequency calculation. To acquire a steeper roll-off for
the preamplifier, band-pass filter, and PGA. Here, the low-pass filter, n filter stages can be connected in
reasonable gains were set for the first two blocks, and the series. The resulting transfer function is:
gain for the fourth block (PGA) was determined 1
𝐺 = (1+α1∗s)(1+α2∗s)…(1+αn∗s) (4)
accordingly.
1) Analog Common Voltage (ACOM) generator In the case that all filters have the same cut-off
The ACOM generator is a power block that will frequency, fC, the coefficients become:
supply 2.5 V elsewhere in the circuit. This circuit
topology includes a voltage divider with two equivalent 𝑛
α1 = α2 = ⋯ = αn = α = √( √2 − 1) (5)
resistors to divide the 5 V power source in half. The
resulting 2.5 V signal is isolated using a voltage follower As a result, fC of each partial filter is 1/α times higher
buffer. This will provide the 2.5 V baseline for the ECG. than fC of the overall filter [12]. Provided this
The capacitance within this pseudo-ground circuit is information, the case of five series low-pass filters, (3)
added for stability of the DC output. must be multiplied by a correction factor, as shown
2) Preamplifier stage (instrumentation amplifier) below.
The purpose of this stage is to provide both high input
impedance and a high common mode rejection ratio, √( 5√2−1) √( 5√2−1)
which helps to improve the signal-to-noise ratio of the 𝑓𝑐 = = (6)
system as a whole. The main component is the LT1167 2𝜋𝜏 2𝜋𝑅𝐶
instrumentation amplifier. This amplifier operates with This new formula gives a desired cutoff frequency of
power rails of 0 V and 5 V called as a single supply. 150 Hz when a time constant τ = RC of 4.09*10-4 is used.
Since the range is non-negative the signal is centered on This means that for each low-pass filter within the
the midpoint voltage, Voffset = 2.5 V. This offset is system, the product of the resistance and capacitance
applied using the ACOM generator circuit. To acquire must equal this value. To maximize gain within the band-
proper resistance values for the gain of the preamplifier pass stage, the smallest capacitor value (330 pF) is used
at this stage, (2) was utilized. to allow for a maximized feedback resistance. The
49.4 𝑘Ω corresponding resistance is calculated to be 1.2 MΩ to
𝐺1 = 1 + (2) meet all constraints. The gain of this filter, G2, is then
𝑅𝐺
equal to the feedback resistance divided by the input
In order to achieve a gain of 10.96, the resistance, RG resistance, which equates to -3.64.
= 4.96 kΩ, is found by applying the formula. This 4) Low-pass stage
resistance must then be split into two equal parts. The The low-pass topology that is employed is called
resulting two equivalent resistors are used calculate the Sallen-Key. It is a second-order filter and has unity gain
average of the input signal, which then act as an input to characteristics. As long as the resistor values and
the DRL circuitry (see Section II.B-6)). capacitor values are chosen with the same tau value as
3) Band-Pass stage previously calculated (see Section II.B-3)), the filter will
This stage starts with a high-pass filter input that has a have the correct frequency response. Due to the unity
cutoff frequency of 0.05 Hz. This cutoff frequency is set gain characteristic, all components will equate to each
by the values of the resistor and capacitor as shown in (3). other (R14 will be equivalent to R15 and C8 will be
1 1 equivalent to C9). The value of C is chosen to be 330 nF,
𝑓𝑐 = = (3) which leads to an R-value of 1.24 kΩ when the tau
2𝜋𝜏 2𝜋𝑅𝐶
equivalency is used.
Picking the capacitor to be 10 uF and applying (3) 5) Programmable Gain Amplifier (PGA) stage
yields a resistance value of roughly 330 kΩ. With these This stage consists of a low-pass filter leading into a
specifications, if the circuit is saturated, there will be a non-inverting operational amplifier and is immediately
time delay for the DC baseline to return to the followed by another low-pass filter. The reasoning
equilibrium baseline, 2.5 V. This is a result of the high behind the programmable aspect of this stage is for
time constant of the high-pass portion of the band-pass compensation due to variable electrical activity of the
filter. To eliminate this effect, a reset switch is added to heart. Since we want to be able to scale the output signal
discharge the capacitor and drive the output back to to a visible level, the gain must be adjusted. The values

©2017 Int. J. Electron. Electr. Eng. 303


International Journal of Electronics and Electrical Engineering Vol. 5, No. 5, October 2017

of the resistors and capacitors in the low-pass filters were The parametric simulation in Fig. 2 shows the
picked to be 330 nF and 1.24 kΩ, just as above. To find frequency response for the PGA system at different gain
the gain of the non-inverting operational amplifier, the settings. The bottommost trace represents the minimum
following (7) is used: possible gain for the system, when Rvar = 1 kΩ. The
𝑅𝑓 topmost trace represents the maximum possible gain for
𝐺4 = 1 + (7) the system, when Rvar = 100 kΩ. The middle trace depicts
𝑅𝑖
the frequency response when Rvar = 10 kΩ to further
In this equation, Rf is the total resistance in the demonstrate the relationship between the variable resistor
feedback loop and Ri is the input resistance. This block and the gain. The key here is that all three traces
is called a programmable gain amplifier because Rf demonstrate comparable frequency responses. Thus, the
contains a 100 kΩ potentiometer, which can be major advantage of the PGA is that the user can have
manipulated. The DS1804 NV, nonvolatile digital manipulation over the output gain without altering other
potentiometer, is utilized and has 100 unique positions. behaviors of the system in order to cover the wide range
In this case, these values range from RvarL, 1 kΩ, to RvarH, of the amplification.
100kΩ, in increments of 1kΩ. The device provides an
ideal method for low-cost trimming applications using a
Central Processing Unit (CPU) or manual control input
with minimal external circuitry (see Section II.D-2)). To
achieve the required gain range, the system of equations
(8)-(9) must be solved. Here, GTL is the lower bound of
the total gain and GTH is the upper bound of the total gain,
which are 432 and 1728 V/V, respectively.
𝑅𝑣𝑎𝑟𝐿 + 𝑅𝑓1
𝐺𝑇𝐿 = 𝐺1 ∗ 𝐺2 ∗ 𝐺3 ∗ (1 + ) (8)
𝑅𝑖
𝑅𝑣𝑎𝑟𝐻 + 𝑅𝑓1
𝐺𝑇𝐻 = 𝐺1 ∗ 𝐺2 ∗ 𝐺3 ∗ (1 + ) (9)
𝑅𝑖

In these equations, 39.89 is the product of the


individual gains of the previous blocks, Rf1 is a constant
resistor in the feedback loop, and Ri is the input resistor.
Solving this system and picking the closest resistor
Figure 2. Bode plot of the simulated output of the ECG lead at
values available gives an Rf1 of 26.7 kΩ and a Ri of 6.8 minimum gain, maximum gain, and one gain in between minimum and
kΩ. maximum.

Figure 3. Circuit diagram of a single ECG lead. Two identical circuits were combined to create the ECG shield. Regarding the operational amplifiers,
an LT1167 was used for the instrumentation amplifier and the TLV274 was used for all other op-amps. When implementing the transistor that serves
as a reset switch, it is attached to the capacitor, C4, on the band-pass filter circuit block (see Section II.B-3)).

6) Driven Right Leg (DRL) circuit leg circuit is added to the design to further minimize
One of the most important performance parameters for common mode voltage [14].
ECG system applications is the Common Mode In this case, a low resistance, Rp (see Fig. 3), is used to
Rejection (CMR) [13]. This is because the differential drive the common mode voltage into the patient’s body.
between the two raw input voltages is very small. Initially, the body is at a positive common mode voltage,
Driving common mode voltage through a resistor is one so the DRL inverts and amplifies the signal from
technique to improve CMR [13]. Thus, the driven right between the two equivalent resistors in the preamplifier

©2017 Int. J. Electron. Electr. Eng. 304


International Journal of Electronics and Electrical Engineering Vol. 5, No. 5, October 2017

(see Section II.B-2)). The amplified negative signal is copper planes, called polygons, create a similar
then fed back into the patient’s right leg, which pulls phenomenon to ensure power signal integrity (see Fig. 4).
down the common mode voltage, thereby increasing the
CMRR.
The closed loop gain of this system, G5, can be
calculated using (10), where Zf is the total feedback
impedance (11).

𝑍𝑓 𝑍𝑓 𝑍𝑓
𝐺5 = = =2∗ (10)
𝑍𝑖 𝑅𝐺 ⁄2 𝑅𝐺

𝑅𝑓
𝑍𝑓 = (11)
1+𝑠𝑅𝑓 𝐶𝑓

This feedback loop improves CMR by (1 + G5) [10].


In summary, the DRL provides stability to the system,
while ultimately improving CMR. If the third electrode is
connected to a DRL, the effective resistance to common
is reduced to Rp, which also serves as a current-limiting
resistor [14]. The DRL circuit block is also used to help
remove a significant amount of noise due to power-line
interference, as well as to prevent any potentially
dangerous currents from flowing through the patient [13],
[14].
7) Additional components
In addition to the primary blocks, several other Figure 4. (a) Conceptual illustration of electronics package suitable for
components are added onto the PCB in order to transition onboard testing in an Arduino UNO platform. (b) PCB layout of the
ECG shield. PCB was a two-layer board.
the circuit from a breadboard prototype to a final shield
version. The audio jack is added in order to connect the D. Software – Arduino
electrode leads from the body to the PCB. An additional
screw terminal is placed on the PCB to account for the The software for this design consists of two parts: the
extra lead needed for the DRL. There are also a series of firmware and the user interface. The firmware is the code
header pins that match the pinout of the Arduino so that on the microcontroller that acts independent of the user.
the PCB can interface readily with the software (see Fig. In this design, the firmware contains code that is used to
3). Several other header pins are also added to the acquire data from the PCB and coordinate
schematic to either serve as access (or test) points or to communication with the computer. The computer runs a
create sockets for removable components. main application that serves as a user interface to display
the data that has been gathered.
C. CAD Drawing of ECG Circuit 1) Arduino firmware
The Printed Circuit Board (PCB) design is based on The firmware code is implemented on a
the schematic developed from the ECG circuit hardware microcontroller. The Arduino Uno R3 was selected for
described in Section II.B. This PCB is designed and this project due to its availability, wide community
constructed in Eagle, a PCB design freeware. The support and its efficiency in high-speed prototyping [6].
process of exporting the schematic to Eagle involves Fig. 5 demonstrates the Arduino firmware
recreating each component and connection on the implementation flowchart. The firmware on the Arduino
Cadence PSPICE schematic. Then the entire single is used to gather data, maintain communication with the
channel design gets repeated to create a dual channel computer, and autonomously control various aspects of
ECG circuit. However, only a single DRL channel is the ECG leads. The implementation and description of
used to negate interference from the measurements. the Arduino code can be found in the flowchart below,
Each component placed on the Eagle schematic is which includes both automatic gain and defibrillation
required to have a specified footprint that identifies its desaturation control. These abstract blocks will be
physical form on the PCB. On this board file, the discussed in more detail in Sections II.D-2) and II.D-3).
connections from the schematic are preserved. Each The flowchart details the implementation of the
component is placed on a 2.3 in x 3 in (1 in = 0.0254 m) Arduino firmware. Upon startup, the Arduino initializes
board and connected via copper traces, following the serial communication with the computer and LabVIEW
connections on the schematic. Trace widths vary from 8 Graphical User Interface (GUI) as well as a timer
mil to 32 mil (1 mil = 2.54*10-5 m) depending on the interrupt that will be used to set the sampling rate at 750
type of connection. Power or signal connections are Hz to adhere to the Nyquist-Shannon sampling theory
generally given larger traces to reduce noise and ensure [15], [16]. After initialization, there is an infinite loop
solid connectivity. For power and ground, separate that allows for data acquisition as well as control of the

©2017 Int. J. Electron. Electr. Eng. 305


International Journal of Electronics and Electrical Engineering Vol. 5, No. 5, October 2017

ECG lead circuit board. Every timer interrupt, data is position. With the calculation of the current gain of the
sampled. After the data is sampled, the code checks to PGA stage determined, it is possible to find the new
see if it is time to auto-calibrate the ECG leads. Finally, wiper position that will lead to the desired ECG lead
there is a check to see if either lead is saturated. If neither amplification. By rearranging the formula used to
one has saturated, the sampled ECG lead data is calculate the current gain of the PGA, and multiplying it
transmitted to the computer. by the necessary amplification calculated in the first step,
the new digital potentiometer position is determined.
With the new wiper position known, it is compared to the
previous wiper position to determine how far it needs to
move. If the wiper position needs to move in the negative
direction, loopRuni will be negative. To overcome the
negative number of for loop iterations, the absolute value
of loopRuni should be used and the wiper direction
should be changed from up to down.

Figure 5. Flowchart for the Arduino firmware.

The firmware on the Arduino is very simple as it


mainly provides a platform to easily send the data to the
computer. It does so by using the Circular Byte Buffer
implementation for Arduino, which is the memory
efficient way to read and write data from an array-backed
circular buffer [17]. That being said, both of the main 3) Desaturation function
automatic features of the Arduino, that of the gain The algorithm for saturation check is simple yet
control and desaturation switch, have been described important because saturation of the ECG will prevent the
below as algorithms to allow for straightforward proper use of the ECG, Algorithm 2.
implementation.
2) Automatic gain calibration
Automatic gain calibration of the ECG system allows
the Arduino to control the gain of the amplifiers in real
time to allow for the best signal acquisition. The
algorithm for automatic gain calibration can be seen in
Algorithm 1.
This algorithm works by comparing the peaks of the
ECG QRS single to a threshold value, and determining
whether the ECG lead gain should be increased or
decreased. By comparing the peak ECG QRS signal to
the threshold value, it is possible to determine the exact
gain needed to reach the desired ECG amplification. In order to determine if saturation has occurred, a
Once this extra gain has been determined, the current moving window of the previous 75 sampled data points
gain of the PGA must be determined (see Section II.B-5)). is kept. This corresponds to the last 0.1 seconds of ECG
To do this, (7) is modified by calculating Rf as the series data given the 750 Hz sampling rate. If the ECG is ever
sum of the two resistors that make up the effective Rf and saturated for more than 0.1 seconds, the desaturation
then plugging in the actual resistances for both Rf and Ri. switch will be engaged to bring the ECG back down to
Since Rf is made up of a resistor and a digital baseline. In order to determine if saturation has occurred,
potentiometer, the resistance of the digital potentiometer the last 75 samples are averaged. If this average is above
must be calculated by multiplying its current wiper a threshold set to the previous max value, then it is said
position by the step in resistance from moving one wiper to have saturated and the switch will be activated.

©2017 Int. J. Electron. Electr. Eng. 306


International Journal of Electronics and Electrical Engineering Vol. 5, No. 5, October 2017

E. Software – LabVIEW Data processing was accomplished through various


After data collection on the Arduino, the raw ECG different built-in LabVIEW VIs and was used for signal
data is transmitted to a LabVIEW executable that does all denoising, feature extraction as well as lead calculation.
of the signal processing, lead calculations, heartbeat Implementation of the LabVIEW code is outlined and
detection, and arrhythmia detection. This executable also described in the flowchart in Fig. 7.
displays all of the data to the user via a custom GUI. The 1) LabVIEW code implementation flowchart
GUI provides the user with an easy way to see the ECG Once the data was received from the Arduino, the raw
data. This allows for determination of how the heart is data is denoised. This abstract block will be discussed in
beating and for visual recognition of any sort of potential more detail in Sections II.E-2). Then, two parallel
pathologies. In Fig. 6, ECG lead I, II, and III are processes occurred in LabVIEW. The denoised ECG data
displayed of the left along with the augmented lead aVR, was used to calculate the various leads using the
aVL, and aVF on the right. Einthoven limb leads and Einthoven triangle [18]. At the
same time, data from both lead I and lead II was used to
detect the QRS complex of each beat. To do this, a
modified version of the Pan-Tompkins peak detection
algorithm was implemented. The implementation of this
algorithm can be seen in Section II.E-3). Furthermore,
Wavelet based ECG feature extraction was deployed in
order to perceive the P and T wave position, which is
discussed in more detail in Section II.E-4). After all of
the calculations for the various lead have been made, the
QRS complexes have been detected, and the Beats Per
Minute (BPM), R-R interval, P-R interval, and R-T
interval were calculated, all the data was displayed on the
Figure 6. Front Panel of the LabVIEW ECG GUI. Displayed are ECG
leads I, II, and III as well as aVR, aVF, and aVL. GUI for easy access.
2) Wavelet based ECG signal denoising
After recording a certain period of time (e.g.: 1
minutes), before the further signal processing, raw data
should be denoised. The noise in the ECG signal may
come from 1) other physiological signals, like
Electromyography (EMG) and respiration signal; 2)
electrode contact noise; 3) motion artifacts. These noises
could be modeled as white noise or color noise [19],
which could be denoised based on Wavelet Transform
(WT). The WT of the ECG signal f(x) is defined as (12):
1 ∞ 𝑥−𝑡
𝑊𝑠 𝑓(𝑥) = f(x) ∗ Ѱ𝑠 = ∫−∞ 𝑓(𝑡)Ѱ ( 𝑠 ) 𝑑𝑡 (12)
𝑠

Scale factor s determines the basis function.


Corresponding coefficients like d1, d2, d3, etc. give
frequency domain information. WT with higher s value
will focus on the low frequency domain, and vice versa.
Prototype wavelet Ѱ𝑠 is chosen as Daubechies wavelet
(db06) due to similarity of the shape to the QRS wave of
ECG signal. Previous studies apply golobla thereshold
for all levels of WT. On the other hand, Poornachandra et
al. introduced a level dependent threshold for ECG
denosing [20] which using this approach can enable us to
achieve higher signal to noise ratio (SNR). The threshold
is defined in (13):
𝜎
𝑘√2 log(𝑛)
𝑡𝑙,𝑘 = (13)
𝑆𝑙,𝑘 +𝑏

where 𝜎𝑘 is the variance of the noise. If 𝜎𝑘 is unknown,


it could be estimated via median absolute deviation [21]
shown in (14):
𝑚𝑒𝑑𝑖𝑎𝑛|𝑥|
Figure 7. Flowchart for the LabVIEW code. 𝜎𝑘 = (14)
0.6745

©2017 Int. J. Electron. Electr. Eng. 307


International Journal of Electronics and Electrical Engineering Vol. 5, No. 5, October 2017

Sl,k in (13) is scale level dependent parameter (15): composed of a cascaded high-pass and low-pass filter.
𝐾
The cutoff frequency for the high-pass filter is 5 Hz and
𝑆𝑙,𝑘 = 2(𝐿− ⁄𝐿) (15) the cutoff frequency of the low-pass filter is 17 Hz. This
creates a pass band from 5 to 17 Hz. After the band-pass
L is a total or deepest decomposition wavelet transform filter, the point-by-point derivative of the signal is taken.
level, which normally ranges from 3 to 5. And K is the Wired to the point-by-point derivative is the time
current level which thresholding is applying on. between samples, which is dictated by the sampling rate
Based on 𝑡𝑙,𝑘 threshold, we apply soft threshold to the of the Arduino. Next to further isolate the QRS complex
wavelet coefficient at each level (16): values below zero are eliminated. This helps remove
noise. Finally, the signal is squared and amplified to
𝛿𝑡 (𝑥) = 𝑠𝑔𝑛(𝑥)(|𝑥| − 𝑡𝑙,𝑘 ) (16) create peaks for each QRS complex. Fig. 9 shows the
LabVIEW implementation of the algorithm described in
Then the ECG signal was reconstructed based on these Algorithm 3.
modified coefficients shown in Fig. 8.

Figure 9. LabVIEW implementation of the modified Pan-Tompkins


algorithm.

4) Heart rate calculation


Using the output of the Pan-Tompkins QRS detection
algorithm, heart rate was calculated using last ten
detected beats shown in Algorithm 4.

Algorithm 4: Pseudocode of Heart Rate Calculation

Define: P to be the output of the Pan-Tompkins


algorithm, f to be a flag to determine if current peak
Figure 8. Demonstrates the signal denoise result. Denoising with db06
is still occurring, HR to be previously calculated
and level 5. heart rate, and thresh to be the threshold used to
signal a peak has been detected.
3) Pan-Tompkins algorithm in LabVIEW Data: P, f, HR, thresh
A modified implementation of the Pan-Tompkins Results: heartRate
algorithm created with the use of built in LabVIEW point
initialize f = false;
by point functions for real time QRS detection shown in
Algorithm 3 [22], [23]. if ~f && P > thresh then
f = true;
Algorithm 3: Pseudocode of Pan-Tompkins Algorithm beatArrat[i] = current time –
previous beat time ;
Define: Ei to be the data from ECGi
i = (i+1)%10;
Data: Ei
heartRate = avg(beatArray[] over all i)
Result: R
else
for a signal Ei do
heartRate = HR;
B = Band-pass filter(Ei )low cutoff =
end if
5Hz high cutoff = 17Hz;
if f && P<thresh then
D = Point-by-point derivative(B);
f = false;
if D < 0
end if
D=0
end if Heart rate was determined using the output of the Pan-
Tompkins Sub-VI. Each time a peak from the Pan-
S = Square(B)
Tompkins goes over the threshold value set for the heart
A = avg(Sk,Sk-1,Sk-2,Sk-3,Sk-4) rate calculation, the time of the beat minus the time of
end do the previous beat is stored in a circular array of length 10.
Upon entering the Pan-Tompkins QRS detection Sub- This captures the time between each beat. The points
VI, each data point passes through a band-pass filter from the array are then averaged to get the average time

©2017 Int. J. Electron. Electr. Eng. 308


International Journal of Electronics and Electrical Engineering Vol. 5, No. 5, October 2017

between beats from the last ten beats. With the average Root Mean Square of the Successive Differences
time per beat, heart rate is easily back calculated. (RMSSD) and NN50 which is the the number of pairs of
5) Wavelet based ECG feature extraction successive NNs (same as R-R, normal beats) that differ
The denoised signal is also can be sent to the feature by more than 50 ms could also be calculated based on
extraction sub VI in LabVIEW for ECG feature this information.
extraction shown in Fig. 7, which is based on the discrete Denosied ECG
wavelet transform(DWT). Original signal, which is” s” signal

in Fig. 10, will be decomposed by a high pass filter and a


low pass filter. High pass filter result would be finally Wavelet
transformed to the level 1detail coefficients d1. Low pass Transform
Level 5
d5
d2 d5
filter result, which is transformed to the approximation
coefficients, would treated as the next level original
signal, and repeated to get level 2 detail coefficients d2.
Search for max
This progress would repeated 5 times for a typical ECG Decrease TH1 positive and min
60% R-R interval
search window
40% R-R interval
search window
negative pair
signal and get level 1 to level 5 detail coefficients d1 to
d5. Remaining approximation coefficients is a5 and is
also shown in Fig. 10. NO
Absolute
value
Search for max
positive and min
Search for max
positive and min
Typical one cardiac cycle signal and its wavelet >TH1? negative pair negative pair

transform is shown in Fig. 10:


YES
Absolute Absolute
value value
QRS complex >TH2? >TH3?
position
YES YES

P wave position T wave position

Figure 11. Demonstrates flowchart of Wavelet based ECG feature


extraction.

III. RESULTS
The LabVIEW algorithm was tested using 25 one-
minute long ECG data sets from the MIT-BIH
Arrhythmia Database. Using this database, detected beats
were compared to the annotated information with each
ECG signal. To maintain consistency throughout the tests,
ECG beat detection was done on data from lead II. The
algorithm that was implemented in this project was able
to achieve a sensitivity of 93.5%. The percentage of
Figure 10. DWT result with db06 and level 5. correctly classified heartbeats from the LabVIEW HRV
analysis varied from 89% to 100% with an average of
QRS complex is much clearer at high frequency scale 97.46%. The average error rate for the detected RR
like d2. After the WT, and rejecting all the isolated interval was 0.12% The RMSSD error rate was 1.69%.
maximum points, algorithm tries to search for the local The NN50 error rate was 1.95%.
maximum (lmax) positive point and local minimum (lmin)
negative point pair, which absolute value of (lmax - lmin) is IV. DISCUSSION AND CONCLUSION
larger than preset threshold; the zero-crossing point
between this pair is the position of the R wave [10]. If Here, the systematic design for a fully operational
algorithm could not find this pair for more than 2 ECG system has been described in detail. The skills
seconds by preset threshold, lower threshold will be acquired from a project like this can be really useful for
chose to search back again. experimental or lab purposes in biomedical engineering
Search windows for P wave detection which windows curriculum.
location is decided by QRS position and length is The authors are aware that the ADS1298 from Texas
depending on the R-R interval are performed to search at Instruments exists, which is an integrated circuit (IC)
low frequency scale, like d5. If one pair of local chip that can be used in the manufacturing of ECG
maximum positive point and local minimum negative systems. For advanced scholars that can afford the chip
point could be found and larger than preset threshold, a P and to whom this product is available, this could be
wave can be detected. Similar approach is also applied to incorporated in the design; however, in order to make
find the T wave shown in Fig. 11. this design more reproducible to engineers worldwide,
R-R interval, P-R interval, R-T interval could be found the steps in this paper are available. Understanding the
based on the position of QRS complex, T wave and P ECG design at a less abstract and more fundamental
wave. Further Heart rate variability (HRV) analysis like level makes this type of design more robust and adaptive

©2017 Int. J. Electron. Electr. Eng. 309


International Journal of Electronics and Electrical Engineering Vol. 5, No. 5, October 2017

to other applications. The authors believe that this paper [7] Z. Xuan, et al., “Invasive and noninvasive means of measuring
intracranial pressure: A review,” Physiological Measurement, vol.
can provide helpful information and will be useful for
38, p. R143, 2017.
training purposes without using complex ICs. [8] M. S. Maragheh, S. R. Sandock, A. Kumar, and Y. H. Jung,
LabVIEW is graphical programming software that is “Smart patch for wound management,” USA Patent, 2015.
widely used in industry as well as academia. [9] A. D’Ausilio, “Arduino: A low-cost multipurpose lab equipment,”
Behavior Research Methods, vol. 44, pp. 305-313, 2012.
Understanding how to implement different algorithms [10] C. Li, C. Zheng, and C. Tai, “Detection of ECG characteristic
and utilize the available toolboxes can equip students to points using wavelet transforms,” IEEE Transactions on
take on many different projects and prepare them for biomedical Engineering, vol. 42, pp. 21-28, 1995.
their careers [24]. Additionally, the Arduino Uno was [11] M. Shokoueinejad, et al., “Sleep apnea: A review of diagnostic
sensors, algorithms, and therapies,” Physiological Measurement,
selected for use in this project due to its availability, vol. 38, p. R204, 2017.
wide community support, and its efficiency in high-speed [12] T. Kugelstadt, “Active filter design techniques,” Op Amps for
prototyping. Furthermore, the impact of this design has Everyone: Design Reference, pp. 271-281, 2008.
[13] V. Acharya, “Improving common-mode rejection using the right-
potential to span beyond academic education at the leg drive amplifier,” Texas Instruments, pp. 1-11, 2011.
college and research level. [14] B. B. Winter and J. G. Webster, “Driven-right-leg circuit design,”
For instance, the authors hope that by providing this IEEE Transactions on Biomedical Engineering, pp. 62-66, 1983.
toolkit, and designing it based on the widely accessible [15] E. J. Candès and M. B. Wakin, “An introduction to compressive
sampling,” IEEE Signal Processing Magazine, vol. 25, pp. 21-30,
material, that it would encourage students K-12 to pursue 2008.
BME and the study of the physiological signals [24], [25]. [16] C. E. Shannon, “Communication in the presence of noise,” Proc.
Finally, training biomedical engineers across the globe to of the IRE, vol. 37, pp. 10-21, 1949.
[17] P. Morin, Open Data Structures: An Introduction, Athabasca
understand the basics of how to acquire and study the University Press, 2013.
ECG signal may be the key to developing cardiac [18] M. B. Conover, Understanding Electrocardiography, Elsevier
diagnostic equipment or new signal processing Health Sciences, 2003.
approaches in their future career that can help combat the [19] M. A. Awal, S. S. Mostafa, M. Ahmad, and M. A. Rashid, “An
adaptive level dependent wavelet thresholding for ECG
issues of CVD and other disorder such as sleep apnea denoising,” Biocybernetics and Biomedical Engineering, vol. 34,
mortality rates worldwide [26]-[28]. pp. 238-249, 2014.
[20] S. Poornachandra, “Wavelet-based denoising using subband
dependent threshold for ECG signals,” Digital Signal Processing,
ACKNOWLEDGMENT vol. 18, pp. 49-55, 2008.
The authors would like to thank Dr. Amit Nimunkar, [21] D. L. Donoho and I. M. Johnstone, “Adapting to unknown
smoothness via wavelet shrinkage,” Journal of the American
Keum San Chun, Samuel Jensen, Shawn Patel, Alex Statistical Association, vol. 90, pp. 1200-1224, 1995.
Nguyen, Adib Keikhosravi, Lucas Hurtley, Gustavo [22] J. Pan and W. J. Tompkins, “A real-time QRS detection
Zach Vargas, and Robert Scott Carson, for guidance in algorithm,” IEEE Transactions on Biomedical Engineering, pp.
230-236, 1985.
the early design phases of the project. Funding for this [23] W. J. Tompkins, Biomedical Digital Signal Processing, Editorial
project was provided by the Department of Biomedical Prentice Hall, 1993.
Engineering, University of Wisconsin-Madison. [24] J. Travis and J. Kring, LabVIEW for Everyone, Prentice-Hall,
2007.
[25] A. J. Nimunkar, X. Zhang, M. Shokoueinejad, and J. G. Webster,
CONFLICTS OF INTEREST “Promoting active learning in biomedical engineering classes
through blended instruction,” Age, vol. 24, p. 1.
The authors declare no conflict of interest. [26] M. Shokoueinejad, “Computer-Based sleep apnea detection and
use of rebreathe device (“Smart CO2”) to treat sleep apnea,” The
REFERENCES University of Wisconsin - Madison, 2017.
[27] I. D Santos, et al., “Sleep apnea therapy device that automatically
[1] J. Xu, K. D. Kochanek, S. L. Murphy, and B. Tejada-Vera, adjusts the fraction of inspired carbon dioxide,” US 15/376,180
“Deaths: Final data for 2007,” National vital statistics reports: Patent, December 2016.
From the Centers for Disease Control and Prevention, National [28] C. Fernandez, S. Rusk, N. Glattard, and M. Shokoueinejad,
Center for Health Statistics, National Vital Statistics System, vol. “Computational phenotyping in polysomnography: Using
58, pp. 1-19, 2010. interpretable physiology-based machine learning models to
[2] T. Yamashita and S. R. Kunkel, “The association between heart predict health outcomes,” J. Sleep Res., vol. 40, p. A26, 2017.
disease mortality and geographic access to hospitals: County level
comparisons in Ohio, USA,” Social Science & Medicine, vol. 70,
pp. 1211-1218, 2010.
[3] J. P. Clarys, “Electromyography in sports and occupational Mehdi Shokoueinejad (SM’12, M’17)
settings: an update of its limits and possibilities,” Ergonomics, vol. received his B.Sc. degree in electrical
43, pp. 1750-1762, 2000. engineering from the University of Tehran, in
[4] M. Lamontagne, “Application of electromyography in sport 2011, and the M.Sc. and the Ph.D. degrees in
medicine,” in Rehabilitation of Sports Injuries, Springer, 2001, pp. Biomedical Engineering at the University of
31-42. Wisconsin-Madison (UW-Madison). WI,
[5] N. Meziane, S. Yang, M. Shokoueinejad, J. Webster, M. Attari, USA, in 2013 and 2016, respectively.He
and H. Eren, “Simultaneous comparison of 1 gel with 4 dry joined Boston Scientific Corporation as a
electrode types for electrocardiography,” Physiological senior R&D scientist, MN, USA, in 2017. His
Measurement, vol. 36, p. 513, 2015. main areas of research interest are the
[6] F. Wang, X. Zhang, M. Shokoueinejad, B. J. Iskandar, J. E. development of non-invasive and invasive physiological measurement
Medow, and J. G. Webster, “A novel intracranial pressure readout and biomedical signal processing methods for assessment of the
circuit for passive wireless LC sensor,” IEEE Transactions on cardiovascular, brain and respiratory system (sensors, identification
Biomedical Circuits and Systems, pp. 1-10, 2017. algorithms, and therapeutic devices). Dr. Shokoueinejad was the
recipient of the 2016 IEEE-EMBS, NSF Young Professionals

©2017 Int. J. Electron. Electr. Eng. 310


International Journal of Electronics and Electrical Engineering Vol. 5, No. 5, October 2017

Contributing to Smart and Connected Health, FL, USA. He won the Willis J. Tompkins received the B.S. and
First Place Grand Award at the 2014 Qualcomm Innovation M.S. degrees in electrical engineering from
competition, WI, USA. He has been extensively involved in organizing the University of Maine, Orono, Maine, USA
and contributing to American research societies such as Annual in 1963 and 1965, respectively, and the Ph.D.
Biomedical Society Meetings. degree in biomedical electronic engineering
from the University of Pennsylvania,
Philadelphia, Pennsylvania, USA in 1973. He
is currently Professor Emeritus of Biomedical
Michelle K. Chiang was born in Yokosuka, Engineering at the University of Wisconsin-
Japan. In 2015, she received her B.Sc. degree Madison, where he has been on the faculty
in biomedical engineering with a certificate in since 1974. He previously served for five years as Chair of the
Japanese studies from the University of Department of Electrical and Computer Engineering. He has published
Wisconsin - Madison (UW-Madison, WI, four textbooks including: 1) Biomedical Digital Signal Processing,
USA). Subsequently, she continued at UW- Prentice Hall, 1993; 2) Design of Microcomputer-Based Medical
Madison and received her M.S. degree in Instrumentation, Prentice Hall, 1981 (with J. G. Webster); and 3)
biomedical engineering in 2017. Chiang Interfacing Sensors to the IBM PC, Prentice Hall, 1988 (with J. G.
joined Johnson Health Tech. Co., Ltd. Webster). His research interests include development of
(Cottage Grove, WI, USA) in 2017 as an microprocessor-based medical instrumentation and real-time computer
Electrical Project Engineer in the Research and Development processing of electrocardiograms. Dr. Tompkins is a Life Fellow of the
department. Her research interests include embedded systems IEEE (Institute of Electrical and Electronics Engineers), a Founding
development and medical instrumentation. Fellow of the AIMBE (American Institute for Medical and Biological
Engineering), and an Inaugural Fellow of BMES (Biomedical
Engineering Society). He is a past President of the IEEE EMBS
(Engineering in Medicine and Biology Society). He is a past Chair of
Sam Lines received his B.Sc. and M Sc. the Biomedical Engineering Division of the ASEE (American Society
degrees in Biomedical engineering from the for Engineering Education).
University of Wisconsin-Madison (UW-
Madison). WI, USA, in 2015 and 2017
respectively. He joined Plexus Engineering John G. Webster (M'59-SM'69-F'86-LF’97)
Solutions in 2017 as a software engineer received the B.E.E. degree from Cornell
focusing on medical device software. University, Ithaca, NY, USA in 1953, and the
M.S.E.E. and Ph.D. degrees from the
University of Rochester, Rochester, NY,
USA in 1965 and 1967, respectively. He was
a Highly Cited Researcher, King Abdulaziz
University, Jeddah, Saudi Arabia.
He is Professor Emeritus of Biomedical
Engineering at the University of Wisconsin-
Fa Wang (M’17) received the B.Sc. degree Madison, USA. In the field of medical instrumentation he taught
in Biomedical engineering from Fudan undergraduate and graduate courses in bioinstrumentation and design.
Univerisity, Shanghai, China in 2011, and He does research on a sleep apnea device that uses no increased
Ph.D. degrees in Electrical and Computer pressure and a hydrocephalus shunt valve controlled by a pressure
Engineering from the University of sensor. He is the editor of Medical instrumentation: application and
Wisconsin-Madison (UW-Madison). WI, design, Fourth Edition New York, John Wiley & Sons, 2010, and has
USA, in 2017. Dr.Wang Joined Philips in developed 25 other books including the Encyclopedia of medical
2017 as an Electrical design engineer focus devices and instrumentation, Second Edition, New York: John Wiley &
on the MRI receiving coil design. His Sons, 2006, The physiological measurement handbook, CRC Press,
research interests include the hardware and Boca Raton, FL, 2015, Webster, J. G. and H. Eren (ed.), The
the software for the physiological measurement. measurement, instrumentation and sensors handbook, 2nd Ed. CRC
Press, Boca Raton, FL, 2014, Eren, H. and Webster, J. G. (ed.).
Telemedicine and electronic medicine, CRC Press, Boca Raton, FL,
2016, and 200 research papers. Dr. Webster is a fellow of the Institute
of Electrical and Electronics Engineers, Instrument Society of America,
American Institute of Medical and Biological Engineering, and Institute
of Physics. He has been a member of the IEEE-EMBS Administrative
Committee and the NIH Surgery and Bioengineering Study Section. He
is the recipient of the 2001 IEEE-EMBS Career Achievement Award.

©2017 Int. J. Electron. Electr. Eng. 311

You might also like