Skip to content

wfdb_to_wav writes invalid samples as 0 for resolutions below 12 bits #637

Closed

Description

@tompollard

wfdb_to_wav computes each output sample as (d - adc_zero) << (16 - adc_res) and then casts it to int16. For signals with a resolution below 12 bits, the invalid sample value overflows int16 and becomes 0, so a gap in the signal looks like a valid zero in the .wav file.

For example, a format 212 record with samples 100, -2048, 200, where -2048 is the invalid value for format 212, gives:

adc_res valid samples invalid sample in the .wav
12 1600, 3200 -32768
11 3200, 6400 0

With 11 bits, -2048 << 5 is -65536, which wraps to 0 as an int16. Record 100 in sample-data is format 212 with 11-bit resolution, so this affects MIT-BIH records that contain gaps.

One fix is to map invalid samples to -32768 (the format 16 invalid value) after the shift, instead of shifting them.

Found while reviewing #632.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions