braindecode.functional.spectral_input#

braindecode.functional.spectral_input(x)[source]#

Prepare x for an FFT, STFT or eigendecomposition.

PyTorch has no complex bfloat16 dtype: CPU and MPS FFTs reject bfloat16/float16, and Intel Gaudi (HPU) has no complex tensors at all. This returns x in at least float32, moved to the CPU when it lives on an HPU; float32/float64 CPU/CUDA inputs are returned as they are. Cast a real result back with .to(x) (the input’s dtype and device):

spectrum = torch.fft.rfft(spectral_input(x), dim=-1).abs().to(x)
Parameters:

x (Tensor) – Real input of the spectral operation.

Returns:

x in promote_types(x.dtype, float32), on the CPU for HPU inputs.

Return type:

Tensor