SHC vNext QR proof of concept
SHA-256 Extension · 0x00 0 WASM imports · 0 floats Lossless 1D signal codec (LPC + Golomb-Rice)

ECG Rhythm Strip

100% bit-exact lossless compression of 10-second human ECG rhythm strips (PhysioNet MIT-BIH & European ST-T) expanding to FHIR R4 Observation.valueSampledData.

WASM module42,742 Becg-strip.wasm
Card sizes1,406–2,128 Bacross 8 sample records
Max FHIR ÷ card8×deterministic FHIR R4 output
Best QR versionVersion 28-Lup to Version 35-L

Try live in Viewer (afib) Download WASM (by hash) View model.d.ts

Quick launch any sample record in the universal viewer:

nsr afib bigeminy lbbb paced vtach av-block stemi

Card header
0x00 followed by the 32-byte SHA-256 digest of the WebAssembly module (35 bytes total card framing including the 2-byte SHA-256 check)
SHA-256
b37fa36f53a0e4818c8456be8ee7fe0532806a20fb35772607f38938e6ffb75c (download by hash)
WASM exports
memory, shc_alloc, shc_decode, shc_encode (0 host imports)
Machine-readable files
model.d.ts · codecs/ecg-strip/ecg-strip.wasm · Source on GitHub

Sample records & benchmarks (8)

Each sample record below was encoded at build time by ecg-strip.wasm, wrapped in a SHA-256 content-addressed card (0x00 || sha256), and decoded back into a FHIR R4 Bundle. Click any record name to open its live QR card in the universal viewer.

RecordCard & QR (L / M)FHIR JSONDEFLATE (L9)FHIR ÷ cardDownloads
nsrNormal sinus rhythm (~74 bpm, MIT-BIH 100) 1,859 BVersion 32-L / Version 37-M 15,656 B3 entries 3,978 Bfits none 8× model.json · card.txt · fhir.json
afibAtrial fibrillation with irregular R-R (MIT-BIH 201) 1,848 BVersion 32-L / Version 37-M 15,568 B3 entries 4,044 Bfits none 8× model.json · card.txt · fhir.json
bigeminyVentricular bigeminy with alternating PVCs (MIT-BIH 106) 2,047 BVersion 34-L / Version 39-M 15,457 B3 entries 4,850 Bfits none 8× model.json · card.txt · fhir.json
lbbbComplete left bundle branch block (MIT-BIH 109) 2,066 BVersion 34-L / Version 39-M 16,685 B3 entries 5,331 Bfits none 8× model.json · card.txt · fhir.json
pacedVentricular paced rhythm with spikes (MIT-BIH 107) 2,128 BVersion 35-L / Version 39-M 16,685 B3 entries 5,926 Bfits none 8× model.json · card.txt · fhir.json
vtachVentricular tachycardia / flutter (MIT-BIH 207) 2,008 BVersion 34-L / Version 38-M 14,951 B3 entries 5,369 Bfits none 7× model.json · card.txt · fhir.json
av-block2nd-degree Mobitz II AV block (MIT-BIH 231) 1,842 BVersion 32-L / Version 36-M 15,428 B3 entries 4,216 Bfits none 8× model.json · card.txt · fhir.json
stemiAcute inferior ST-segment elevation (European ST-T e0103) 1,406 BVersion 28-L / Version 32-M 11,308 B3 entries 2,842 BVersion 40-L 8× model.json · card.txt · fhir.json

Technical specification & format

Rendered from codecs/ecg-strip/README.md in the repository.

A content-addressed (0x00 || sha256(wasm)) WebAssembly codec conforming to CODEC-ABI v0.1 that packs 100% bit-exact lossless clinical ECG rhythm strips — including standard 10-second strips at 250–360 Hz — into a single dense QR code and decodes them into standards-compliant FHIR R4 Bundle resources containing Observation.valueSampledData.

  • WASM binary: ecg-strip.wasm — 42,742 bytes
  • SHA-256: b37fa36f53a0e4818c8456be8ee7fe0532806a20fb35772607f38938e6ffb75c
  • Static audit (auditWasm): 0 violations, 0 imports, 0 floating-point instructions, 0 SIMD/threads, 0 reachable panics (enforced at link time), #![no_std], #![forbid(unsafe_code)] in ecg_strip_core.
  • Decode speed: 2.5–3.8 ms per 10-second strip (including full canonical re-encode verification across all 4 predictors).

