Skip to content

compute_hr doesn't check that QRS indices are strictly increasing #602

Closed

Description

@tompollard

compute_hr assumes qrs_inds is strictly increasing, but doesn't check it. If two beats have the same index, the RR interval is 0:

import numpy as np
from wfdb import processing

processing.compute_hr(20, [2, 8, 8, 15], fs=1)
# ZeroDivisionError: float division by zero

processing.compute_hr(20, np.array([2, 8, 8, 15]), fs=1)
# RuntimeWarning: divide by zero, and the output contains inf

Beats that go backwards (e.g. [2, 8, 5, 15]) give a negative interval and a negative heart rate (-20 bpm in this example) without any error.

This can happen if annotations are combined from several sources or include non-beat annotations at the same sample (see #185).

compute_hr could check that qrs_inds is strictly increasing and raise a clear ValueError if not. #601 makes the last interval count as well, so a repeated last beat now hits the same problem.

Activity

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