When a twelve-lead electrocardiogram is written as text for a large language model, the number of tokens has to be balanced against the information lost through compression. This paper presents a deterministic encoding that writes eight independent leads as amplitude letters and exact time gaps and recovers the remaining four limb leads algebraically. The key points are selected with a cardiac-cycle-dependent tolerance, the amplitudes are parameterized by a 26-letter logarithmic codebook learned from a training set, and a 10-step tolerance schedule keeps all records within a fixed token budget. The encoding was applied to 21,388 records from the public PTB-XL database and evaluated using an exact decode-and-re-encode round trip, waveform reconstruction error, and a paired comparison of convolutional classifiers trained with 5 different seeds on signals from the original and decoded databases. All records were contained in 4,080 tokens (average: 2,866 tokens, 64.3% fewer than a per-sample transcription), and all stored lead strings were exactly reproduced. The average correlation between the decoded and reference signals was 0.982. The macro-averaged area under the receiver operating characteristic curve was 0.9167 for the reference signals and 0.9157 for the decoded signals (paired difference -0.0010; 95% patient-level bootstrap interval, -0.0028 to 0.0007), within the pre-specified non-inferiority margin of -0.010; this is not a confirmatory result, because the test fold had been used during encoder development. The diagnostic content of a compact text can therefore be preserved, while the language model's ability to read the text is yet another matter.
Figures & tables
Approach
Studies
Input to the language model
Meaning of symbols
Waveform recoverable from the input
Encoder alignment
[ 2 , 3 , 12 ]
Continuous embeddings
No symbols
No
Generic symbolic time series
[ 13 , 14 ]
Symbols for aggregates or linear pieces
Value bins or clustered pieces
Approximately
Learned ECG vocabularies
[ 4 , 6 , 15 ]
Learned tokens or codes
Learned from data
Depends on the codebook
Fixed ECG alphabet
[ 5 ]
Amplitude and time letters, 12 leads
Amplitude and duration bins
Approximately; time quantized
ECG-26c (this paper)
–
Amplitude letters and exact gaps, 8 leads, ≤ 4,080 tokens
μ -law bins in mV; exact sample counts
Approximately; key-point times exact
TABLE I: Comparison of related studies and the positioning of this paper.
Fig. 1: Encoder (top) and decoder (bottom) of ECG-26c. The tolerance level k starts at 0 and increases only when the serialized text exceeds the token budget; decoding requires the frozen codebook and the format conventions but no learned model.
Design element
ECG-aBcDe
ECG-26c
Sampling rate
Resampled to 250 Hz
100 Hz (PTB-XL records100)
Leads written
All 12
I, II and V1–V6; the other four rebuilt with Eq. ( 1 )
Key-point selection
ℓ 1 trend filtering
RDP with a cycle-dependent tolerance
Amplitude letters a–z
24 equal-width bins between the 1st and 99th training percentiles, plus 2 open outer bins
μ -law bins ( μ = 20) between the 0.05th and 99.95th training percentiles; a–m ≤ 0 mV < n–z
Decoded amplitude
Upper bound of the bin
Mean of the training key points in the bin
Very large amplitudes
Absorbed by the outer letters
Lead written at half or quarter scale (x2, x4)
TABLE II: Design comparison between ECG-aBcDe [ 5 ] and ECG-26c.
Fig. 2: The 26-letter amplitude partition, with alternating hatching. (a) Full range; the outer bins a and z extend beyond the plotted range. (b) Close-up of the bins near zero, where they are narrowest. The dotted line marks 0 mV.
Point
Sample
Input (mV)
Letter
Decoded (mV)
Gap
Time letter
1
0
0.025
n
0.018
10
J
2
10
0.101
p
0.110
1
–
3
11
0.144
q
0.177
3
C
4
14
− 0.001
m
− 0.024
5
E
5
19
− 0.009
m
− 0.024
1
–
6
20
0.016
n
0.018
2
B
TABLE III: Worked example: the first twelve key points of lead II in PTB-XL record 1. Every key point contributes its amplitude letter and then the time letter of the following gap, which is omitted when the next key point is one sample away.
Fig. 3: Filtered input (solid) and decoded (dashed) amplitudes of the key points in Table 3, covering 0–280 ms. Connecting lines only guide the eye; the example illustrates quantization and is not a diagnostic validation.
Fig. 4: The first four seconds of leads II and V2 in PTB-XL record 1: filtered reference (solid line) and signal decoded from ECG-26c text (dashed line).
Metric
Reference
Decoded
Paired Δ [95% interval]
Macro-AUROC (primary)
0.9167 ± 0.0014
0.9157 ± 0.0010
− 0.0010 [ − 0.0028, 0.0007]
Micro-AUROC
0.9281 ± 0.0027
0.9253 ± 0.0015
− 0.0029 [ − 0.0044, − 0.0013]
Macro-AP
0.8025 ± 0.0044
0.8026 ± 0.0033
0.0001 [ − 0.0036, 0.0039]
Macro-F1
0.7304 ± 0.0027
0.7276 ± 0.0029
− 0.0027 [ − 0.0081, 0.0026]
AUROC, NORM
0.9393 ± 0.0041
0.9408 ± 0.0028
0.0015 [ − 0.0006, 0.0036]
AUROC, MI
0.9115 ± 0.0074
0.9074 ± 0.0024
− 0.0041 [ − 0.0081, − 0.0002]
TABLE IV: Test-fold metrics of the CNN (mean ± SD over five seeds; thresholds selected on the validation fold) and paired differences with 95% patient-cluster bootstrap intervals. The higher mean in each row is shown in bold.
Variant
Mean tokens
Max tokens
Saving
Median PRDN (%) 12 / 8 / 4 leads
Δ macro-AUROC [95% interval]
Quantization only
8,029
8,043
0%
11.7 / 10.6 / 18.7
− 0.0007 [ − 0.0023, 0.0009]
Uniform 0.02 mV
3,611
7,728
55.0%
11.4 / 10.4 / 18.2
− 0.0020 [ − 0.0040, 0.0000]
Level 0 (fixed)
2,912
7,462
63.7%
12.7 / 11.4 / 20.5
0.0000 [ − 0.0016, 0.0016]
ECG-26c (final)
2,866
4,080
64.3%
12.7 / 11.4 / 20.6
− 0.0010 [ − 0.0028, 0.0007]
Level 3 (fixed)
2,177
6,702
72.9%
16.1 / 14.4 / 26.0
− 0.0002 [ − 0.0021, 0.0016]
Level 6 (fixed)
1,637
5,372
79.6%
25.3 / 22.3 / 42.1
− 0.0042 [ − 0.0067, − 0.0017]
TABLE V: Compression, reconstruction, and paired diagnostic change for each encoding variant. Token and PRDN values cover all 21,388 records; Δ macro-AUROC refers to the test fold, with 95% patient-cluster bootstrap intervals. Savings are relative to quantization only.
Fig. 5: Compression trade-off on the test fold. (a) Median PRDN over the twelve leads. (b) Mean paired change in macro-AUROC with 95% patient-cluster bootstrap intervals. The filled marker denotes the final ECG-26c encoding, and the dashed line marks the analytic margin of − 0.010.