1
CHAPTER 5
SOFTWARE DEVELOPMENT USING LabVIEW FOR MEDICAL
INSTRUMENTS
5.1 Programming of PCG
The software used for analyzing the PCG signal obtained from the hardware is
LabVIEW. The software acquires the PCG signals from the hardware through NI DAQ.
Once the PCG signals data is obtained it is processed using various stages.
The flow chart to analyze the heart signal is shown in the fig 5.1. It gives the step
by step procedure of the backend operation of the analysis form. The developed program
extracts the wanted information on the signal.
i. Sampling
To convert a signal from continuous time to discrete time, a process called
sampling is used. The value of the signal is measured at certain intervals in time. Each
measurement is referred to as a sample. To convert the acquired signal into a form that
can be treated by a computer has to be digitized, i.e. reduced from an analog form (time-
and value-continuous) to digital (time- and value-discrete). This process is called A/D
conversion or sampling. It consists of two steps:
a. First, the analog signal s(t) is converted to a time-discrete form x(n) by sampling its
value (in the more specific sense of the word) in periodical intervals of duration ts, the
sampling period,.
2
Pre-Processing
Feature Extraction
Fig 5.1: Flowchart for Analyzing Heart sounds and Displaying Heart Rate
Start
DAQ
Filter
Baseline Wondering
Removing
Wideband Noise
Suppression
Peak Detection
Envelope Development
Time Interval
12
This type of power line interference is eliminated by using a programmable digital
Butterworth band reject filter.
The baseline wondering are suppressed by wavelet transform approach method.
The LabVIEW advanced signal processing tool kit (ASPT) provides WA Detrend Virtual
Instrument (VI) which cab be used to remove the low frequency baseline wandering (or
trend) of a signal. An internal parameter called trend level is required for base line
removal. The trend level is calculated as follows
Where t is the sampling duration and N is the number of sampling points in t time.
After the baseline wandering is suppressed, the PCG signal becomes more
stationary and explicit than the raw PCG signals. The remaining noise is complex
stochastic process with wideband nature. To suppress the wide band noise, the wavelet
Denoise VI module from LabVIEW is used.
This VI first Decomposes the PCG signal into several sub bands by applying the
wavelet transform, and then modifies each wavelet coefficients by applying a threshold
or shrinkage function, and finally reconstructs the denoised signal. In the present study,
we have used undecimated wavelet transform (UWT) sym 5 with single level and soft
thresholding for the wavelet denoising VI block setup. These settings perform perfect
denoising on the original PCG signal, and smoothen the signal without suppressing PCG
features such as peaks of the first, second and so on. For effective feature extraction, we
13
apply a wavlet denise VI with UWT sym5 and multiple level on the detrended signal to
make only the peaks of first and second if possible third and fourth signal more distinct.
b. PERFORMING FEATURE EXTRACTION ON PCG SIGNALS:
For the purpose of diagnosis, we often need to extract various features from the
preprocessed PCG data, including the peaks of first and second heart beats.
The multiresolution analysis Express VI used decompose the PCG signal by 6
level, Daubechies 6 (db6) wavelets and then reconstructs the signal with D4,D5 & D6 sub
bands. D4, D5 and D6 sub bands will be kept for reconstruction of PCG signals because
it makes more accurate for detection of heart sounds (beats)
c. Feature Extraction:
After detrending the PCG signal and applying denoising VI, the resulting signal is
applied to the wave peak detection VI. Peak detection is one of the most important time
domain function performed in signal monitoring. Peak detection is the process of finding
the locations and amplitudes of local maxima and minima in a signal that satisfies certain
threshold value. In the present study the waveform detector used records the locations of
the signal peak above some threshold value in an output array in terms of indices.
The peak detector function used has some important features, such as
� The function can process many blocks of data that are part of the same signal.
14
� This function retains the internal states and history information from one call to the next.
This VI internally allocates the structure that contains the information on the first block
of data and destroys it on the last block of data.
� The peak location function gives the peak locations at fractional indices. It uses the
quadratic fit algorithm and returns the peak locations as floating point numbers, not as
integers index values.
� The function allows implicit noise reduction while finding the peaks. Using the width
parameter effectively reduces the noise in the input signal when finding the peaks.
� The function performs a quadratic curve fitting to find the peaks. The core of the peak
finding algorithm consists of fitting a parabola to successive groups of points, equal in
number to width. The function uses the coefficients from the fit to determine whether a
peak or valley is present.
� For each set of points, the algorithm performs the least-square quadratic fit, and then
performs a series of tests on the coefficients to see whether they meets the criteria for a
peak. The function checks whether each parabola is at a local maxima, determines the
sign of the quadratic coefficients, which indicate the parabola’s concavity, and finally
checks that the peak is above the designated threshold.
At the output of waveform detector both amplitude and time locations are taken
into considerations for the construction of envelope. The envelope will be constructed for
a sampled value of the input signal.
15
To develop the envelope the following notations are considered
MPEAK = Maximum Amplitude of the sampled signal
MT1 = Time of the maximum amplitude --------(2)
THR = Threshold of the signal
TSEC = limits of the signal where peaks are measured
The technique used for PCG feature extraction is an approach which employs
peak or valley detection and to construct envelopes based on the peak values detected
which satisfies certain threshold conditions. The developed envelopes of the PCG give an
approximate representation of instantaneous magnitudes. This is done because the
envelopes are easier to process the PCG while they retain enough information to detect
the cardiac events.
1. Determine the MPEAK and MT1
2. Merge the peaks that are above THR that are very close to MT1 about (20 msec apart) to
the MPEAK value
3. If the peaks are lower than the threshold ignore that and search for the new local maxima
4. Assign systole the envelope that has short intervals which do not vary much over time
5. Assign diastole to the remaining intervals.
6. Assign S1 or S2 labels to each peak so that S1 signals the start of systole and S2 the start
of diastole.
16
5.2 Programming of Pulse Oximeter.
Our aim is to design and build an inexpensive, accurate, and user friendly pulse
oximeter that will allow doctors to receive pertinent data, which can be used to provide
medical attention to patients.
The program control elements and the control functions used in programming of
LabVIEW based pulse oximeter are
1. Sequence Structure
2. Extraction Portion of Signal.
3. Amplitude and Level measurements.
4. Curve Fitting.
17
Fig 5.6: Flow Chart for signal Capture
Start
Switch ON the RED
LED and wait
Capture RED Sensor
Value
Switch OFF RED LED
Switch ON the IR LED
and wait
Capture the IR Sensor
Value
Switch OFF the IR
LED
End
18
i.Sequence Structure:
Determining the execution order of a program by arranging its elements in a
certain sequence is called control flow. In labVIEW there are sequence structures to
obtain control flow within a data flow frame work. A sequence structure is an ordered set
of frames that executes sequentially. A sequence structure executes frame 0, followed by
frame 1, then frame 2, until the last frame executes. Only when the last frame completes
does the data leave the structure. There are two types of sequence structures the flat
sequence structure and the stack sequence structure.
Fig 7a: Flat Sequence Structure Fig 7b: Stack Sequence Structure
The Flat sequence structure is a program control element whose sub diagrams are
organized from left to right, side by side. In my present work flat Sequence Structure is
used because the program code designed for determining of SPO2 and heart rate needs to
execute separately for RED LED and IR LED with necessary delay in-between them. A
Frame is a sub diagram of structure.
ii. Extraction Portion of Signal:
19
It is a signal manipulation Sub VI which Extracts portions of data from the input
signals and returns the extracted data. A point or a range of data can be extracted, and the
extracted data can be by time or index. The time and index of the first occurrence of a
value can also be found out.
This sub VI can be configured so that a portion of the acquired signal is extracted
from which the DC valve and AC valve is determined which will be used for processing
for heart rate and SPO2.
iii. Amplitude and Level measurements:
It is a signal analysis Sub VI which is used for measurement of voltages (AC &
DC).
20
This sub VI can be configured to measure to measure values such as DC ,RMS
,Peak to Peak, maximum Peak, Minimum Peak and so on.
iv. Curve Fitting:
As the usage of digital measurement instruments during the test and measurement
process increases, acquiring large quantities of data becomes easier. However, the
methods of processing and extracting useful information from the acquired data become a
challenge.
During the test and measurement process, you often see a mathematical
relationship between observed values and independent variables, an independent variable
that results from an inaccurate measuring device. One way to find the mathematical
relationship is curve fitting, which defines an appropriate curve to fit the observed values
and uses a curve function to analyze the relationship between the variables.
The curve fitting performs the following tasks:
� Reduce noise and smooth data
� Find the mathematical relationship or function among variables and use that
function to perform further data processing, such as error compensation, velocity
and acceleration calculation, and so on
� Estimate the variable value between data samples
� Estimate the variable value outside the data sample range
21
Different fitting methods can evaluate the input data to find the curve fitting
model parameters. Each method has its own criteria for evaluating the fitting residual in
finding the fitted curve. By understanding the criteria for each method, you can choose
the most appropriate method to apply to the data set and fit the curve. In LabVIEW, you
can apply the Least Square (LS), Least Absolute Residual (LAR), or Bisquare fitting
method to the Linear Fit, Exponential Fit, Power Fit, Gaussian Peak Fit, or Logarithm Fit
VI to find the function f(x).
5.2.1 Theoretical description:
Lab VIEW program is to calculate:
� Percent oxygenation
� Pulse rate
22
The percent oxygen in the blood of a patient can be calculated by measuring the
amount of light that is transmitted through the fingertip using a photodiode as a sensor
and two LEDs (red and IR) as the light source. The photodiode detects the transmitted
light and the DAQ device outputs a voltage that corresponds to the amount of light
detected. The final signal appears as the waveform of a pulse. There will be two
waveforms: one signal for the red LED and a second for the IR LED. Once these signals
are generated using the DAQ device, several measurements are made. First, the amount
of time that elapses in between peaks will be determined in order to calculate the pulse
rate. Second, the AC and DC of the voltage signals will be determined in order to
calculate the percent of oxygenation. Once these values are found, the modulation ratio
is calculated. The modulation ratio is essentially the ratio of the magnitude of the red
waveform to that of the IR waveform.
To be able to record and calculate all of these measurements, the code is split into
a series of 5 different events that occur from left to right of our code.
The first event that occurs is turning ON the red LED by generating step voltage
using the DAQ device, this is shown in the first frame of the flat sequence structure used
to execute the developed code.
Then, the second event occurs which includes several steps:
� There is first a 5 second delay before anything happens to ensure that the red light
is turned on
23
� The light transmittance is detected by the photodiode and outputs as a voltage
signal for 5 secs using DAQ device input.
� The generated signal is cut into a section containing time between 3 secs to 8
seconds
� The DC (average) value between 3 to 8 secs is calculated
� The residual is obtained.
� The residual's peak to peak (AC) voltage value is found out.
� The time interval in between peaks is found.
� The peak to peak time interval obtained is divided by 60 in order to obtain the
pulse rate.
All the above steps are performed by the sub diagram placed in the second frame
of the flat sequence structure.
The third event turns on the IR LED and turns off the Red LED by generating step
voltage using the DAQ device, this is shown in the third frame of the flat sequence
structure.
The fourth event includes is a repeat of the second step, however all values will be
found for the IR signal instead of the red LED signal. Also, it is unnecessary to find the
peak to peak time interval for the IR signal because the pulse rate should be the same for
both LED signals, and therefore, calculating pulse rate from the red LED only is
sufficient. This is performed by the sub diagram placed in the fourth frame of the flat
sequence structure.
24
The fifth event turns off both Red and IR LEDs.
After these values are determined, the modulation ratio can be calculated by using
the equation R = (AC/DC) RED / (AC/DC) IR. Then, the empirical data is referenced in
order to find the percentage of oxygenation. The calibration curve was obtained from the
below graph and corresponding equation:
Y= - 10.291 * X * X – 27.865 * X + 117.93 - - - - - - - - - -( )
5.3 Programming of ECG
25
Electrocardiogram (ECG) is a diagnostic tool that measures and records the
electrical activity of the heart in exquisite detail. Interpretation of these details allows
diagnosis of a wide range of heart conditions.
5.3.1 ECG SIGNAL PROCESSING
Generally, the recorded ECG signal is often contaminated by noise and artifacts
that can be within the frequency band of interest and manifest with similar characteristics
as the Preprocessing ECG signals helps to remove contaminants from the ECG signals.
Broadly speaking, ECG contaminants can be classified into the following categories
• power line interference
• electrode pop or contact noise
• patient–electrode motion artifacts
• electromyographic (EMG) noise
• baseline wandering
Among these noises, the power line interference and the baseline wandering are
the most significant and can strongly affect ECG signal analysis. Except for these two
noises, other noises may be wideband and usually a complex stochastic process which
also distort the ECG signal.
26
Preprocessing of ECG
Data
Fig 5.8 : Flow Chart for ECG Signal Capture, Process and Display
Start
Acquire ECG Data
through Electrodes
using NI-DAQ
Filter
Baseline Wondering
Removing
Wideband Noise
Suppression
Display ECG data Storing the ECG
data in a file
Stop
27
The power line interference is narrow-band noise centered at 60 Hz (or 50 Hz)
with a bandwidth of less than 1 Hz. Usually the ECG signal acquisition hardware can
remove the power line interference. However the baseline wandering and other wideband
noises are not easy to be suppressed by hardware equipments. Instead, the software
scheme is more powerful and feasible for offline ECG signal processing.
5.3.2 Removing Baseline Wandering
Baseline wandering usually comes from respiration at frequencies wandering
between 0.15 and 0.3 Hz, and we can suppress it by a high pass digital filter. We also can
use the wavelet transform to remove baseline wandering by eliminating the trend of the
ECG signal. The Lab VIEW DFDT provides an intuitive and interactive way to design
and implement finite impulse response (FIR) or infinite impulse response (IIR) filters
easily and effectively.
Fig 5.9: Using the WA Detrend VI to remove baseline wandering
28
In addition to digital filters, the wavelet transform is also an effective way to
remove signals within specific subbands. The LabVIEW ASPT provides the WA Detrend
VI which can remove the low frequency trend of a signal. We can see that the resulting
ECG signals contain little baseline wandering information but retain the main
characteristics of the original ECG signal. It is also seen that the wavelet transform-based
approach is better because this approach introduces no latency and less distortion than the
digital filter-based approach.
5.3.4 Removing Wideband Noise
After we remove baseline wandering, the resulting ECG signal is more stationary
and explicit than the original signal. However, some other types of noise might still affect
feature extraction of the ECG signal. The noise may be complex stochastic processes
within a wideband, so you cannot remove them by using traditional digital filters. To
remove the wideband noises, we can use the Wavelet Denoise Express VI. This
LabVIEW based higher-level Express VI first decomposes the ECG signal into several
sub-bands by applying the wavelet transform, and then modifies each wavelet coefficient
by applying a threshold or shrinkage function, and finally reconstructs the denoised
signal. The following figure shows an example of applying the un-decimated wavelet
transform (UWT) to the ECG signal.
For the purpose of diagnosis, we often need to extract various features from the
preprocessed ECG data, including QRS intervals, QRS amplitudes, PR intervals, ST
intervals, The detection of the R-peaks and consequently of the QRS complexes in an
29
ECG signal provides information about the heart rate, the conduction velocity, the
condition of tissues within the heart as well as various abnormalities.
Fig 5.10: Removing wideband noises from an ECG signal by applying the UWT
It supplies evidence for the diagnoses of cardiac diseases. For this reason, it has
drawn considerable attention in the ECG signal processing field. After extracting the
features by performing QRS complex detection, we can analyze the features with other
methods. For example, we can perform heart rate variability (HRV) analysis on the R-R
interval signal to demonstrate the state of the heart and nerve system.
ECG Signal is analyzed using built-in function of Wavelet Transforms to
calculate the heart rate. The normal value of heart beat lies in the range of 60 to 100
beats/minute. A slower rate than this is called bradycardia (Slow heart) and a higher rate
is called tachycardia (Fast heart). If the cycles are not evenly spaced, an arrhythmia may
be indicated. If the P-R interval is greater than 0.2 seconds, it may suggest blockage of
the AV node. Wavelet is found to be superior to the conventional FFT method in finding
the small abnormalities in ECG signals. The equation to calculate heart rate is given
below:
30
Heart Rate = (1/RR Interval) * 60
5.4 Programming of Humidity and Temperature Measurement:
A graphical program is developed in LabVIEW to convert the received voltage
signal to relative humidity. LabVIEW represents the continuous variation of relative
humidity with time graphically. It also keeps record of the relative humidity and
temperature, which can also be stored as numeric value in file and perform as backup.
The software running on the computer is based on the LabVIEW suite. It is a VI
(virtual instrument) that is able to communicate with the measuring circuit and control
the measuring procedure. It is able to record the data acquired in real-time, since the
acquisition frequency is selected to be at a relaxed number of 1000Hz. The LabVIEW
program can afterwards save the measurements into files for later processing. It can also
provide some means of signal processing. For example it can help acquiring maximum
and minimum values automatically for each inhale and exhale which is needed in this
kind of measurements. The measurements are saved in a file format that is easy to open
by typical spreadsheet programs. Also, the LabVIEW suite provides many ways of
drawing the measurements into graphs, thus making it easier to view different
phenomena related to this study.
Special care has been given so that the measuring procedure itself is quite simple
for an operator, where cooperation with a subject is needed. So, the interface is quite
simple in appearance, but nevertheless significant programming has been made on the
LabVIEW so that the result is satisfactory for our purpose in terms of automation and
accuracy.
31
1. “A color spectrographic phonocardiography (CSP) applied to the detection and
characterization of heart murmurs: preliminary results”.- Reza Ramezani
Sarbandi, John D Doyle, Mahdi Navidbakhsh, Kamran Hassani, Hassan Torabiyan
2. COLOR SPECTROGRAPHIC PHONOCARDIOGRAPHY FOR THE
DETECTION AND CHARACTERIZATION OF PEDIATRIC HEART
MURMURS: A CASE study- REZA RAMEZANI SARBANDI, KAMRAN
HASSANI, Department of Biomechanics, Science and Research Branch, Islamic
Azad University Tehran, Iran
3. “Novel method of predicting the optimal atrioventricular delay in patients with
complete AV block, normal left ventricular function and an implanted DDD
pacemaker.” Miki Y, Ishikawa T, Matsushita K, Yamakawa Y, Matsumoto K, Sumita
S, Uchino K, Kimura K, Umemura S.- Department of Medical Science and Cardiorenal
Medicine, Yokohama City University School of Medicine, Yokohama, Japan.
4. Sjöholm Johan, “Development of a Phonocardiography Amplifier”,
Master’s Thesis, spring 1999, Helsinki University of Technology
5. Moss and Adams, “Heart diseases in infants, children, and adolescents”,
Williams & Williams, Baltimore, 1995, pp. 135-146
6. Phonocardiography Signal Processing- By Abbas K. Abbas, Rasha Bassam
1. Jackson L.B., “Digital Filters and Signal Processing”,
Kluwer Academic Publishers, Boston, 1986, pp. 153-167