braindecode.functional.hilbert_freq#

braindecode.functional.hilbert_freq(x, forward_fourier=True)[source]#

Compute the Hilbert transform using PyTorch, separating the real and imaginary parts.

The analytic signal xa(t) of a real-valued signal x(t) is defined as:

xa(t)=x(t)+iy(t)=F1{U(f)F{x(t)}}

where: - F is the Fourier transform, - U(f) is the unit step function, - y(t) is the Hilbert transform of x(t).

Parameters:
  • input (torch.Tensor) –

    Input tensor. The expected shape depends on the forward_fourier parameter:

    • If forward_fourier is True:

      (…, seq_len)

    • If forward_fourier is False:

      (…, seq_len / 2 + 1, 2)

  • forward_fourier (bool, optional) – Determines the format of the input tensor. - If True, the input is in the forward Fourier domain. - If False, the input contains separate real and imaginary parts. Default is True.

Returns:

Output tensor with shape (…, seq_len, 2), where the last dimension represents the real and imaginary parts of the Hilbert transform.

Return type:

torch.Tensor

Examples

>>> import torch
>>> input = torch.randn(10, 100)  # Example input tensor
>>> output = hilbert_transform(input)
>>> print(output.shape)
torch.Size([10, 100, 2])

Notes

The implementation is matching scipy implementation, but using torch. scipy/scipy