Table of Contents
Fetching ...

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.

AnyECG: Foundational Models for Multitask Cardiac Analysis in Real-World Settings

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.

Paper Structure

This paper contains 37 sections, 9 equations, 4 figures, 7 tables.

Figures (4)

  • Figure 1: Overall architecture and pre-training pipeline of AnyECG. AnyECG is pre-trained in two steps. The Rhythm Quantizer is pre-trained through proxy tasks to embed morphology, frequency, and demography into tokens (up). Then, the entire AnyECG, along with the ECG Tokenizer, is further pre-trained by predicting the code indices of the masked tokens to learn the semantic relationships between tokens (bottom-left). The Cardio-Sparse approach restricts interactions of patches from the same lead or from the same position across different leads (bottom-right). LN: LayerNorm, Conv: 1D convolution with kernel size of 15.
  • Figure 2: Downstream Task of the ECG Foundation Model. The framework demonstrates fine-tuning AnyECG on heterogeneous ECG datasets, including portable devices, Holter monitors, standard 12-lead recordings, and Event monitor, to address four critical tasks: (1) Anomaly Detection (binary classification of normal vs. abnormal rhythms), (2) Arrhythmia Classification, (3) Ultra-Long ECG Analysis (continuous monitoring for ultra-long ECG event detection), and (4) Corrupted Lead Generation. AnyECG achieves task-specific adaptability through fine-tuning while preserving pre-learned cardiac semantics.
  • Figure 3: Visualization of Corrupted Lead Generation among WGAN (top), CGAN (middle), AnyECG (bottom).
  • Figure 4: Ablation study of Pre-training Phase in Anomaly Detection with AnyECG-L and AnyECG-XL