add_gaussian_noise

selfeeg.augmentation.functional.add_gaussian_noise(x: ArrayLike, std: float = 1.0, mean: float = 0.0, get_noise: bool = False) tuple[ArrayLike, ArrayLike | None][source]

adds gaussian noise with the desired standard deviation.

It is also possible to add a vertical shift (mean on the noise). Note that in this case the noise will not have 0 mean anymore and it cannot be concretely considered white noise.

Parameters:
  • x (ArrayLike) – The input Tensor or Array.

  • std (float, optional) –

    The std of the gaussian distribution.

    Default = 1

  • mean (float, optional) –

    A constant to add to the generated white noise.

    Default = 0

  • get_noise (bool, optional) –

    Whether to return the generated noise or not.

    Default = False

Returns:
  • x (ArrayLike) – The augmented version of the input Tensor or Array.

  • noise (ArrayLike, optional) – The generated noise. Returned only if get_noise is set to True.

Example

>>> import torch
>>> import math
>>> import selfeeg.augmentation as aug
>>> x = torch.zeros(16,32,1024) + torch.sin(torch.linspace(0, 8*torch.pi,1024))
>>> xaug, noise = aug.add_gaussian_noise(x, 0.1, get_noise=True)
>>> print(math.isclose(noise.std(),0.1,rel_tol=1e-2)) # should return True
>>> print(math.isclose(xaug.mean(),0,rel_tol=1e-4, abs_tol=1e-3)) # should return True