MIT-LCP / wfdb-python

Native Python WFDB package
MIT License
738 stars 300 forks source link

Unexpected changes to checksum after `wrsamp` #449

Closed briangow closed 1 year ago

briangow commented 1 year ago

Simply reading an entire WFDB record and writing it without making any changes should result in a consistent checksum. However this is not the case with wrsamp (in v4.0.0).

orig_record = wfdb.rdrecord('100', pn_dir='mitdb/1.0.0')
print(orig_record.checksum)
[-22131, 20052]
wfdb.wrsamp('python_wrsamp_100', orig_record.fs, orig_record.units, orig_record.sig_name, orig_record.p_signal)
python_wrsamp = wfdb.rdrecord('python_wrsamp_100')
print(python_wrsamp.checksum)
[55201, 4478]
bemoody commented 1 year ago

That's because wrsamp re-scales the samples; in this case, it picks a new adc_gain and baseline in order to fit the provided p_signal values into a 12-bit range.

I don't know exactly how this is done, but you would only expect the checksum to match if the d_signal values match (which would be the case if the adc_gain and baseline likewise match.)

briangow commented 1 year ago

Ok, thanks for the explanation.