Shortcuts

CWTSpectrum

class torcheeg.transforms.CWTSpectrum(sampling_rate: int = 250, wavelet: str = 'morl', total_scale: int = 128, contourf: bool = False, apply_to_baseline: bool = False)[source][source]

A transform method to convert EEG signals of each channel into spectrograms using wavelet transform.

from torcheeg import transforms

t = transforms.CWTSpectrum()
t(eeg=np.random.randn(32, 1000))['eeg'].shape
>>> (32, 128, 1000)

Part of the existing work uses Resize to warp the output spectrum to a specified size suitable for CNN processing.

from torcheeg import transforms

t = Compose([
    CWTSpectrum(),
    ToTensor(),
    Resize([260, 260])
])
t(eeg=np.random.randn(32, 1000))['eeg'].shape
>>> (32, 128, 1000)

When contourf is set to True, a spectrogram of filled contours will be generated for each channel and converted to np.ndarray and returned. This option is usually used for single-channel analysis or visualization of a single channel.

from torcheeg import transforms

t = CWTSpectrum(contourf=True)
t(eeg=np.random.randn(32, 1000))['eeg'].shape
>>> (32, 480, 640, 4)
Parameters:
  • sampling_rate (int) – The sampling period for the frequencies output in Hz. (default: 128)

  • wavelet (str) – Wavelet to use. Options include: cgau1, cgau2, cgau3, cgau4, cgau5, cgau6, cgau7, cgau8, cmor, fbsp, gaus1, gaus2 , gaus3, gaus4, gaus5, gaus6, gaus7, gaus8, mexh, morl, shan. (default: 'morl')

  • total_scale – (int): The total wavelet scales to use. (default: 128)

  • contourf – (bool): Whether to output the np.ndarray corresponding to the image with content of filled contours. (default: False)

  • apply_to_baseline – (bool): Whether to act on the baseline signal at the same time, if the baseline is passed in when calling. (default: False)

__call__(*args, eeg: ndarray, baseline: ndarray | None = None, **kwargs) Dict[str, ndarray][source][source]
Parameters:
  • eeg (np.ndarray) – The input EEG signals in shape of [number of electrodes, number of data points].

  • baseline (np.ndarray, optional) – The corresponding baseline signal, if apply_to_baseline is set to True and baseline is passed, the baseline signal will be transformed with the same way as the experimental signal.

Returns:

The spectrograms based on the wavelet transform for all electrodes. If contourf=False, the output shape is [number of electrodes, total_scale, number of data points]. Otherwise, the output shape is [number of electrodes, height of image, width of image of image, 4], where 4 represents the four channels of the image colors.

Return type:

np.ndarray[number of electrodes, …]

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources