Support Vector Machine and Artificial Neural Network Implementation
in Embedded Systems for Real Time Arrhythmias Detection
Andr
´
es Orozco-Duque
1
, Santiago R
´
ua
1
, Santiago Zuluaga
1
, Alfredo Redondo
1
, Jose V. Restrepo
2
and John Bustamante
1
1
Centro de Bioingenieria, Universidad Pontificia Bolivariana, Cr. 1 70-1, Medell
´
ın, Colombia
2
Grupo de Investigaci
´
on en Microelectr
´
onica, Universidad Pontificia Bolivariana, Cr. 1 70-1, Medell
´
ın, Colombia
Keywords:
Arrhythmias, Artificial Neural Network, ECG Signal, FPGA, Microcontroller, Support Vector Machine.
Abstract:
This article presents the development and implementation of an artificial neural network (ANN) and a support
vector machine (SVM) on a 32-bit ARM
R
Cortex
R
M4 microcontroller core from Freescale Semiconductor
and on a FPGA Spartan
R
6 from Xilinx
TM
, looking for real-time detection of ventricular tachycardia (VT)
and ventricular fibrillation (VF). They were compared in terms of accuracy and computational cost. A Fast
Wavelet Transform (FWT) was used, and the energy in each sub-band frequency was calculated in the feature
extraction stage. For the training and validation algorithms, labeled signals from MIT-BIH database with
normal sinus rhythm, VF and VT in a time window of 2 seconds were used. Test results achieve an accuracy
of 99.46% for both ANN and SVM with execution time less than 0.6 ms in microcontroller and 30 µs in FPGA
for ANN and less than 30 ms in a microcontroller for SVM. The test was done with a 32 MHz clock.
1 INTRODUCTION
Wearable Cardiac devices are currently used to moni-
tor the ECG signal in patient with high cardiac risk
and detect arrhythmias in real-time (Oresko et al.,
2010). Pre-processing, feature extraction and classi-
fication are the main processing stages in this kind of
devices.
Ventricular Fibrillation (VF) is considered a fatal
arrhythmia and Ventricular Tachycardia (VT) may in-
duce VF over time. For this reason, a real-time car-
diac monitoring systems must to include a module
for the detection of these arrhythmias. To detect VT
and VF in real-time, various algorithms have been de-
veloped, such as fuzzy similarity-base approximate
entropy (Xie et al., 2011), Wavelet based features
(Balasundaram et al., 2011), phase space reconstruc-
tion (S
´
aenz and Bustamante, 2009), feature selec-
tion with Support Vector Machine (SVM) (Alonso-
Atienza et al., 2012) and Artificial Neural Network
(ANN) (Valenza et al., 2008).
For implementing of these algorithms in embed-
ded systems such as FPGA or microcontroller, an
analysis of the computational cost is necessary. This
paper compares the accuracy of two machine learning
methods: ANN and SVM. In order to measure and
compare the computational cost, both algorithms
were implemented in a 32-bit microcontroller, further
an ANN was implemented in the FPGA.
2 METHODOLOGY
2.1 Fast Wavelet Transform
For the pre-processing and feature extraction stage,
the Fast Wavelet Transform (FWT) was used. FWT
works like an array of high pass h(n) and low pass
l(n) filters where coefficients depend of the mother
wavelet selected and with cut frequency set in the
middle of the input signal’s spectrum (Benedetto,
1999). The block diagram of FWT is shown in the
Figure 1.
FWT was developed on the FPGA. In this im-
plementation, is important to synchronize the coef-
ficients of the different levels because the delay in-
creases as the level of decomposition.
Symlets 8 was selected as mother wavelet accor-
ding to (Singh and Tiwari, 2006).
310
Orozco-Duque A., Rúa S., Zuluaga S., Redondo A., V. Restrepo J. and Bustamante J..
Support Vector Machine and Artificial Neural Network Implementation in Embedded Systems for Real Time Arrhythmias Detection.
DOI: 10.5220/0004232003100313
In Proceedings of the International Conference on Bio-inspired Systems and Signal Processing (BIOSIGNALS-2013), pages 310-313
ISBN: 978-989-8565-36-5
Copyright
c
2013 SCITEPRESS (Science and Technology Publications, Lda.)
h(n)
2
l(n)
2
cD3(n)
cA
3(n)
cA
1(n)
cD2(n)
cD
1(n)
x(n)
Decomposition
level 1
Decomposition
level 2
Decomposition
level 3
h(n)
2
l(n)
2
h(n)
2
l(n)
2
cA
2(n)
Figure 1: Block diagram of FWT.
2.2 Sub-bands Wavelet Energy
The ECG signal was segmented in two seconds time
window. The energy contribution of the Wavelet’s
sub-bands coefficients were extracted to create the
feature vector. Wavelet coefficients of decomposition
level cD3, cD4 and cD5, and approximation level A5
were selected. Other coefficients were discarded be-
cause they represent less than 2% of the total signal’s
energy.
2.3 Signal Database
MIT-BIH Malignant Ventricular Arrhythmia
Database and MIT-BIH Normal Sinus Rhythm
Database (Goldberger et al., 2000) were used. Seven
different labeled signals of normal ECG, five signals
with VT and 4 with VF were downloaded. 1163
segments with VT were extracted, 1292 with VF
and 813 with normal rhythm. 60 % of the segments
were located in the training group, 20 % in the cross
validation group and the last 20 % in the testing
group.
2.4 Hardware
A Kinetis Microcontroller from Freescale
Semiconductors
TM
was selected for its low-power
performance with an ARM
R
Cortex M4 core with
Floating Point (FP) unit and DSP functions.
The selected FPGA was a Spartan
R
6 XC6SLX9
from Xilinx
TM
for its balance of low cost, and low
power consumption. It has 9152 logic cells, 1430
slices, 11440 flip-flops, 32 of 18kb Block RAM and
16 DSP slices.
3 ALGORITHMS
IMPLEMENTATION
3.1 Artificial Neural Network
A feed-forward ANN with four layers was imple-
mented: one input layer with four neurons, two hid-
den layers each with three neurons, and one output
layer with only one neuron. This structure was se-
lected after different test with a cross validation set
using MATLAB
R
. Each neuron of the input layer
corresponds to one of the energy sub-bands obtained
from FWT. The output layer classifies between nor-
mal rhythm and VT/VF (Figure 2).
Figure 2: ANN structure designed for VT/VF detection.
The ANN was trained in MATLAB using the
back-propagation algorithm of the Neural Network
Toolbox. The model obtained including the bias ma-
trix is:
W
layer1
=
13.6942 0.4326 0.0403 0.0823 0.7342
2.5106 4.631 0.2119 0.6442 0.4936
9.6895 0.9629 0.6307 2.0219 0.2652
(1)
The weights matrix for layer two is:
W
layer2
=
17.2050 1.4175 2.4593 6.1326
5.3072 0.8866 8.6401 4.4102
1.8915 6.6518 4.4547 4.4037
(2)
The output layer is:
W
layout
= [
3.0015 3.8829 2.2100 3.0934
] (3)
In the matrix W
layer1
, W
layer2
and W
layout
, the
columns represent the weights of each input of a neu-
ron, each row represent one neuron in the layer.
The pureline activation function was used in the
output layer and sigmoid function was used in the hid-
den layers.
The ANN was implemented in the FPGA using
System Generator
TM
from Xilinx
TM
. This software al-
lows the use of the Simulink
TM
development environ-
ment to designing high-performance DSP systems.
FPGA allows parallel processing by reconfiguring the
hardware according to the program. Figure 3 shows
the architecture of one neuron implemented in System
Generator
TM
.
Sigmoid activation function is given by
P(t) =
1
1 + e
t
(4)
SupportVectorMachineandArtificialNeuralNetworkImplementationinEmbeddedSystemsforRealTimeArrhythmias
Detection
311
Figure 3: Artificial neuron implemented in System Genera-
tor.
To implement this function in the FPGA a step-by
step approximate function was used. The sigmoid
approximate activation function used was:
a =
0, x < 0
0.1572, 2 x < 1
0.334, 1 x < 0
0.5, x = 0
0.5734, 0 < x 0.8
0.7356, 0.8 < x < 1.5
0.8779, 1.5 x 2.5
0.9509, 2.5 < x 3.5
1, 3.5 < x
(5)
This was implemented using a ROM block, which
stored the outputs of the activation function. The sys-
tem was designed to select the address of the ROM
memory according with the input of the activation
function.
The ANN model was implemented using Sys-
tem Generation with the artificial neuron as shown in
Figure 3.
In the microcontroller, the algorithm was imple-
mented on C. The CMSIS 2.0 library was used in the
ANN implementation, which has more than 60 DSP
functions including fixed point and single-precision
floating point math. Using this library is possible to
implement the prediction algorithm of ANN with ma-
trix operations as shown in the following code:
arm_mat_mult_f32(&L1,&C,&NL1);
arm_mat_add_f32(&NL1,&B1,&NL1);
activation_sigmoid(&ANN_layer1[0],NN_layer1);
Where
&C
,
&L1
,
&B1
,
&NL1
are pointers to feature
matrix, weights matrix of layer 1, bias vector for layer
1 and ANN structure for neurons of layer 1 respec-
tively. Arm mat mult and arm mat add are matrix
operations of CMSIS 2.0 and activation sigmoid is
a function developed by the authors. This piece of
code calculates the propagation through layer 1 of the
ANN. To implement the complete feed-forward pro-
pagation algorithm, the code is the same but with ite-
rations according to the number of layers.
The sigmoid activation function was implemented
C using “math.h” library, it was not necessary to use
the approximation as with the FPGA.
3.2 Support Vector Machine (SVM)
A SVM prediction algorithm was implemented in the
microcontroller. SVM is a supervised learning ma-
chine method which selects the hyperplane that di-
vides the training set into two classes so that maxi-
mizes distance of each set (Steinwart and Christmann,
2008). In a SVM, given X, an input vector with m di-
mensions, a new feature vector f R
m1
is computed
depending of the proximity to vectors in the training
set. To compute the proximity, a Gaussian kernel ex-
pression:
k
x, x
= e
xx
2
2σ
2
(6)
was used. The prediction is calculated with the in-
ner product between the new feature vector f and the
weights (alphas) of the model θ
T
, where the predic-
tion is 1, if θ
T
f 0.
The SVM training was executed in MATLAB with
the training set referenced in section 2.3 using a sim-
plified version of SMO algorithm from the Learn-
ing Machine online course of Andrew Ng from Stan-
ford University. The regularization parameter and the
σ parameter of the Gaussian kernel were optimized
using the cross validation set to avoid high bias or
high variance.
The SVM prediction function was implemented in
a microcontroller on C language using CMSIS 2.0 li-
brary and similar methodology as on the ANN imple-
mentation.
The SVM implemented in this work is a four di-
mensions machine.
4 RESULTS AND DISCUTION
Accuracy of the detection algorithm in the test set was
99.46% for both, ANN and SVM, measure was done
after implementation on FPGA and Microcontroller.
ANN was implemented in both, 32 bit microcon-
troller and FPGA, table 1 shows the execution times.
Table 1: ANN prediction time.
Embedded System Time (µ s)
Microcontroller (32Mhz) 600
FPGA (32Mhz) 0.30
SVM was implemented only in the microcon-
troller. Table 2 shows the execution times of SVM
and ANN in the microcontroller.
BIOSIGNALS2013-InternationalConferenceonBio-inspiredSystemsandSignalProcessing
312
Table 2: ANN and SVM prediction time in microcontroller.
Algorithm Time (ms)
ANN 0.6
SVM 30
SVM and ANN can reach same accuracy; how-
ever prediction algorithm for SVM takes about 50
times more than ANN in the same microcontroller.
This is shown in Table 2. For this application ANN
is better because the execution time is less than SVM
with the same accuracy.
In this application, there is a time limit of two sec-
onds determined by the time windows used in the fea-
ture extraction stage. Table 2 show that VF/VT could
be detected in real time using both SVM and ANN.
The support vector machine was only imple-
mented in the microcontroller. The implementation of
SVM in an FPGA requires the realization of complex
mathematical operations for calculating the Gaussian
kernel. Its implementation in the FPGA using Sys-
tem Generation is difficult because the multiplications
consumes all the resources of DSP-slices which are
limited. It is necessary the used of a math processor
tha could be implemented in a FPGA.
The microcontroller’s advantages are the low
power consumption and the additional peripherals.
Furthermore, it allows easy programming of complex
mathematical operations because is programmed in C.
Currently, the authors are working on multiclass
classifier that will allow to differentiate between VT
and VF and to detect other types of arrhythmias, such
as premature atrial contractions, premature ventricu-
lar contractions, atrial fibrillation, atrial flutter, among
others. Therefore the develop of robust classifier in
real time is necessary. A mixed platform with a mi-
crocontroller and parallel co-processors implemented
on a FPGA has been developed to implement a real-
time pre-processing, feature extraction and classifica-
tion system.
5 CONCLUSIONS
In this work, two machine learning methods were im-
plemented in an embedded system: SVM and ANN.
Both methods can be used to detect VT/VF in real-
time with FWT scales energy as features and 2 sec-
onds windows analysis.
SVM and ANN are powerful tools for arrhythmias
classification and could be real-time implemented in
both, microcontroller and FPGA. ANN is faster than
SVM, for VT/VF detection is better use ANN because
it has lower execution time than SVM, nevertheless
SVM was implemented considering future work with
other types of arrhythmias, where a robust classifier
will be necessary.
REFERENCES
Alonso-Atienza, F., Rojo-
´
Alvarez, J. L., noz, A. R.-M.,
Vinagre, J. J., Garc
´
ıa-Alberola, A., and Camps-Valls,
G. (2012). Feature selection using support vector ma-
chines and bootstrap methods for ventricular fibril-
lation detection. Expert Systems with Applications,
39(2):1956 1967.
Balasundaram, K., Masse, S., Nair, K., Farid, T., Nan-
thakumar, K., and Umapathy, K. (2011). Wavelet-
based features for characterizing ventricular arrhyth-
mias in optimizing treatment options. In Engineer-
ing in Medicine and Biology Society,EMBC, 2011 An-
nual International Conference of the IEEE, pages 969
–972.
Benedetto, J. J. (1999). Sampling theory and wavelets. In
Signal Processing for Multimedia, pages 19–33.
Goldberger, A. L., Amaral, L. A. N., Glass, L., Hausdorff,
J. M., Ivanov, P. C., Mark, R. G., Mietus, J. E., Moody,
G. B., Peng, C.-K., and Stanley, H. E. (2000). Phys-
iobank, physiotoolkit, and physionet. Circulation,
101(23):e215–e220.
Oresko, J., Jin, Z., Cheng, J., Huang, S., Sun, Y., Duschl,
H., and Cheng, A. (2010). A wearable smartphone-
based platform for real-time cardiovascular disease
detection via electrocardiogram processing. Informa-
tion Technology in Biomedicine, IEEE Transactions
on, 14(3):734 –740.
S
´
aenz, J. F. and Bustamante, J. (2009). Algoritmo com-
putacional para la detecci
´
on de fibrilaci
´
on ventricular
basado en la t
´
ecnica de reconstrucci
´
on de espacio de
fases con tiempo de retardo variable. Revista de la
Federaci
´
on Argentina de Cardiolog
´
ıa, 38:60–65.
Singh, B. N. and Tiwari, A. K. (2006). Optimal selection of
wavelet basis function applied to ecg signal denoising.
Digital Signal Processing, 16(3):275 287.
Steinwart, I. and Christmann, A. (2008). Support vector
machines. Springer.
Valenza, G., Lanata, A., Ferro, M., and Scilingo, E. (2008).
Real-time discrimination of multiple cardiac arrhyth-
mias for wearable systems based on neural networks.
In Computers in Cardiology, 2008, pages 1053 –1056.
Xie, H.-B., Zhong-Mei, G., and Liu, H. (2011). Classifi-
cation of ventricular tachycardia and fibrillation using
fuzzy similarity-based approximate entropy. Expert
Systems with Applications, 38(4):3973 3981.
SupportVectorMachineandArtificialNeuralNetworkImplementationinEmbeddedSystemsforRealTimeArrhythmias
Detection
313