Skip to content
compressionKIT
User guide
HELIA

ECG (Electrocardiography)

Electrocardiography (ECG/EKG) records the electrical activity of the heart over time using electrodes placed on the skin. It’s the gold standard for cardiac monitoring and is used to detect:

  • Arrhythmias (atrial fibrillation, ventricular tachycardia)
  • Myocardial infarction (heart attack)
  • Conduction abnormalities
  • Heart rate and HRV

The ECG waveform consists of the characteristic P-QRS-T complex, where the sharp QRS complex represents ventricular depolarization.

PropertyValue
Typical sampling rate250–500 Hz
Useful bandwidth0.5–40 Hz
MorphologySharp QRS complexes, smooth P and T waves
Key challengePreserving QRS timing and amplitude

ECG compression in the v1 release has RVQ, SPIHT, and hybrid configurations. The RVQ architecture is tuned for the higher sampling rate and sharper morphology of ECG signals; SPIHT is the clean-signal DSP baseline, and hybrid AI+DSP runs help characterize artifact-heavy regimes.

  • Data source: PTB-XL — 21,799 12-lead ECG recordings
  • Preprocessing: Resample 500 → 256 Hz, Lead II (lead_index=1), layer normalization
  • Model: Conv2D encoder/decoder + EMA RVQ bottleneck (256-entry codebooks)
  • Compression range: 2× – 64× (six golden configs)
  • Loss: MSE + derivative loss (weight 0.1)

See ECG Models (v1.1 exports) for the full results table, architecture breakdown, and training instructions.

ModelCRPRD (%)Cosine
ecg-rvq-02x2×2.500.9997
ecg-rvq-04x4×4.090.9992
ecg-rvq-08x8×7.480.9972
ecg-rvq-16x16×11.180.9936
ecg-rvq-32x32×16.040.9868
ecg-rvq-64x64×22.350.9742
Terminal window
uv run compressionkit golden run ecg-rvq-8x

At higher compression ratios, frame-by-frame reconstruction can introduce visible seams at frame boundaries. compressionkit.evaluation.stitching provides four comparable strategies so the impact can be measured:

MethodWindowNotes
hard_concatrectangular, no overlapbaseline (worst seams)
overlap_addHann, 50 % overlapcanonical default
linear_crossfadetriangular, 50 % overlapLUT-free alternative
tukey_overlap_addTukey(α=0.25)minimal taper knob

The helper seam_discontinuity_ratio reports a first-difference RMS ratio at seam neighbourhoods versus the rest of the signal — a scalar that complements HR/HRV for driving future stitching work.

Enable it in any ECG RVQ YAML under evaluation.stitching: (see configs/ecg_rvq_256hz_32x_golden.yaml), or run it against an already-trained model without retraining:

Terminal window
uv run python scripts/eval_ecg_stitching.py \
--run-dir results/ecg_rvq_256hz_32x_golden \
--duration-sec 30 --num-recordings 10