Overview: Electrophysiological Dynamics and Signal Detection Theory
The CardioROC interactive laboratory models the intersection of human visual pattern recognition, cardiac electrophysiology, and the mathematical framework of Signal Detection Theory (SDT). In clinical cardiology, interpreting an Electrocardiogram (ECG) is fundamentally a continuous binary decision task performed under varying signal-to-noise ratios ($SNR$). An observer must scrutinize biological action potentials conducted to surface electrodes, differentiating healthy sinus rhythms from life-threatening morphological anomalies across temporal lead derivations.
The normal cardiac cycle reflects ordered myocardial depolarization and repolarization sequences governed by transmembrane ion fluxes ($\text{Na}^+$, $\text{K}^+$, $\text{Ca}^{2+}$). Depolarization originating at the Sinoatrial (SA) node produces the $P$ wave (atrial activation). The electrical wavefront travels through the Atrioventricular (AV) node, descending through the bundle of His and Purkinje network to trigger the sharp, high-amplitude $QRS$ complex (ventricular depolarization). Subsequent ventricular repolarization manifests as the broader $T$ wave. Morphological deviations—such as Premature Ventricular Contractions (PVCs) exhibiting broadened, aberrant $QRS$ complexes, junctional escape rhythms lacking $P$ waves, or ischemic $T$-wave inversions—require immediate spatial identification.
Rather than evaluating diagnostic skill via simplistic raw percentage accuracy (which is notoriously vulnerable to class imbalance), CardioROC models user responses via a Receiver Operating Characteristic (ROC) curve. The ROC curve maps the True Positive Rate ($TPR$, or Sensitivity) against the False Positive Rate ($FPR$, or $1 - \text{Specificity}$):
$$ TPR = \frac{TP}{TP + FN}, \quad FPR = \frac{FP}{FP + TN} $$
Under the Gaussian binormal model of Signal Detection Theory, internal sensation distributions for Noise $\mathcal{N}(0, \sigma^2)$ and Signal+Noise $\mathcal{N}(\mu, \sigma^2)$ define the observer's discriminability index $d'$ (d-prime):
$$ d' = \Phi^{-1}(TPR) - \Phi^{-1}(FPR) $$
where $\Phi^{-1}(p)$ is the standard normal quantile (probit) function. A higher $d'$ signifies superior physiological discriminability independent of personal response bias (conservatism versus aggressiveness in clinical flagging).
How to Use the CardioROC Diagnostic Simulator & Auto-Pilot Engine
CardioROC operates as a continuous, real-time clinical telemetry stream. Mastery of the interface involves spatial beat acquisition, visual timing, and parameter tuning:
1. Spatial Waveform Targeting & Live Visual Feedback:
The top monitor displays a continuous, scrolling Lead II rhythm strip. The simulator performs direct spatial hit-testing on the exact beat you tap:
- Targeting Abnormal Beats: When you spot an arrhythmia (such as a missing $P$-wave, a wide distorted PVC, or an inverted $T$-wave), tap or click directly on that waveform. A successful identification logs a True Positive ($TP$, Hit), illuminating the beat with a bright GREEN target reticle, a floating score indicator, and an affirmative audio chime.
- Avoiding False Alarms: Tapping a healthy, normal sinus beat triggers an immediate RED warning reticle, penalizing your score and logging a False Positive ($FP$).
- Correct Rejections vs. Misses: Letting a normal beat travel off the left edge untouched logs a True Negative ($TN$) with an exit verification toast. Conversely, failing to tag an abnormal beat before it exits off-screen registers a False Negative ($FN$, Miss) with a red warning badge at the monitor exit boundary.
2. Conservative Clinical AI (Auto-Pilot Mode):
Tapping the 🤖 AUTO-PILOT button activates an automated diagnostic agent. Unlike a reckless coin-flipper, the AI models a disciplined clinical physician adhering to Primum non nocere ("First, do no harm"). When noise is low ($\sigma_n^2 \le 10$), the AI operates with near-perfect diagnostic precision ($d' > 3.5$). As you elevate the noise slider toward $100$, the physiological signal is submerged by baseline wander and muscle tremor. The AI detects that evidence has fallen below the confidence threshold and refuses to make reckless guesses, letting its positive call rate drop to zero ($TP \to 0, FP \to 0$). Its operational point gracefully shifts to $(0,0)$, demonstrating zero diagnostic confidence without generating dangerous false alarms.
3. Telemetry Sweep Speed Dynamics:
In standardized clinical electrocardiography, paper records scroll at calibrated velocities (typically $25\text{ mm/s}$ for standard diagnostics or $50\text{ mm/s}$ to expand complex tachyarrhythmias). CardioROC decouples the visual sweep velocity from screen DPI and frame rates, advancing the buffer according to exact physical time deltas:
$$ \Delta x = v_{\text{sweep}} \cdot \Delta t $$
Use the Sweep Speed (mm/s) slider to adjust the scrolling speed from a relaxed $15\text{ mm/s}$ to a rapid $50\text{ mm/s}$, testing your rapid diagnostic reflex under clinical stress conditions.
4. Real-Time ROC Tracking:
The lower panel displays the evolving ROC curve and live operational state. The glowing cyan node represents your empirical $(FPR, TPR)$ operating point. As your decisions accumulate, the system updates your empirical sensitivity index $d'$ and calculates the theoretical Area Under the Curve ($AUC$):
$$ AUC = \Phi\left(\frac{d'}{\sqrt{2}}\right) $$
A pure guesswork strategy yields $d' \approx 0.0$ ($AUC = 0.500$, along the diagonal chance line). High diagnostic precision pushes the curve upward into the top-left corner, achieving $d' > 2.5$ ($AUC > 0.960$).
Technical Details & Mathematical Engine
The CardioROC simulation engine is built entirely with vanilla JavaScript, HTML5 Canvas, and the Web Audio API, adhering strictly to deterministic signal processing pipelines:
Continuous Ring-Buffer Waveform Synthesis: Instead of disjointed waveform segments, the simulator maintains a real-time temporal ring buffer. Individual beats are generated by evaluating modular mathematical components across phase angle $\theta(t)$:
$$ V_{\text{ECG}}(t) = V_P(t) + V_{QRS}(t) + V_T(t) + \eta_{\text{EMG}}(t) + V_{\text{wander}}(t) $$
where the $R$-wave peak of the $QRS$ complex is modeled by a sharp Gaussian distribution $A_R \exp\left(-\frac{(t - \mu_R)^2}{2\sigma_R^2}\right)$, and the $P$ and $T$ waves utilize shaped sinusoids. White Gaussian noise $\eta_{\text{EMG}}(t) \sim \mathcal{N}(0, \sigma_n^2)$ is generated via the Box-Muller transform:
$$ Z = \sqrt{-2\ln U_1} \cos(2\pi U_2) $$
Combined with a low-frequency respiratory drift function $V_{\text{wander}}(t) = A_{\text{wander}} \sin(2\pi f_r t)$, this provides authentic multi-component artifact synthesis.
Robust Probit Approximation & SDT Calculation: To compute $d'$ in real time without numerical singularities at $TPR, FPR \in \{0, 1\}$, the system applies the Haldane-Anscombe continuity correction:
$$ TPR_{\text{adj}} = \frac{TP + 0.5}{(TP + FN) + 1.0}, \quad FPR_{\text{adj}} = \frac{FP + 0.5}{(FP + TN) + 1.0} $$
The inverse cumulative standard normal distribution $\Phi^{-1}(p)$ is evaluated using Acklam's rational minimax approximation, maintaining an absolute relative error $\epsilon < 1.15 \times 10^{-9}$ across all probabilities.
Conservative Decision Criterion Formula: When the Auto-Pilot AI evaluates an incoming cardiac cycle, its hit probability $P(\text{Hit})$ and false alarm probability $P(\text{FA})$ scale with signal confidence across $[0, 100]$:
$$ P(\text{Hit}) = \max\left(0.0, 0.98 \cdot \left(1 - \frac{\sigma_n^2}{100}\right)\right) $$
$$ P(\text{FA}) = \max\left(0.0, 0.02 \cdot \left(1 - \frac{\sigma_n^2}{100}\right)\right) $$
At $\sigma_n^2 = 100$, $P(\text{Hit}) = P(\text{FA}) = 0.00$, mathematically modeling the refusal to guess in zero-evidence environments.
Future Directions & Clinical Extensions
CardioROC serves as an expandable foundation for biomedical signal processing education. Planned future milestones include:
- 12-Lead Vectorcardiography: Implementing simultaneous multi-channel telemetry ($I, II, III, aVR, aVL, aVF, V_1\text{--}V_6$) with interactive lead switching and Einthoven limb triangle vector calculations.
- Arrhythmia Library Expansion: Introducing complex rhythm disturbances, including Atrial Fibrillation (chaotic fibrillatory $f$-waves), Wolff-Parkinson-White syndrome (delta waves), and hyperkalemic peaked $T$ waves.
- Real-time Convolutional Neural Network (CNN) Benchmarking: Running a lightweight in-browser ONNX/WebGPU neural network alongside the human user to visualize human vs. machine ROC curves in real time.
Related BioniChaos Simulations