eess.SPMar 19, 2026

Stress Classification from ECG Signals Using Vision Transformer

Authors: Zeeshan Ahmad, Naimul Khan

Abstract

Vision Transformers have shown tremendous success in numerous computer vision applications; however, they have not been exploited for stress assessment using physiological signals such as Electrocardiogram (ECG). In order to get the maximum benefit from the vision transformer for multilevel stress assessment, in this paper, we transform the raw ECG data into 2D spectrograms using short time Fourier transform (STFT). These spectrograms are divided into patches for feeding to the transformer encoder. We also perform experiments with 1D CNN and ResNet-18 (CNN model). We perform leave-onesubject-out cross validation (LOSOCV) experiments on WESAD and Ryerson Multimedia Lab (RML) dataset. One of the biggest challenges of LOSOCV based experiments is to tackle the problem of intersubject variability. In this research, we address the issue of intersubject variability and show our success using 2D spectrograms and the attention mechanism of transformer. Experiments show that vision transformer handles the effect of intersubject variability much better than CNN-based models and beats all previous state-of-the-art methods by a considerable margin. Moreover, our method is end-to-end, does not require handcrafted features, and can learn robust representations. The proposed method achieved 71.01% and 76.7% accuracies with RML dataset and WESAD dataset respectively for three class classification and 88.3% for binary classification on WESAD.

Figures & tables

Explore similar work

Sep 14, 2026

On the role of the tokenizer in ECG transformer models

Tokenization determines both the physiological content presented to an ECG Transformer and the sequence over which attention operates. We compare eight tokenization strategies across Transformer, Informer, Reformer, and FEDformer on the nine-label CPSC2018 classification task. The input projection and principal backbone capacity are controlled to isolate the effect of token construction. Median-beat and HeartLang tokenization achieve mean macro-AUCs of 0.893 and 0.889 across the four backbones, compared with 0.822 and 0.824 for point-wise and patch-wise tokenization. Pooling the two physiology-aware representations yields an 8.2% relative improvement in macro-AUC. They also reduce mean sequence length from 1,250 to 158 tokens and mean peak training memory from 5.21 to 0.27 GB. The results show that aligning tokens with ECG morphology can improve both predictive performance and memory efficiency without increasing backbone capacity. The source code is available on https://github.com/LeeJarvis996/ecg_tokenizer.
Aug 27, 2026

Interpretable Stress Detection from ECG Signals Using Motif-Based Anomaly Analysis

Stress detection using physiological signals has gained significant attention due to its impact on both physical and mental health. While existing approaches based on machine learning and deep learning achieve strong predictive performance, they often rely on black-box models and fail to capture individual variability in physiological responses. In this work, we propose an interpretable and personalized framework for stress detection using electrocardiogram (ECG) signals based on motif discovery and Matrix Profile analysis. Instead of training a classifier, the method learns subject-specific baseline cardiac behavior by extracting recurring heartbeat patterns (motifs) from ECG signals. Stress is then detected as a deviation from these baseline patterns using a distance-based anomaly score. Experiments are conducted on the WESAD dataset using a carefully designed train-validation-test protocol to ensure reliable evaluation. The results show that the proposed approach can effectively detect stress for several subjects while providing clear interpretability through direct comparison of ECG patterns. However, the performance varies across individuals due to differences in physiological responses, with some subjects exhibiting minimal morphological changes under stress. Additional analysis incorporating heart rate variability (HRV) features reveals that while HRV can improve performance in certain cases, its contribution is not consistent across all subjects. These findings highlight the importance of personalization and interpretability in physiological stress detection and demonstrate that motif-based approaches provide a meaningful alternative to black-box models, while also revealing inherent limitations due to inter-subject variability.
Aug 12, 2026

A Vision Transformer for ECG-Based Detection of Left Ventricular Systolic Dysfunction Across Multiple Clinical Sites

Reduced left ventricular ejection fraction (LVEF) is frequently asymptomatic and often detected only after advanced heart failure develops. Electrocardiograms are recorded routinely yet underused for this condition, because reduced LVEF has no single diagnostic waveform. We trained an ensemble of vision transformers from scratch to detect reduced LVEF (≤\leq40%) from 12-lead ECGs, analyzing each heartbeat individually, using 10,142 patients across seven sites in three US health systems. In a held-out external cohort of 4,092 patients from three geographically independent US clinical sites at a real-world reduced-LVEF prevalence of 8.72%, the model achieved an AUROC of 0.88 (95% CI 0.86-0.89), sensitivity 81.2%, specificity 81.0%, and negative predictive value 97.8%. Sensitivity remained high across sex, race, ethnicity, and comorbidity subgroups, while specificity was lower in older patients and those with atrial fibrillation or cardiomyopathy. Beat-level attention maps provided interpretability into the model's predictions, showing consistent focus on the QRS complex rather than the P wave. These findings support the potential of routine ECGs as a scalable first-pass triage step to identify patients who should undergo echocardiography for reduced ejection fraction across diverse patient populations.