change_ref

selfeeg.augmentation.functional.change_ref(x: ArrayLike, mode: str = 'avg', reference: int = None, exclude_from_ref: int = None) ArrayLike[source]

changes the reference of all EEG record in the ArrayLike object.

Currently, reference can be changed to:

  1. Channel reference (e.g. Cz). Each record of a channel is subtracted to the record of the Cz channel. Cz(t) becomes 0 for all t

  2. Common Average Reference (CAR). Each record is subtracted of the average of all electrodes. Currently, it does not cover all particular cases which can be managed by major libraries like EEGlab or MNE as this implementation is minimalist.

To get a more detailed description about re-referencing, check this brief background page of the EEGlab library [eeglab] .

Parameters:
  • x (ArrayLike) – The input Tensor or Array. The last two dimensions must refer to the EEG recording (Channels x Samples).

  • mode (str or int, optional) –

    The re-reference modality. Accepted arguments are:

    1. 0, ‘chan’, ‘channel’. Single Channel re-referencing

    2. 1, ‘avg’, ‘average’, ‘car’. Common Avarage re-referencing.

    Default = “avg”

  • reference (int, optional) –

    The reference electrode, given as an integer with the index position of the EEG channel in the input ArrayLike object x. Remember that the EEG channel dimension must be the second to last.

    Default = None

  • exclude_from_ref (int or list[int], optional) –

    Argument designed to exclude some channels during average re-referencing. This apply for example when x has records from nose tip or ear lobe.

    Default = None

Returns:

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

References

Example

>>> import torch
>>> import selfeeg.augmentation as aug
>>> torch.manual_seed(1234)
>>> x = torch.ones(16,32,1024)*2 + torch.sin(torch.linspace(0, 8*torch.pi,1024))
>>> x[:,0,:]= 0.
>>> xaug = aug.change_ref(x, 'channel', 5)
>>> print(x[0,0].max()!=0 and x[0,0].min()!=0) # should return False
>>> print( (xaug[0,[i for i in range(1,32)]].min().item()==0 and
...         xaug[0,0].min().item()!=0) ) # should return True