Benchmark on 8 Real Open-Access Human ECG Recordings (PhysioNet)

All 8 strips are real human ECG recordings fetched from PhysioNet under the Open Data Commons Attribution License v1.0 (ODC-By 1.0), verified against each database's cardiologist .atr annotations (scripts/fetch-physionet.ts). Every strip round-trips through shc_encode → pack({ codec: { sha256 } }) → QR numeric digits → parse → runCodec with 0 sample error across all 27,700 samples.

StripPhysioNet RecordPathologyLeadFsSamplesFHIR JSONDEFLATE (L9)Codec Payload (bits/smp)SHA-256 Card (+35 B)QR Version-L (bare / viewer)vs FHIRvs DEFLATEBest Predictor
nsrmitdb/100 @ 00:10Normal Sinus RhythmMLII360 Hz3,60015,656 B3,978 B (>QR max)1,824 B (4.05 b/s)1,859 BV32-L / V32-L8.42×2.14×P0: delta
afibmitdb/201 @ 00:10Atrial FibrillationMLII360 Hz3,60015,568 B4,044 B (>QR max)1,813 B (4.03 b/s)1,848 BV32-L / V32-L8.42×2.19×P3: lms3
bigeminymitdb/106 @ 12:30Ventricular BigeminyMLII360 Hz3,60015,457 B4,850 B (>QR max)2,012 B (4.47 b/s)2,047 BV34-L / V34-L7.55×2.37×P2: ar2-damped
lbbbmitdb/109 @ 00:00Left Bundle Branch BlockMLII360 Hz3,60016,685 B5,331 B (>QR max)2,031 B (4.51 b/s)2,066 BV34-L / V34-L8.08×2.58×P2: ar2-damped
pacedmitdb/107 @ 00:00Ventricular Paced RhythmMLII360 Hz3,60016,685 B5,926 B (>QR max)2,093 B (4.65 b/s)2,128 BV34-L / V35-L7.84×2.78×P1: linear2
vtachmitdb/207 @ 00:38VTach / Ventricular FlutterMLII360 Hz3,60014,951 B5,369 B (>QR max)1,973 B (4.38 b/s)2,008 BV33-L / V34-L7.45×2.67×P2: ar2-damped
av-blockmitdb/231 @ 01:382nd-Deg AV Block (Mobitz II)MLII360 Hz3,60015,428 B4,216 B (>QR max)1,807 B (4.02 b/s)1,842 BV32-L / V32-L8.38×2.29×P0: delta
stemiedb/e0103 @ 16:15Acute ST-Elevation (+200 µV)MLIII250 Hz2,50011,308 B2,842 B1,371 B (4.39 b/s)1,406 BV27-L / V28-L8.04×2.02×P0: delta

Why this matters: On all seven 10-second 360 Hz MIT-BIH strips, raw DEFLATE of the FHIR Bundle is 3,978–5,926 bytes, exceeding QR Version 40-L maximum capacity (2,953 bytes) — none can fit in a single QR code under generic compression. ecg-strip fits every 10-second strip into a single QR code even with the 33-byte SHA-256 content-addressed codec reference, 2-byte integrity check, full viewer URL, patient demographics, device metadata, SNOMED CT interpretation, and provenance note.


Input Model (model.d.ts)

export interface EcgStrip {
  patient?: { family?: string; given?: string[]; birthDate?: string };
  source?: { name: string; version?: string };
  recordedAt: string;           // FHIR dateTime / instant
  sampleRateHz: number;         // integer 50..1000 (e.g. 250, 360, 500)
  microvoltsPerUnit: number;    // integer 1..1000 (e.g. 5 => 0.005 mV/step)
  interpretation?: { system?: string; code?: string; display?: string; text?: string };
  note?: string;
  leads: {
    lead: "I"|"II"|"III"|"aVR"|"aVL"|"aVF"|"V1"|"V2"|"V3"|"V4"|"V5"|"V6"|"MLII"|"MLIII";
    samples: number[];          // exact signed i16 (-32768..32767), 1..12000/lead, <=24000 total
  }[];
}

Bounded Limits

DimensionBound
sampleRateHz50..1000 (integer Hz)
microvoltsPerUnit1..1000 (integer µV/LSB)
leads1..12 unique standard leads
samples per lead1..12000 (equal length across leads; <= 24000 total)
Sample value-32768..32767 (i16)
Card payload<= 4096 bytes (CODEC-ABI limit)

FHIR R4 Output Mapping (shc_decode)

