Resample#

class torch_ecg.preprocessors.Resample(fs: int | None = None, dst_fs: int | None = None, siglen: int | None = None, inplace: bool = False, **kwargs: Any)[source]#

Bases: Module

Resample the signal into fixed sampling frequency or length.

Parameters:
  • fs (int, optional) – Sampling frequency of the source signal to be resampled.

  • dst_fs (int, optional) – Sampling frequency of the resampled ECG.

  • siglen (int, optional) – Number of samples in the resampled ECG.

  • inplace (bool, default False) – Whether to perform the resampling in-place.

Note

One and only one of fs and siglen should be set. If fs is set, src_fs should also be set.

TODO

Consider vectorized scipy.signal.resample()?

forward(sig: ndarray | Tensor) ndarray | Tensor[source]#

Apply the resampling to the signal.

Parameters:

sig (numpy.ndarray or torch.Tensor) – The signal to be resampled, of shape (..., n_leads, siglen).

Returns:

The resampled signal.

  • If sig is a torch.Tensor, the output is a tensor.

  • If sig is a numpy.ndarray, the output is a NumPy array with floating dtype. When the input dtype is floating, the same floating dtype is preserved; otherwise, float32 is used.

Return type:

numpy.ndarray or torch.Tensor