Personalized Electrocardiographic and HRV Dynamics for Acute Stress Detection: A Leave-One-Subject-Out Benchmark on WESAD
Abstract
Automated classification of acute psychological stress from non-invasive wearable electrocardiography (ECG) is a fundamental problem in physiological computing, affective state recognition, and wearable Internet of Medical Things (IoMT). A central barrier to cross-subject generalization is inter-individual baseline heterogeneity: resting heart rate and basal heart rate variability (HRV) metrics vary widely across individuals due to genetic, cardiorespiratory fitness, and circadian factors, causing uncalibrated global classifiers to degrade substantially on unseen subjects. Furthermore, resource constraints and telemetry-privacy vulnerabilities pose major roadblocks for edge-node wearable deployment. In this work, we present an end-to-end reproducible research pipeline benchmarked across all 15 subjects (N = 15, 445 standardized 60-second windows) of the public Wearable Stress and Affect Detection (WESAD) dataset, paired with a bare-metal embedded microcontroller deployment. Single-lead chest ECG acquired at 700 Hz is conditioned via zero-phase 4th-order Butterworth filtering (0.5–40 Hz), followed by adaptive noise-floor peak prominence detection and physiological interval gating. A selected 8-feature representation capturing heart rate, time-domain variability, and robust spread metrics is transformed via subject-specific relative baseline calibration: X* = (X - Bs) / |Bs|. Key Results and Findings: 1. Generalization Boost: Evaluated under strict 15-fold Leave-One-Subject-Out Cross-Validation (LOSO-CV), baseline-relative calibration elevates classification accuracy from 81.57% to 92.36% (+10.79%) and stress F1-score from 73.03% to 89.03% (+16.00%) over identical unnormalized baselines. 2. Scorecard: At a calibrated decision threshold of tau = 0.35, the primary model achieves an ROC-AUC of 0.9494, PR-AUC of 0.9467, sensitivity of 86.25%, and specificity of 95.79%. A comparative benchmark across six machine learning architectures demonstrates consistent generalization (ROC-AUC > 0.937). 3. Physiological Attribution: Permutation importance and odds ratio analyses indicate that cardiac interval compression (Delta MeanRR) and heart rate acceleration (Delta MeanHR) are the primary contributors to the learned boundary. 4. Bare-Metal ARM Cortex-M4 DSP: Translating this framework to physical hardware, we implement a bare-metal edge processing node on the STM32G474RE (16 MHz HSI). Real-time signal conditioning is executed via an on-chip 5-stage Direct Form II Transposed Biquad IIR filter executing in ~1.87 µs per sample (<0.1% arithmetic CPU utilization at 350 Hz). 5. Telemetry Obfuscation: To safeguard patient privacy against casual wire tapping, an on-chip 32-bit discrete chaotic stream scrambler (Marsaglia Xorshift32 + Golden Ratio Weyl sequence with Nonce-CBC diffusion) executes in 2.0 µs (32 clock cycles), elevating wire Shannon entropy to H = 7.25–7.98 bits/byte while supporting bit-exact (0.000000 V) terminal descrambling. 6. Physical HIL Validation: Continuous hardware-in-the-loop streaming over 15,000 packets demonstrates 100% transmission reliability and zero CRC errors across authorized monitoring and adversarial eavesdropper operating modes.