shc_decode emits deterministic minified UTF-8 JSON with fixed key order:

  • Bundle (type: "collection")
    • resource:0 — Patient (id: "0", with name/birthDate when present)
    • resource:1 (optional) — Device (id: "1", with deviceName and optional version when source is present)
    • resource:k — One Observation per lead:
      • status: "final", category: procedure
      • code: ISO/IEEE 11073-10101 (urn:iso:std:iso:11073:10101) per-lead MDC code (131329–131336, 131389–131392) + text: "ECG Lead <name>"
      • subject: { reference: "resource:0" }, effectiveDateTime: recordedAt, optional device: { reference: "resource:1" }
      • valueSampledData:
        • origin: { value: 0, unit: "mV", system: "http://unitsofmeasure.org", code: "mV" }
        • period: pure-integer decimal milliseconds round(1_000_000 / sampleRateHz) / 1000 (e.g., 2.778 for 360 Hz, 4 for 250 Hz, 2 for 500 Hz)
        • factor: pure-integer decimal microvoltsPerUnit / 1000 mV/unit (e.g., 0.005 for 200 adu/mV)
        • dimensions: 1
        • data: space-separated exact integer ADC samples — 100% lossless
      • Optional interpretation (CodeableConcept) and note (Annotation)

Wire Format & Lossless DSP + Entropy Coding

  1. Compact Binary Header:
    • Byte 0: version bits (0 = v1; 1..3 → UNSUPPORTED), optional-section flags (patient, source, interpretation, note), reserved bits (0).
    • recordedAt: compact 4-byte little-endian Unix seconds when exact UTC YYYY-MM-DDThh:mm:ssZ (1970–2105), else length-prefixed ASCII.
    • sampleRateHz - 50 (ULEB128), microvoltsPerUnit - 1 (ULEB128), numLeads (u8), numSamples - 1 (ULEB128).
    • Optional sections: patient (2-byte packed day-offset for YYYY-MM-DD in 1900–2079), source, interpretation (2-bit code for http://snomed.info/sct / http://loinc.org / literal), note.
  2. Per-Lead Integer Predictor Selection (4 modes, 2-bit tag):
    • P0: 1st-order delta x[n-1]
    • P1: 2nd-order linear 2*x[n-1] - x[n-2]
    • P2: damped 2nd-order AR(2) (7*x[n-1] - 3*x[n-2] + 2) >> 2
    • P3: 3-tap integer delta-LMS (Q10 fixed-point weights updated with bounded integer gradient step >> 6)
    • The encoder evaluates all 4 predictors per lead and picks the shortest output (lowest predictor ID breaks ties).
  3. 6-Context Activity-Adaptive Range Coder:
    • Zigzag-mapped residuals are coded in one of 6 contexts selected by an integer EMA of |residual| (0, <=1, <=3, <=7, <=18, >18).
    • Each context maintains a 16-symbol adaptive frequency table (0..14 direct, 15 escape → order-1 Exp-Golomb with adaptive unary prefix probabilities + equiprobable mantissa bits).
  4. Canonicality:
    • shc_decode re-encodes the decoded EcgStrip and rejects any card whose bytes do not match byte-for-byte (MALFORMED).

Build, Fetch & Test

# Re-fetch and verify the 8 real PhysioNet strips into examples/
bun codecs/ecg-strip/scripts/fetch-physionet.ts

# Rebuild ecg-strip.wasm (requires rustc with wasm32-unknown-unknown target)
bash codecs/ecg-strip/rust/build.sh

# Run full audit, lossless round-trip, canonicality, fuzz, and benchmark suite
bun test codecs/ecg-strip/ecg-strip.test.ts

PhysioNet Attribution

  • MIT-BIH Arrhythmia Database (mitdb, records 100, 106, 107, 109, 201, 207, 231): Moody GB, Mark RG. The impact of the MIT-BIH Arrhythmia Database. IEEE Eng in Med and Biol 20(3):45–50 (May–June 2001). DOI: 10.13026/C2F305 (ODC-By 1.0).
  • European ST-T Database (edb, record e0103): Taddei A, Distante G, Emdin M, Pisani P, Moody GB, Zeelenberg C, Marchesi C. The European ST-T Database: standard for evaluating systems for the analysis of ST-T changes in ambulatory electrocardiography. European Heart Journal 13:1164–1172 (1992). DOI: 10.13026/C2D59Z (ODC-By 1.0).