AnyECG: Foundational Models for Multitask Cardiac Analysis in Real-World Settings
Yue Wang, Xu Cao, Yaojun Hu, Haochao Ying, Hongxia Xu, Ruijia Wu, James Matthew Rehg, Jimeng Sun, Jian Wu, Jintai Chen
TL;DR
AnyECG introduces a two-stage, self-supervised foundation model tailored for real-world ECG data, addressing heterogeneity, low SNR, and demographic shifts. It combines a Rhythm Quantizer that encodes patches into discrete Rhythm Codes and a Cardio-Sparse Attention mechanism to efficiently handle ultra-long sequences, paired with masked pre-training to learn semantic cardiac event representations. The approach uses a multi-view decoder (morphology, frequency via DWT, and demography) and a vector-quantized codebook to enable robust, transferable ECG representations across diverse datasets and devices. Empirical results across anomaly detection, arrhythmia classification, corrupted lead generation, and ultra-long ECG analysis show AnytimeECG variants outperform state-of-the-art methods, with larger models achieving the strongest overall performance. The work demonstrates the practical potential of large-scale, modality-rich ECG foundation models for robust, device-agnostic cardiac diagnostics in real-world settings.
Abstract
Electrocardiogram (ECG), a non-invasive and affordable tool for cardiac monitoring, is highly sensitive in detecting acute heart attacks. However, due to the lengthy nature of ECG recordings, numerous machine learning methods have been developed for automated heart disease detection to reduce human workload. Despite these efforts, performance remains suboptimal. A key obstacle is the inherent complexity of ECG data, which includes heterogeneity (e.g., varying sampling rates), high levels of noise, demographic-related pattern shifts, and intricate rhythm-event associations. To overcome these challenges, this paper introduces AnyECG, a foundational model designed to extract robust representations from any real-world ECG data. Specifically, a tailored ECG Tokenizer encodes each fixed-duration ECG fragment into a token and, guided by proxy tasks, converts noisy, continuous ECG features into discrete, compact, and clinically meaningful local rhythm codes. These codes encapsulate basic morphological, frequency, and demographic information (e.g., sex), effectively mitigating signal noise. We further pre-train the AnyECG to learn rhythmic pattern associations across ECG tokens, enabling the capture of cardiac event semantics. By being jointly pre-trained on diverse ECG data sources, AnyECG is capable of generalizing across a wide range of downstream tasks where ECG signals are recorded from various devices and scenarios. The experimental results show that AnyECG achieves an average performance improvement of 6% across four critical tasks-anomaly detection, arrhythmia classification, corrupted lead generation, and ultra-long ECG recognition. AnyECG learns common ECG rhythm from data and significantly outperforms state-of-the-art methods in each of these tasks.
