Sparse Temporal AutoEncoder for ECG Anomaly Detection
Abstract
1. Introduction
- We propose an efficient unsupervised ECG anomaly detection framework that learns exclusively from normal ECG recordings, addressing realistic clinical and monitoring scenarios where abnormal annotations are scarce or unavailable.
- We introduce a scalable representation learning strategy that jointly captures complementary time-domain and time–frequency ECG characteristics using dual TCN encoders, addressing limitations of existing approaches in which these representations are either processed independently or combined using computationally expensive architectures that do not scale well to long ECG sequences.
- We design a hybrid sparse attention mechanism tailored to long ECG sequences, which enables effective modeling of both local and long-range temporal dependencies while substantially reducing the computational cost compared to dense attention mechanisms.
- Extensive experiments on the PTB-XL dataset demonstrate that the proposed framework achieves state-of-the-art unsupervised anomaly detection performance with real-time inference capability, highlighting its suitability for large-scale and continuous ECG monitoring.
2. Related Work
2.1. Unsupervised ECG Anomaly Detection
2.2. Time-Domain and Time–Frequency ECG Representations
2.3. TCN-Based Models for ECG Analysis
2.4. Attention Mechanisms for Long ECG Sequences
3. Methodology
3.1. Problem Description
3.2. STAE Architecture
- 1.
- Spectral signal and Masking-Out procedure:Generate a time–frequency representation from time series using the Short-Time Fourier Transform (STFT) and a masking strategy for both domains that partially obscures the input data. This approach, adapted from [13], encourages the model to focus on learning essential signal patterns from the training dataset.
- 2.
- TCN-based encoders: The STAE model integrates two TCN-based encoders, TCN-Encoder1D and TCN-Encoder2D, designed to extract temporal and spectral representations of ECG signals. These encoders ensure a comprehensive understanding of both time-series and frequency-domain features before fusion for anomaly detection. Both encoders employ Temporal Blocks as their fundamental building units, as illustrated in Figure 2, incorporating the following:Dilated convolutions to augment the receptive field, enabling the model to capture both local variations and long-range dependencies.Chomp layers to maintain temporal alignment and prevent unwanted shifts in feature extraction.Batch Normalization and Dropout to stabilize training and enhance generalization.ReLU activations for efficient non-linear feature transformation.Residual connections to preserve gradient flow and prevent vanishing gradients during deep feature extraction.Where TCN-Encoder1D consists of three stacked Temporal Blocks, producing a feature representation, and TCN-Encoder2D is composed of four stacked Temporal Block Outputs for spectral feature representation.
- 3.
- Sparse cross fusion attention: This process is enhanced through concatenation, sparse attention, and MLP transformations before being passed to the decoder for ECG reconstruction. After passing the input ECG data through both TCN 1D and 2D encoders, the extracted temporal features (from TCN-Encoder1D) and spectral features (from TCN-Encoder2D) are concatenated. This concatenation ensures that information in both the time domain and frequency domain is available for subsequent processing, allowing the model to capture a more comprehensive latent representation. Instead of directly feeding the concatenated features into the decoder, STAE applies a sparse attention mechanism [23], specifically Strided Block Attention, to refine feature interactions. Unlike traditional self-attention, which computes attention across the entire sequence, it suffers from high computational costs. Strided Block Attention divides the input sequence into blocks of a fixed size (block size) and applies attention only within each block using a stride-based mechanism rather than across the whole sequence, which limits the number of attention operations while still capturing essential local dependencies and incorporating global contextual information.
| Algorithm 1 Strided Block Attention with Global Mean-Logit Fusion. |
|
- 4.
- TCN-Decoder1D: In the STAE model, it is responsible for reconstructing the original ECG signal along with its variation (uncertainty estimate), which is later utilized in the anomaly score computation. It employs Temporal Blocks as its core building components, incorporating Dilated Convolutions, Chomp Layers, Residual Connections, and ReLU Activation, as shown in Figure 2, while omitting Batch Normalization and Dropout.
3.3. Training Objective
3.4. Anomaly Score
4. Experiments
4.1. ECG Dataset and Preprocessing
4.2. Evaluation Metrics
4.3. Implementation Details
4.4. Performance Comparison
4.5. Ablation Study on Sparse Attention Mechanisms
4.6. Ablation Study on the Time–Frequency Representation
5. Discussion
6. Conclusions
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Acknowledgments
Conflicts of Interest
References
- Serhani, M.A.; T. El Kassabi, H.; Ismail, H.; Nujum Navaz, A. ECG Monitoring Systems: Review, Architecture, Processes, and Key Challenges. Sensors 2020, 20, 1796. [Google Scholar] [CrossRef] [Scilit] [PubMed]
- Wang, H.; Zhou, Y.; Zhou, B.; Niu, X.; Zhang, H.; Wang, Z. Interactive ECG annotation: An artificial intelligence method for smart ECG manipulation. Inf. Sci. 2021, 581, 42–59. [Google Scholar] [CrossRef] [Scilit]
- Ogunpola, A.; Saeed, F.; Basurra, S.; Albarrak, A.M.; Qasem, S.N. Machine Learning-Based Predictive Models for Detection of Cardiovascular Diseases. Diagnostics 2024, 14, 144. [Google Scholar] [CrossRef] [Scilit] [PubMed]
- Munõz, A.; Torres-Santamaria, J.; Iregui, M.; Romero, E.; Cruz-Roa, A. Comparative Analysis of Deep Neural Network Architectures for Heart Disease Classification in Electrocardiography Signals. In Proceedings of the 2024 20th International Symposium on Medical Information Processing and Analysis (SIPAIM); IEEE: Piscataway, NJ, USA, 2024; pp. 1–4. [Google Scholar]
- Farady, I.; Patel, V.; Kuo, C.C.; Lin, C.Y. ECG Anomaly Detection with LSTM-Autoencoder for Heartbeat Analysis. In Proceedings of the 2024 IEEE International Conference on Consumer Electronics (ICCE); IEEE: Piscataway, NJ, USA, 2024; pp. 1–5. [Google Scholar] [CrossRef] [Scilit]
- Deng, A.; Hooi, B. Graph neural network-based anomaly detection in multivariate time series. In Proceedings of the AAAI Conference on Artificial Intelligence; AAAI Press: Menlo Park, CA, USA, 2021; Volume 35, pp. 4027–4035. [Google Scholar]
- Liu, S.; Zhou, B.; Ding, Q.; Hooi, B.; Zhang, Z.; Shen, H.; Cheng, X. Time series anomaly detection with adversarial reconstruction networks. IEEE Trans. Knowl. Data Eng. 2022, 35, 4293–4306. [Google Scholar] [CrossRef] [Scilit]
- Zong, B.; Song, Q.; Min, M.R.; Cheng, W.; Lumezanu, C.; Cho, D.; Chen, H. Deep autoencoding gaussian mixture model for unsupervised anomaly detection. In Proceedings of the International Conference on Learning Representations, Vancouver, BC, Canada, 30 April–3 May 2018. [Google Scholar]
- Wang, H.; Luo, Z.; Yip, J.W.; Ye, C.; Zhang, M. ECGGAN: A Framework for Effective and Interpretable Electrocardiogram Anomaly Detection. In Proceedings of the 29th ACM SIGKDD Conference on Knowledge Discovery and Data Mining; ACM: New York, NY, USA, 2023; pp. 5071–5081. [Google Scholar]
- Jiang, A.; Huang, C.; Cao, Q.; Wu, S.; Zeng, Z.; Chen, K.; Zhang, Y.; Wang, Y. Multi-scale cross-restoration framework for electrocardiogram anomaly detection. In Proceedings of the International Conference on Medical Image Computing and Computer-Assisted Intervention; Springer: Berlin/Heidelberg, Germany, 2023; pp. 87–97. [Google Scholar]
- Zhou, Y.; Yang, Y.; Gan, J.; Li, X.; Yuan, J.; Zhao, W. Multi-scale Masked Autoencoder for Electrocardiogram Anomaly Detection. arXiv 2025, arXiv:2502.05494. [Google Scholar] [CrossRef] [Scilit]
- Sellam, A.Z.; Benaissa, I.; Taleb-Ahmed, A.; Patrono, L.; Distante, C. MAAT: Mamba Adaptive Anomaly Transformer with association discrepancy for time series. arXiv 2025, arXiv:2502.07858. [Google Scholar] [CrossRef] [Scilit]
- Bui, N.T.; Hoang, D.H.; Phan, T.; Tran, M.T.; Patel, B.; Adjeroh, D.; Le, N. Tsrnet: Simple framework for real-time ecg anomaly detection with multimodal time and spectrogram restoration network. In Proceedings of the 2024 IEEE International Symposium on Biomedical Imaging (ISBI); IEEE: Piscataway, NJ, USA, 2024; pp. 1–4. [Google Scholar]
- Le, M.D.; Rathour, V.S.; Truong, Q.S.; Mai, Q.; Brijesh, P.; Le, N. Multi-module recurrent convolutional neural network with transformer encoder for ECG arrhythmia classification. In Proceedings of the 2021 IEEE EMBS International Conference on Biomedical and Health Informatics (BHI); IEEE: Piscataway, NJ, USA, 2021; pp. 1–5. [Google Scholar]
- Wagner, P.; Strodthoff, N.; Bousseljot, R.D.; Kreiseler, D.; Lunze, F.I.; Samek, W.; Schaeffter, T. PTB-XL, a large publicly available electrocardiography dataset. Sci. Data 2020, 7, 154. [Google Scholar] [CrossRef] [Scilit] [PubMed]
- Chouvarda, I.; Filos, D.; Maglaveras, N. Time-domain analysis of the electrocardiogram. In Cardiovascular Computing—Methodologies and Clinical Applications; Springer: Berlin/Heidelberg, Germany, 2019; pp. 81–102. [Google Scholar]
- Cordero, E.; Giacchi, G.; Rodino, L. A Unified Approach to Time–Frequency Representations and Generalized Spectrograms. J. Fourier Anal. Appl. 2025, 31, 9. [Google Scholar] [CrossRef] [Scilit]
- Thill, M.; Konen, W.; Wang, H.; Bäck, T. Temporal convolutional autoencoder for unsupervised anomaly detection in time series. Appl. Soft Comput. 2021, 112, 107751. [Google Scholar] [CrossRef] [Scilit]
- Yu, L.R.; Lu, Q.H.; Xue, Y. DTAAD: Dual Tcn-attention networks for anomaly detection in multivariate time series data. Knowl.-Based Syst. 2024, 295, 111849. [Google Scholar] [CrossRef] [Scilit]
- Cai, L.; Wu, Q.; Zhang, D.; Liang, Q.; Cong, X.; Huang, X. Multi-Scale Heart Rate Anomaly Detection Based on Temporal Convolutional Networks. In Proceedings of the 2024 WRC Symposium on Advanced Robotics and Automation (WRC SARA); IEEE: Piscataway, NJ, USA, 2024; pp. 327–332. [Google Scholar] [CrossRef] [Scilit]
- Zhang, S.; Fang, Y.; Ren, Y. ECG autoencoder based on low-rank attention. Sci. Rep. 2024, 14, 12823. [Google Scholar] [CrossRef] [Scilit] [PubMed]
- Bai, S.; Kolter, J.Z.; Koltun, V. An empirical evaluation of generic convolutional and recurrent networks for sequence modeling. arXiv 2018, arXiv:1803.01271. [Google Scholar] [CrossRef] [Scilit]
- Child, R.; Gray, S.; Radford, A.; Sutskever, I. Generating long sequences with sparse transformers. arXiv 2019, arXiv:1904.10509. [Google Scholar] [CrossRef] [Scilit]
- Ruff, L.; Vandermeulen, R.A.; Görnitz, N.; Binder, A.; Müller, E.; Müller, K.R.; Kloft, M. Deep Semi-Supervised Anomaly Detection. arXiv 2019, arXiv:1906.02694. [Google Scholar]
- Patro, S.; Sahu, K.K. Normalization: A preprocessing stage. arXiv 2015, arXiv:1503.06462. [Google Scholar] [CrossRef] [Scilit]
- Dalianis, H. Evaluation Metrics and Evaluation. In Clinical Text Mining: Secondary Use of Electronic Patient Records; Springer International Publishing: Cham, Switzerland, 2018; pp. 45–53. [Google Scholar] [CrossRef] [Scilit]
- Vujović, Ž. Classification model evaluation metrics. Int. J. Adv. Comput. Sci. Appl. 2021, 12, 599–606. [Google Scholar] [CrossRef] [Scilit]
- Strodthoff, N.; Wagner, P.; Schaeffter, T.; Samek, W. Deep Learning for ECG Analysis: Benchmarks and Insights from PTB-XL. IEEE J. Biomed. Health Inform. 2021, 25, 1519–1528. [Google Scholar] [CrossRef] [Scilit] [PubMed]
- Loshchilov, I.; Hutter, F. Decoupled weight decay regularization. arXiv 2017, arXiv:1711.05101. [Google Scholar]
- Zheng, Y.; Liu, Z.; Mo, R.; Chen, Z.; Zheng, W.; Wang, R. Task-oriented self-supervised learning for anomaly detection in electroencephalography. In Proceedings of the International Conference on Medical Image Computing and Computer-Assisted Intervention; Springer: Berlin/Heidelberg, Germany, 2022; pp. 193–203. [Google Scholar]
- Clifford, G.D.; Azuaje, F.; McSharry, P. (Eds.) Advanced Methods and Tools for ECG Data Analysis; Artech House Boston: Norwood, MA, USA, 2006; Volume 10. [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 PhysioNet: Components of a new research resource for complex physiologic signals. Circulation 2000, 101, e215–e220. [Google Scholar] [CrossRef] [Scilit] [PubMed]






| Method | AUC | Params (M) | Inference Time (s) |
|---|---|---|---|
| Zheng et al (2022) [30] | 0.757 | - | - |
| BeatGAN (2022) [7] | 0.799 | - | - |
| Jiang et al (2023) [10] | 0.860 | 7.09 | 0.19 |
| TSRNet (2024) [13] | 0.860 | 4.39 | 0.03 |
| MMAE-ECG (2025) [11] | 0.860 | 0.398 | - |
| STAE (Ours) | 0.872 | 1.39 | 0.009 |
| Method | Accuracy | Precision | Recall | F1-Score |
|---|---|---|---|---|
| Jiang et al (2023) [10] | 0.759 | 0.838 | 0.723 | 0.776 |
| TSRNet (2024) [13] | 0.780 | 0.841 | 0.764 | 0.801 |
| STAE (Ours) | 0.801 | 0.848 | 0.798 | 0.822 |
| Attention | AUC |
|---|---|
| Standard self-attention | 0.849 |
| Sparse block attention | 0.826 |
| Sparse strided attention | 0.800 |
| Sparse strided block attention (Ours) | 0.872 |
| Model Variant | AUC | Inference Time (s) |
|---|---|---|
| Time-domain only STAE | 0.781 | 0.003 |
| Full STAE (Ours) | 0.872 | 0.009 |
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. |
© 2026 by the authors. 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.
Share and Cite
Daci, R.; Taleb-Ahmed, A.; Patrono, L.; Distante, C. Sparse Temporal AutoEncoder for ECG Anomaly Detection. Sensors 2026, 26, 1589. https://doi.org/10.3390/s26051589
Daci R, Taleb-Ahmed A, Patrono L, Distante C. Sparse Temporal AutoEncoder for ECG Anomaly Detection. Sensors. 2026; 26(5):1589. https://doi.org/10.3390/s26051589
Chicago/Turabian StyleDaci, Radia, Abdelmalik Taleb-Ahmed, Luigi Patrono, and Cosimo Distante. 2026. "Sparse Temporal AutoEncoder for ECG Anomaly Detection" Sensors 26, no. 5: 1589. https://doi.org/10.3390/s26051589
APA StyleDaci, R., Taleb-Ahmed, A., Patrono, L., & Distante, C. (2026). Sparse Temporal AutoEncoder for ECG Anomaly Detection. Sensors, 26(5), 1589. https://doi.org/10.3390/s26051589

