Repository navigation
Description
I noticed a documentation-worthy quirk in the public MIT-BIH Noise Stress Test Database records when they are read with wfdb 5.5.1.
The nstdb ECG records were created by nst from mitdb 118 and 119. In the first five minutes, which the dataset description says are noise-free, the digital samples are exactly 1024 lower than the source mitdb record, and p_signal is a constant 5.12 mV lower.
This comes from the headers, not from a difference in how Python converts samples. For example, mitdb 118 has adc_zero = baseline = 1024. nstdb 118e24 has adc_zero = 0 and baseline = 1024 (the header line is 212 200(1024) 11 0 ...). wfdb, like the C library, uses (d_signal - baseline) / adc_gain. Using adc_zero in place of baseline restores agreement with mitdb p_signal on that clean stretch.
nst appears to do this in source, but the nst man page does not mention it. In nst.c the program saves the input adczero, sets the output adczero to 0, and subtracts the original adczero from each sample. It does not change baseline. nstdbgen is the script that built these records.
I also compared WFDB Software Package 10.7.0 wfdbdesc and rdsamp -P. They report the same header fields and the same 5.12 mV physical offset, so this is not specific to wfdb-python.
A short example, using the first five minutes of mitdb 118 and nstdb 118e24 (108000 samples at 360 Hz):
import wfdb
clean = 360 * 60 * 5
mit_p = wfdb.rdrecord("118", pn_dir="mitdb", sampto=clean)
nst_p = wfdb.rdrecord("118e24", pn_dir="nstdb", sampto=clean)
mit = wfdb.rdrecord("118", pn_dir="mitdb", sampto=clean, physical=False)
nst = wfdb.rdrecord("118e24", pn_dir="nstdb", sampto=clean, physical=False)
print(mit.adc_gain, mit.baseline, mit.adc_zero) # [200.0, 200.0] [1024, 1024] [1024, 1024]
print(nst.adc_gain, nst.baseline, nst.adc_zero) # [200.0, 200.0] [1024, 1024] [0, 0]
print((mit.d_signal - nst.d_signal).max(), (mit.d_signal - nst.d_signal).min())
# 1024 1024
print((mit_p.p_signal - nst_p.p_signal).round(10).max(),
(mit_p.p_signal - nst_p.p_signal).round(10).min())
# 5.12 5.12
alt = (nst.d_signal - nst.adc_zero) / nst.adc_gain
print((mit_p.p_signal - alt).max(), (mit_p.p_signal - alt).min())
# 0.0 0.0The same pattern holds for nstdb 118e00 (format 16 rather than 212) and for 119e24 versus mitdb 119.
I do not think this is a conversion bug in wfdb-python. The package follows the WFDB header specification, which defines baseline as the sample value for 0 physical units and treats baseline and ADC zero as separate fields. I also did not find an existing wfdb-python issue or a note on the nstdb page about this.
This may be a useful concrete example for #744 and #745, where baseline and adc_zero can differ on a real public record. Would a short docs note be welcome?
Activity