Resampling

resample()

Resample a lead to a different sample rate

Polyphase resampling with linear edge extension, so a DC level or slow drift does not ring at the ends. The output has ceil(n * target_rate / fs) samples and the returned lead’s sampling_rate is updated. target_rate must be a whole number of Hz (250 or 250.0). Input must be a single finite lead (1-D). NaN or Inf samples raise ValueError.

ecgdatakit.processing.resample(lead, target_rate, *, fs=None)[source]

Resample a lead to a different sample rate.

Uses polyphase rational resampling (scipy.signal.resample_poly) which preserves signal content up to the Nyquist frequency of the lower sample rate. The signal is extended linearly at both ends (padtype="line") so a DC level or slow drift does not ring at the edges. Output length is ceil(n * target_rate / fs).

Parameters:
  • lead (Lead | NDArray[double]) – Input ECG lead or 1-D signal array (must be finite).

  • target_rate (int) – Desired output sample rate in Hz. A whole-number float such as 250.0 is accepted; the result is stored as an int.

  • fs (int | None) – Sample rate in Hz. Required when lead is a numpy array.

Return type:

Lead