add_eeg_artifact
- selfeeg.augmentation.functional.add_eeg_artifact(x: ArrayLike, Fs: float, artifact: str = None, amplitude: float = None, line_at_60Hz: bool = True, lost_time: float = None, drift_slope: float = None, batch_equal: bool = True) ArrayLike[source]
add common EEG artifacts to the ArrayLike object.
Given a N-dim tensor or a numpy array, add_eeg_artifact add one of the artifact listed in [art] along the last dimension of the input element. Supported artifacts are:
white: simple white noise
line: noise at 50 Hz or 60 Hz
eye: noise in range [1, 3] Hz
muscle: noise in range [20, 60] Hz
drift: straight line with non-zero slope
lost: cancellation of one portion of the signal
Line, eye and muscle artifact are generated with the
add_band_noisefunction. Lost artifact is generated with themaskingfunction. White and drift are generated internally.- Parameters:
x (ArrayLike) – the input Tensor or Array. The last two dimensions must refer to the EEG recording (Channels x Samples).
Fs (float) – The sampling rate of the signal in Hz.
artifact (str, optional) –
The type of artifact to apply. If None is left a random artifact will be chosen.
Default = None
amplitude (float, optional) –
The amplitude of the noise to add. If not given, amplitude=std(x)
Default = None
line_at_60Hz (bool, optional) –
Whether to apply the line artifact at 60Hz (True) or 50Hz (False).
Default = True
lost_time (float, optional) –
The amount of time the signal is canceled. Must be given in seconds. Internally
maskingfunction is called by converting the given time to the percentage of masked signal with the function (Fs*lost_time)/x.shape[-1]. Alternatively, to convert the percentage of the signal masked to the amount of time is masked, just revert the formula, so:lost_time= (masking_percentage * x.shape[-1]) / Fs.
If None is given, 20% of the signal is randomly masked.
Default = None
drift_slope (float, optional) –
The difference between to consecutive points of the straight line to add. If None is given, slope is calculated with the amplitude parameter as
drift_slope = amplitude/x.shape[-1].
If also amplitude is not given
drift_slope = std(x)/x.shape[-1]
Default = None
batch_equal (bool, optional) –
Whether to apply the same masking to all elements in the batch or not. Does apply only if x has more than 2 dimensions
Default = True
- Returns:
x (ArrayLike) – the augmented version of the input Tensor or Array.
References
[art]Fickling et al., (2019) Good data? The EEG Quality Index for Automated Assessment of Signal Quality
Example
>>> import torch >>> import selfeeg.augmentation as aug >>> x = torch.zeros(16,32,1024) + torch.sin(torch.linspace(0, 8*torch.pi,1024)) >>> xaug = aug.add_eeg_artifact(x, 128) >>> print( torch.equal(x,xaug)) # should return False