Inspiration

Health AI models and automated ECG pipelines often fail silently when fed corrupted physiological recordings—baseline wander, muscle noise, 50/60 Hz mains hum, ADC rail clipping, lead-off flatlines, or electrode-motion spikes. Instead of rejecting unreliable input, downstream algorithms confidently output misleading heart-rate or beat metrics.

We built SignalSentry ("Before you trust the signal, test it.") as a local-first, non-diagnostic signal quality and reliability engine that detects, localizes, quantifies, and gates unreliable ECG segments before downstream analysis.


What it does

  • Non-Destructive Ingestion & Preprocessing: Accepts .csv, .txt, and PhysioNet WFDB (.hea + .dat / .zip) recordings locally, auto-infers sampling rates, and keeps the untouched raw waveform separate from a zero-phase Butterworth bandpass (\(0.5\text{--}40\text{ Hz}\)) + optional 50/60 Hz notch filtered copy.
  • Six Explicit Artifact Detectors: Evaluates sliding windows (default \(5\text{ s}\), \(50\%\) overlap) across 20 time-domain, Welch spectral, and beat-consistency features to localize:
    1. Baseline wander (sub-0.55 Hz drift power & median excursion)
    2. High-frequency noise (\(>40\text{ Hz}\) spectral ratio & zero-crossing rate)
    3. Powerline interference (narrowband 50/60 Hz peak vs. flanking spectrum)
    4. Clipping (consecutive samples pinned near min/max rails)
    5. Flatline (rolling sub-window variance collapse)
    6. Transient artifacts (abrupt impulses exceeding the physiological \(P_{97}\) QRS envelope)
  • Documented Quality Scoring & Downstream Reliability Gate: $$S_{\text{seg}} = \text{clip}\Big(0.65 \cdot \max(0,\, 100 - \sum_k P_k) + 0.35 \cdot (100 \cdot p_{\text{clean}}),\; 0,\; 100\Big)$$ Overlapping windows are projected onto non-overlapping \(0.5\text{ s}\) bins (Clean \(80\text{--}100\), Degraded \(50\text{--}79\), Unreliable \(0\text{--}49\)). Users can visually inspect flagged spans on an interactive Canvas waveform explorer and export only quality-verified intervals via the Downstream Analysis Gate.
  • Reproducible Evaluation Lab: Runs recording-disjoint (GroupShuffleSplit) experiments on PhysioNet MIT-BIH Arrhythmia (mitdb) and Noise Stress Test (nstdb) records to measure classification performance, noise sensitivity, feature ablation, and downstream QRS R-peak accuracy across coverage levels.

How we built it

  • Frontend: Next.js (App Router), TypeScript, Tailwind CSS, Recharts, Lucide icons, and a custom high-DPI HTML5 Canvas ECGWaveform renderer with min-max envelope downsampling so QRS peaks are never clipped at full-recording zoom.
  • Backend & Signal Engine: Python, FastAPI, NumPy, SciPy, Pandas, WFDB, scikit-learn (RandomForestClassifier, LogisticRegression, HistGradientBoostingClassifier), and ReportLab for 10-section PDF report generation.
  • Local Persistence & Auth: SQLite (WAL mode via SQLAlchemy) storing analyses, segment features, artifact evidence, immutable evaluation records, and local PBKDF2-SHA256 user/judge sessions—with zero external APIs, zero cloud AI, and zero telemetry.

Real Benchmark Results (MIT-BIH + NSTDB)

Using local PhysioNet mitdb (100, 101, 103, 115, 118, 119) and nstdb (bw, em, ma) records with zero recording leakage between train (\(142\) windows) and test (\(64\) windows):

  • Clean vs. Noisy Classification: LogisticRegression achieved 0.9219 Macro F1 (0.9873 AUROC), RandomForest achieved 0.6744 Macro F1 (0.9541 AUROC, 0.0000 FAR), outperforming the Rule-Based baseline (0.3333 Macro F1, 0.7646 AUROC).
  • Quality Gate Trade-off (Downstream QRS Detection): Rejecting the lowest-quality segments from \(100\% \to 50\%\) coverage improved downstream R-peak \(F_1\) from 0.9521 to 0.9945 (\(+0.0424\)) and reduced Heart Rate MAE from 3.62 bpm to 0.08 bpm.
  • Feature Ablation: Removing spectral frequency features dropped RandomForest AUROC from 0.9541 to 0.7568; removing beat-consistency features dropped Macro F1 from 0.6744 to 0.3816.

Challenges we faced

  1. Separating Normal QRS Peaks from Transient Spikes: Standard MAD-based z-scores flagged legitimate physiological R-peaks because ECGs spend most of each cycle on the flat isoelectric baseline. Switching to a 97th-percentile (\(P_{97}\)) QRS envelope scale cleanly separated true electrode-motion impulses from normal heartbeats.
  2. Cross-Subject Generalization on Real ECGs: Raw voltage amplitude (RMS, std) varies widely across patients in MIT-BIH. Enforcing strict recording-disjoint GroupShuffleSplit revealed that unpruned trees overfit per-subject amplitudes, whereas regularized linear scaling and spectral/beat ratios generalized reliably.
  3. Preserving Peaks When Downsampling: Naive stride decimation misses narrow \(40\text{ ms}\) R-peaks on 30-minute recordings, so we implemented bucketed min-max envelope downsampling across both raw and filtered arrays.

What we learned & Limitations

  • Quality gating measurably protects downstream analytics, turning noisy multi-beat errors into near-zero heart-rate MAE when unreliable segments are excluded.
  • Limitations: SignalSentry is a software reliability gate, not a diagnostic medical device. Default thresholds (80 / 50) are engineering baselines, and severe arrhythmias without recording artifacts can reduce beat-template correlation subscores.

Built With

Share this project:

Updates

Submission history