Repository navigation
Description
Format 8 stores each sample as the difference from the previous one, starting from the header's initial value. When a read starts after the first frames, the decoder restarts that running sum at the window start instead of carrying it from frame 0. The returned values are wrong, and nothing reports an error.
Using the format 8 channel of sample-data/binformats (channel 0, initial value -2047), on current main (239206d):
import wfdb
path = "sample-data/binformats"
full = wfdb.read_signals(path, kind="digital", layout="uniform", channels=[0])
values = full.signals.values[:, 0]
for start in (1, 2, 477):
window = wfdb.read_signals(
path, kind="digital", layout="uniform", channels=[0],
start=start, stop=start + 3,
)
print(start, values[start:start + 3].tolist(), window.signals.values[:, 0].tolist())start |
full read, sliced | windowed read |
|---|---|---|
| 1 | [-1920, -1793, -1666] |
[-1920, -1793, -1666] |
| 2 | [-1793, -1666, -1539] |
[-1920, -1793, -1666] |
| 477 | [570, 442, 314] |
[-2175, -2303, -2431] |
Each windowed read restarts from the initial value at the window start. rdrecord(path, physical=False, sampfrom=477, sampto=480, channels=[0]) returns the same wrong values, and so does v5.17.0, so this has been in the shared decoder for a long time, not in the new readers. Physical reads are affected the same way, through calibration of the wrong digital values.
Expected: a window returns the same samples as the full read sliced to that window. That requires decoding a format 8 channel from frame 0, or at least from a point where the running value is known, up to the window start. WFDB's own library has to do the same for this format.
Suggested tests:
- for several
startvalues, including 1, 2, a mid-record frame and the last frame, both kinds and both layouts, compare a windowed read with the full read sliced to the same window; - the same comparison through
rdrecord(..., sampfrom=...); - a format 8 segment inside a multi-segment record, where the segment's local window starts after frame 0.
Format 8 is rare in PhysioNet data, but any windowed read of it is silently wrong. A changelog entry should say which reads were affected.
Activity
tompollard commentedon Dec 4, 2026
A correction to my description above: I wrote that WFDB's own library "has to do the same", meaning reconstruct the running value from frame 0. It doesn't. In
lib/signal.c,isgsetframehandles format 8 with a plain byte seek (case 8: case 80: default: b = nn;). It discards the bytes before the target sample without accumulating them, and sets the running value to the header'sinitvalonly when the signal is opened. Sordsamp -f Non a format 8 record starts from the initial value at frameN, as wfdb-python did.We've decided to return the values the format defines anyway (#911), because the alternative gives wrong samples. Windowed format 8 reads will therefore intentionally differ from WFDB's
rdsamp, and #911 should document that.