You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
wfdb_to_mat silently wraps samples that don't fit the output type #641
wfdb_to_mat picks the output type (uint8, int16 or int32) from adc_res alone, and then casts the samples to it without checking that they fit. When a valid sample is outside the range of that type, it wraps silently. It can even wrap to the invalid sample value, so it is read back as missing.
This happens when the shift by adc_zero moves a sample out of range, or when the header's resolution is smaller than the values actually stored. For example, with format 16 records:
Input
Written to the .mat
Read back
adc_zero=1, samples [-32767, 0, 32767]
[-32768, -1, 32766]
the first sample becomes the invalid value (NaN)
adc_zero=-1, samples [-32767, 0, 32767]
[-32766, 1, -32768]
32767 wraps to the invalid value
adc_res=8, samples [100, 300, -300]
uint8 [228, 172, 84]
300 and -300 are corrupted
This happens on main, and also with the changes in #633.
Possible fixes:
check the min and max of the shifted samples (leaving out missing samples) against the output type, and use the next larger type if they don't fit
Activity