Resample

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

Bases: torch.nn.modules.module.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: torch.Tensor) torch.Tensor[source]

Apply the resampling to the signal tensor.

Parameters

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

Returns

The resampled signal tensor, of shape (..., n_leads, siglen).

Return type

torch.Tensor