BaselineWanderAugmenter

class torch_ecg.augmenters.BaselineWanderAugmenter(fs: int, bw_fs: ndarray | None = None, ampl_ratio: ndarray | None = None, gaussian: ndarray | None = None, prob: float = 0.5, inplace: bool = True, **kwargs: Any)[source]

Bases: Augmenter

Generate baseline wander composed of sinusoidal and Gaussian noise.

Parameters:
  • fs (int) – Sampling frequency of the ECGs to be augmented

  • bw_fs (numpy.ndarray, optional) – Frequencies of the sinusoidal noises, of shape (n,), defaults to [0.33, 0.1, 0.05, 0.01].

  • ampl_ratio (numpy.ndarray, optional) –

    Candidate ratios of noise amplitdes compared to the original ECGs for each fs, of shape (m, n), defaults to

    np.array(
        [
            [0.01, 0.01, 0.02, 0.03],  # low
            [0.01, 0.02, 0.04, 0.05],  # low
            [0.1, 0.06, 0.04, 0.02],  # low
            [0.02, 0.04, 0.07, 0.1],  # low
            [0.05, 0.1, 0.16, 0.25],  # medium
            [0.1, 0.15, 0.25, 0.3],  # high
            [0.25, 0.25, 0.3, 0.35],  # extremely high
        ]
    )
    

  • gaussian (numpy.ndarray, optional) –

    Candidate mean and std of the Gaussian noises, of shape (k, 2), defaults to

    np.array(
        [  # mean and std, in terms of ratio
            [0.0, 0.001],
            [0.0, 0.003],
            [0.0, 0.01],
        ]
    )
    

  • prob (float, default 0.5) – Probability of performing the augmentation.

  • inplace (bool, default True) – If True, ECG signal tensors will be modified inplace.

  • kwargs (dict, optional) – Additional keyword arguments.

Examples

blw = BaselineWanderAugmenter(300, prob=0.7)
sig = torch.randn(32, 12, 5000)
label = torch.ones((32, 20))
sig, _ = blw(sig, label)
extra_repr_keys() List[str][source]

Extra keys for __repr__() and __str__().

forward(sig: Tensor, label: Tensor | None, *extra_tensors: Sequence[Tensor], **kwargs: Any) Tuple[Tensor, ...][source]

Forward function of the BaselineWanderAugmenter.

Parameters:
  • sig (torch.Tensor) – Batched ECGs to be augmented, of shape (batch, lead, siglen).

  • label (torch.Tensor, optional) – Batched label tensor of the ECGs. Not used, but kept for consistency with other augmenters.

  • extra_tensors (Sequence[torch.Tensor], optional,) – Not used, but kept for consistency with other augmenters.

  • **kwargs (dict, optional) – Not used, but kept for consistency with other augmenters.

Returns:

  • sig (torch.Tensor) – The augmented ECGs.

  • label (torch.Tensor) – Label tensor of the augmented ECGs, unchanged.

  • extra_tensors (Sequence[torch.Tensor], optional) – Unchanged extra tensors.