A Tiny Matched Filter-Based CNN for Inter-Patient ECG Classification and Arrhythmia Detection at the Edge
Abstract
:1. Introduction
- Exploiting the MF interpretation of CNNs to develop a tiny ECG classifier ready for edge deployment.
- Investigate using the first derivative of the ECG signal as an input feature for ECG classification and demonstrate its superiority to using the raw ECG signal.
- Extensively testing the ECG classifier on a raspberry-pi edge device, reporting its performance and benchmarking results, comparing our work to recent state-of-the-art inter-patient ECG classification methods, and showing its competency.
- Validating the model’s generalization capability on several recognized ECG datasets and analyzing the model performance in the presence of noise.
2. Related Work
3. Dataset Preparation and Feature Selection
4. Matched Filter-Based Convolutional Neural Network Classifier
4.1. Matched Filter Interpretation of the Convolutional Neural Network
4.2. Matched Filter-Based ECG Classifier
5. Methods and Tools
5.1. Handling Class Imbalance
5.2. Extraction of Matched Filter Templates
5.3. Workflow and Tools
6. Results and Discussion
6.1. Model Training and Testing Results on the Cloud
6.2. Model Optimization and Testing Results at the Edge
6.3. Comparison with Related Work
6.4. Model Generalization Validation
6.5. Model Performance Analysis in the Presence of Noise
7. Conclusions and Future Work
Funding
Data Availability Statement
Conflicts of Interest
References
- WHO. Cardiovascular Diseases (CVDs). 2021. Available online: https://www.who.int/news-room/fact-sheets/detail/cardiovascular-diseases-(cvds) (accessed on 20 November 2022).
- Luz, E.J.d.S.; Schwartz, W.R.; Cámara-Chávez, G.; Menotti, D. ECG-based heartbeat classification for arrhythmia detection: A survey. Comput. Methods Programs Biomed. 2016, 127, 144–164. [Google Scholar] [CrossRef] [PubMed]
- Berkaya, S.K.; Uysal, A.K.; Gunal, E.S.; Ergin, S.; Gunal, S.; Gulmezoglu, M.B. A survey on ECG analysis. Biomed. Signal Process. Control 2018, 43, 216–235. [Google Scholar] [CrossRef]
- Sahoo, S.; Dash, M.; Behera, S.; Sabut, S. Machine learning approach to detect cardiac arrhythmias in ECG signals: A survey. Irbm 2020, 41, 185–194. [Google Scholar] [CrossRef]
- Farag, M.M. A Self-Contained STFT CNN for ECG Classification and Arrhythmia Detection at the Edge. IEEE Access 2022, 10, 94469–94486. [Google Scholar] [CrossRef]
- Hannun, A.Y.; Rajpurkar, P.; Haghpanahi, M.; Tison, G.H.; Bourn, C.; Turakhia, M.P.; Ng, A.Y. Cardiologist-level arrhythmia detection and classification in ambulatory electrocardiograms using a deep neural network. Nat. Med. 2019, 25, 65–69. [Google Scholar] [CrossRef]
- Farag, M.M. Matched Filter Interpretation of CNN Classifiers with Application to HAR. Sensors 2022, 22, 8060. [Google Scholar] [CrossRef]
- Stankovic, L.; Mandic, D. Convolutional Neural Networks Demystified: A Matched Filtering Perspective Based Tutorial. arXiv 2021, arXiv:2108.11663. [Google Scholar] [CrossRef]
- Chazal, P.d.; O’Dwyer, M.; Reilly, R. Automatic classification of heartbeats using ECG morphology and heartbeat interval features. IEEE Trans. Biomed. Eng. 2004, 51, 1196–1206. [Google Scholar] [CrossRef] [Green Version]
- Moody, G.B.; Mark, R.G. The MIT-BIH arrhythmia database on CD-ROM and software for use with it. In Proceedings of the 1990 Proceedings Computers in Cardiology, Chicago, IL, USA, 23–26 September 1990; pp. 185–188. [Google Scholar]
- Moody, G.; Mark, R. The impact of the MIT-BIH Arrhythmia Database. IEEE Eng. Med. Biol. Mag. 2001, 20, 45–50. [Google Scholar] [CrossRef]
- Ebrahimi, Z.; Loni, M.; Daneshtalab, M.; Gharehbaghi, A. A review on deep learning methods for ECG arrhythmia classification. Expert Syst. Appl. X 2020, 7, 100033. [Google Scholar] [CrossRef]
- Zhang, J.; Liu, A.; Liang, D.; Chen, X.; Gao, M. Interpatient ECG Heartbeat Classification with an Adversarial Convolutional Neural Network. J. Healthc. Eng. 2021, 2021, 9946596. [Google Scholar] [CrossRef]
- Wang, T.; Lu, C.; Sun, Y.; Yang, M.; Liu, C.; Ou, C. Automatic ECG classification using continuous wavelet transform and convolutional neural network. Entropy 2021, 23, 119. [Google Scholar] [CrossRef]
- Mondéjar-Guerra, V.; Novo, J.; Rouco, J.; Penedo, M.G.; Ortega, M. Heartbeat classification fusing temporal and morphological information of ECGs via ensemble of classifiers. Biomed. Signal Process. Control. 2019, 47, 41–48. [Google Scholar] [CrossRef]
- Raj, S.; Ray, K.C. A Personalized Arrhythmia Monitoring Platform. Sci. Rep. 2018, 8, 11395. [Google Scholar] [CrossRef] [Green Version]
- Garcia, G.; Moreira, G.; Menotti, D.; Luz, E. Inter-patient ECG heartbeat classification with temporal VCG optimized by PSO. Sci. Rep. 2017, 7, 1–11. [Google Scholar] [CrossRef]
- Chen, S.; Hua, W.; Li, Z.; Li, J.; Gao, X. Heartbeat classification using projected and dynamic features of ECG signal. Biomed. Signal Process. Control. 2017, 31, 165–173. [Google Scholar] [CrossRef]
- Zhang, Z.; Dong, J.; Luo, X.; Choi, K.S.; Wu, X. Heartbeat classification using disease-specific feature selection. Comput. Biol. Med. 2014, 46, 79–89. [Google Scholar] [CrossRef]
- Lin, C.C.; Yang, C.M. Heartbeat Classification Using Normalized RR Intervals and Morphological Features. Math. Probl. Eng. 2014, 2014, 1–11. [Google Scholar] [CrossRef] [Green Version]
- Bansal, G.; Gera, P.; Bathula, D.R. Template based classification of cardiac arrhythmia in ECG data. In Proceedings of the 2015 IEEE 2nd International Conference on Recent Trends in Information Systems (ReTIS), Kolkata, India, 9–11 July 2015; pp. 337–341. [Google Scholar]
- AAMI. ANSI/AAMI EC57:2012 - Testing and Reporting Performance Results of Cardiac Rhythm and ST Segment Measurement Algorithms. 2012. Available online: https://webstore.ansi.org/Standards/AAMI/ansiaamiec572012ec57 (accessed on 20 November 2022).
- Chen, T.; He, T.; Benesty, M.; Khotilovich, V.; Tang, Y.; Cho, H.; Chen, K.; Mitchell, R.; Cano, I.; Zhou, T. Xgboost: Extreme gradient boosting. R Package Version 0.4-2 2015, 1, 1–4. [Google Scholar]
- Lin, T.Y.; Goyal, P.; Girshick, R.; He, K.; Dollár, P. Focal Loss for Dense Object Detection. arXiv 2018, arXiv:1708.02002. [Google Scholar]
- Kiranyaz, S.; Avci, O.; Abdeljaber, O.; Ince, T.; Gabbouj, M.; Inman, D.J. 1D convolutional neural networks and applications: A survey. Mech. Syst. Signal Process. 2021, 151, 107398. [Google Scholar] [CrossRef]
- Johnson, J.M.; Khoshgoftaar, T.M. Survey on deep learning with class imbalance. J. Big Data 2019, 6, 27. [Google Scholar] [CrossRef] [Green Version]
- Malali, A.; Hiriyannaiah, S.; Siddesh, G.; Srinivasa, K.; Sanjay, N. Supervised ECG wave segmentation using convolutional LSTM. ICT Express 2020, 6, 166–169. [Google Scholar] [CrossRef]
- Arzeno, N.M.; Deng, Z.D.; Poon, C.S. Analysis of first-derivative based QRS detection algorithms. IEEE Trans. Biomed. Eng. 2008, 55, 478–484. [Google Scholar] [CrossRef] [PubMed] [Green Version]
- Tensorflow. Quantization Aware Training with TensorFlow Model Optimization Toolkit—Performance with Accuracy. 2020. Available online: https://blog.tensorflow.org/2020/04/quantization-aware-training-with-tensorflow-model-optimization-toolkit.html (accessed on 20 November 2022).
- Tensorflow. TensorFlow Lite: ML for Mobile and Edge Devices. 2022. Available online: https://www.tensorflow.org/lite/ (accessed on 20 November 2022).
- Coelho, C.N., Jr.; Kuusela, A.; Zhuang, H.; Aarrestad, T.; Loncar, V.; Ngadiuba, J.; Pierini, M.; Summers, S. Ultra low-latency, low-area inference accelerators using heterogeneous deep quantization with QKeras and hls4ml. arXiv 2020, arXiv:2006.10159. [Google Scholar]
- Jacob, B.; Kligys, S.; Chen, B.; Zhu, M.; Tang, M.; Howard, A.; Adam, H.; Kalenichenko, D. Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference. arXiv 2017, arXiv:1712.05877. [Google Scholar]
- Krishnamoorthi, R. Quantizing deep convolutional networks for efficient inference: A whitepaper. arXiv 2018, arXiv:1806.08342. [Google Scholar]
- Tensorflow. TensorFlow Model Optimization Toolkit—Post-Training Integer Quantization. 2019. Available online: https://blog.tensorflow.org/2019/06/tensorflow-integer-quantization.html (accessed on 20 November 2022).
- Rajpurkar, P.; Hannun, A.Y.; Haghpanahi, M.; Bourn, C.; Ng, A.Y. Cardiologist-Level Arrhythmia Detection with Convolutional Neural Networks. arXiv 2017, arXiv:1707.01836. [Google Scholar]
- Goldberger, A.L.; Amaral, L.A.; Glass, L.; Hausdorff, J.M.; Ivanov, P.C.; Mark, R.G.; Mietus, J.E.; Moody, G.B.; Peng, C.K.; Stanley, H.E. PhysioBank, PhysioToolkit, and PhysioNSet: Components of a new research resource for complex physiologic signals. Circulation 2000, 101, e215–e220. [Google Scholar] [CrossRef] [Green Version]
- Laguna, P.; Mark, R.G.; Goldberg, A.; Moody, G.B. A database for evaluation of algorithms for measurement of QT and other waveform intervals in the ECG. In Proceedings of the Computers in cardiology 1997, Lund, Sweden, 7–10 September 1997; pp. 673–676. [Google Scholar]
- Bousseljot, R.; Kreiseler, D.; Schnabel, A. Nutzung der EKG-Signaldatenbank CARDIODAT der PTB über das Internet. Biomed. Tech. Eng. 1995, 40, 317–318. [Google Scholar] [CrossRef]
AAMI Class | MIT-BIH Arrhythmia Types | ||||
---|---|---|---|---|---|
Normal Beat—N | Normal beat (NOR)—N | Right bundle branch block beat (RBBB)—R | Left bundle branch block beat (LBBB)—L | Atrial escape beat (AE)—e | Nodal (junctional) escape beat (NE)—j |
Supraventricular—SVEB | Atrial premature beat (AP)—A | Premature or ectopic supraventricular beat (SP)—S | Nodal (junctional) premature beat (NP)—J | Aberrated atrial premature beat (aAP)—a | |
Ventricular—VEB | Ventricular escape beat (VE)—E | Premature ventricular contraction (PVC)—V | |||
Fusion Beat—F | Fusion of ventricular and normal beat (FVN)—F | ||||
Unknown—Q | Unclassifiable beat (U)—Q | Fusion of paced and normal beat (FPN)—f | Paced beat (P)—/ |
Set | Records | N | SVEB | VEB | F | Q | Total |
---|---|---|---|---|---|---|---|
DS1 | 101, 106, 108, 109, 112, 114, 115, 116, 118, 119, 122, 124, 201, 203, 205, 207, 208, 209, 215, 220, 223, and 230 | 45,866 | 944 | 3788 | 415 | 8 | 51,021 |
DS2 | 100, 103, 105, 111, 113, 117, 121, 123, 200, 202, 210, 212, 213, 214, 219, 221, 222, 228, 231, 232, 233, and 234 | 44,259 | 1837 | 3221 | 388 | 7 | 49,712 |
DS1+DS2 | 90,125 | 2781 | 7009 | 803 | 15 | 100,733 |
Layer | # of Classes = 3 | # of Classes = 4 | # of Classes = 5 | ||||||
---|---|---|---|---|---|---|---|---|---|
Output Shape | Output Shape | Output Shape | |||||||
Params | Params | Params | Params | Params | Params | ||||
Signal Input Layer | (64, 1) | 0 | 0 | (64, 1) | 0 | 0 | (64, 1) | 0 | 0 |
Conv1D Layer | (64, 11) | 363 | 715 | (64, 12) | 396 | 780 | (64, 13) | 429 | 845 |
BatchNormalization | (64, 11) | 44 | 44 | (64, 12) | 48 | 48 | (64, 13) | 52 | 52 |
Activation (Tanh) | (64, 11) | 0 | 0 | (64, 12) | 0 | 0 | (64, 13) | 0 | 0 |
GlobalMaxPooling | (11) | 0 | 0 | (12) | 0 | 0 | (13) | 0 | 0 |
Interval Input Layer | (4, 1) | 0 | 0 | (4, 1) | 0 | 0 | (4, 1) | 0 | 0 |
Dense Layer 1 (Relu) | (4, 32) | 64 | 64 | (4, 32) | 64 | 64 | (4, 32) | 64 | 64 |
Dense Layer 2 (Relu) | (4, 16) | 528 | 528 | (4, 16) | 528 | 528 | (4, 16) | 528 | 528 |
Dense Layer 3 (Relu) | (4, 8) | 136 | 136 | (4, 8) | 136 | 136 | (4, 8) | 136 | 136 |
Flatten | (32) | 0 | 0 | (32) | 0 | 0 | (32) | 0 | 0 |
Concatenate | (43) | 0 | 0 | (44) | 0 | 0 | (45) | 0 | 0 |
Softmax Output Layer | (3) | 132 | 132 | (4) | 180 | 180 | (5) | 230 | 230 |
Total params | 1267 | 1619 | 1352 | 1736 | 1439 | 1855 | |||
Trainable params | 882 | 882 | 932 | 932 | 984 | 984 | |||
Non-trainable params | 385 | 737 | 420 | 804 | 455 | 871 |
Model ID Number | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ||
---|---|---|---|---|---|---|---|---|---|---|---|
Model Variations | Number of Classes | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 4 | 5 | |
Conv1D Trainable | DEF | TRUE | FALSE | DEF | TRUE | TRUE | TRUE | TRUE | TRUE | ||
Layer Kernel Size | 64 | 32 | 32 | 32 | 32 | 32 | 64 | 32 | 32 | ||
Input Feature | DREV | DREV | DREV | BOTH | SIG | DREV | DREV | DREV | DREV | ||
Class Weight Param | SET | SET | SET | SET | SET | NOT | NOT | NOT | NOT | ||
Results | Total Number of Params | 1619 | 1267 | 1267 | 1619 | 1267 | 1267 | 1619 | 1352 | 1420 | |
Number of Trainable Params | 1597 | 1245 | 879 | 1597 | 1245 | 1245 | 1597 | 1330 | 1389 | ||
Training Results % | Training Time (s) | 118.26 | 94.40 | 90.61 | 146.337 | 122.67 | 83.76 | 96.95 | 77.90 | 103.76 | |
Model Accuracy | 99.30 | 98.61 | 93.00 | 96.04 | 96.17 | 99.31 | 99.42 | 98.59 | 98.94 | ||
Average F1-Score | 95.35 | 91.54 | 75.57 | 83.34 | 82.18 | 94.71 | 95.55 | 86.68 | 72.46 | ||
Testing Results % | Model Accuracy | 96.48 | 95.58 | 94.42 | 94.78 | 92.90 | 98.18 | 97.94 | 97.06 | 96.93 | |
Normal Class—N | PREC | 99.38 | 99.47 | 99.39 | 99.57 | 99.67 | 99.00 | 99.06 | 97.73 | 97.96 | |
SEN | 96.96 | 95.86 | 94.67 | 94.91 | 92.98 | 99.10 | 98.31 | 99.14 | 98.85 | ||
F1 | 98.16 | 97.63 | 96.98 | 97.18 | 96.21 | 99.05 | 98.68 | 98.43 | 98.40 | ||
Supraventricular Class—SVEB | PREC | 58.06 | 51.49 | 43.85 | 56.09 | 39.19 | 82.68 | 69.72 | 84.29 | 90.78 | |
SEN | 85.30 | 88.51 | 95.59 | 92.54 | 88.13 | 81.60 | 81.33 | 79.42 | 74.52 | ||
F1 | 69.09 | 65.11 | 60.12 | 69.84 | 54.26 | 82.14 | 75.08 | 81.78 | 81.85 | ||
Ventricular Class—VEB | PREC | 90.20 | 87.93 | 92.23 | 74.10 | 78.07 | 95.63 | 94.53 | 94.99 | 93.39 | |
SEN | 96.34 | 95.65 | 90.31 | 94.32 | 94.47 | 95.00 | 95.47 | 90.13 | 95.13 | ||
F1 | 93.17 | 91.63 | 91.26 | 82.99 | 85.49 | 95.31 | 95.00 | 92.50 | 94.25 | ||
Average Scores | PREC | 82.55 | 79.63 | 78.49 | 76.59 | 72.31 | 92.44 | 78.77 | 69.25 | 56.42 | |
SEN | 92.87 | 93.34 | 93.53 | 93.92 | 91.86 | 91.90 | 91.70 | 67.17 | 53.70 | ||
F1 | 86.81 | 84.79 | 82.79 | 83.34 | 78.65 | 92.17 | 89.59 | 68.18 | 54.90 |
ID | Model | Classes | Features | Classifier | ACC % | N | SVEB | VEB | Macro Average Scores | |||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PREC | SEN | PREC | SEN | PREC | SEN | PREC | SEN | F1 | ||||||
1 | Proposed MF 1 | 3 | ECG Segments + RR | Conv1D MF | 96.48 | 99.38 | 96.96 | 58.06 | 85.30 | 90.20 | 96.34 | 82.55 | 92.87 | 86.81 |
2 | Proposed MF 6 | 3 | ECG Segments + RR | Conv1D MF | 98.18 | 99.00 | 99.10 | 82.68 | 81.60 | 95.63 | 95.00 | 92.44 | 91.90 | 92.17 |
3 | Zhang et al. [13] | 3 | ECG Segments + RR | Conv1D +ADNN | 94.70 | 98.00 | 96.20 | 90.80 | 78.80 | 94.30 | 92.50 | 94.37 | 89.17 | 91.62 |
4 | Wang et al. [14] | 4 | CWT + RR | Conv2D | 99.27 | 98.17 | 99.42 | 89.54 | 74.56 | 93.25 | 95.65 | 70.75 | 67.47 | 68.76 |
5 | Mondéjar-Guerra et al. [15] | 4 | Wavelets + HOS + LBP + RR | Ensemble SVM | 94.50 | 98.20 | 95.90 | 49.70 | 78.10 | 93.90 | 94.70 | 66.35 | 70.28 | 67.08 |
6 | Raj and Ray [16] | 5 | DOST | ABC + LSTSVM | 96.08 | 88.50 | 98.54 | 72.29 | 52.06 | 81.59 | 62.35 | 54.89 | 43.15 | 45.88 |
7 | Garcia et al. [17] | 3 | TVGG + PSO | SVM | 92.40 | 98.00 | 94.00 | 53.00 | 62.00 | 59.40 | 87.30 | 70.13 | 81.10 | 74.60 |
8 | Chen et al. [18] | 3 | DCT + Projection + RR | SVM | 93.10 | 95.40 | 98.40 | 38.40 | 29.50 | 85.10 | 70.80 | 72.97 | 66.23 | 69.18 |
9 | Zhang et al. [19] | 5 | Morph + RR | SVM | 88.34 | 98.98 | 88.94 | 35.98 | 79.06 | 92.75 | 85.48 | 65.65 | 81.53 | 65.46 |
10 | Lin and Yang [20] | 3 | Morph + WT + RR | LDC | 93.00 | 99.30 | 91.60 | 31.60 | 81.40 | 73.70 | 86.20 | 68.20 | 86.40 | 73.43 |
Validation Method | Training Set | Validation Set | Testing Set | Dataset Size | Classes (Distribution) | Test Acc % | Macro Average Scores % | Number of Params | ||
---|---|---|---|---|---|---|---|---|---|---|
Prec | SEN | F1 | ||||||||
Inter-Patient | MIT-BIH DS1 | DS2 | 51,021, 49,712 | N, SVEB, VEB (90,125, 2781, 7009) | 98.18 | 92.44 | 91.9 | 92.17 | 1267 | |
Random Division | St Petersburg INCART Dataset | 175,907 | N, SVEB, VEB (122,941, 1594, 16,010) | 99.43 | 96.03 | 92.20 | 94.00 | 1140 | ||
Random Division | QT Dataset | 14156 | N, SVEB, VEB, F (9593, 609, 933, 189) | 98.76 | 96.35 | 91.19 | 93.60 | 1180 | ||
Random Division | PTB Diagnostic ECG Dataset | 14,550 | Normal, Abnormal (10,505, 4045) | 100.00 | 100.00 | 100.00 | 100.00 | 200 | ||
Cross-Dataset | MIT-BIH DS1 | MIT-BIH DS2 | INCART | 51021, 49712, 175907 | N, SVEB, VEB (213,066, 4375, 23,019) | 97.23 | 82.12 | 81.07 | 81.24 | 1267 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2023 by the author. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Farag, M.M. A Tiny Matched Filter-Based CNN for Inter-Patient ECG Classification and Arrhythmia Detection at the Edge. Sensors 2023, 23, 1365. https://doi.org/10.3390/s23031365
Farag MM. A Tiny Matched Filter-Based CNN for Inter-Patient ECG Classification and Arrhythmia Detection at the Edge. Sensors. 2023; 23(3):1365. https://doi.org/10.3390/s23031365
Chicago/Turabian StyleFarag, Mohammed M. 2023. "A Tiny Matched Filter-Based CNN for Inter-Patient ECG Classification and Arrhythmia Detection at the Edge" Sensors 23, no. 3: 1365. https://doi.org/10.3390/s23031365
APA StyleFarag, M. M. (2023). A Tiny Matched Filter-Based CNN for Inter-Patient ECG Classification and Arrhythmia Detection at the Edge. Sensors, 23(3), 1365. https://doi.org/10.3390/s23031365