braindecode.functional.hilbert_freq#
- braindecode.functional.hilbert_freq(x, forward_fourier=True, n_times=None)[source]#
Compute the Hilbert transform using PyTorch, separating the real and imaginary parts.
The analytic signal \(x_a(t)\) of a real-valued signal \(x(t)\) is defined as:
\[x_a(t) = x(t) + i y(t) = \mathcal{F}^{-1} \{ U(f) \mathcal{F}\{x(t)\} \}\]where: - \(\mathcal{F}\) is the Fourier transform, - \(U(f)\) is the unit step function, - \(y(t)\) is the Hilbert transform of \(x(t)\).
- Parameters:
x (
Tensor) – Time-domain signal of shape(..., n_times), or its one-sided RFFT as real and imaginary pairs of shape(..., n_times // 2 + 1, 2).forward_fourier (
bool) – Compute the RFFT of a time-domain signal. Set to False to supply its spectrum directly.n_times (
Optional[int]) – Original number of time samples. Supply it with a precomputed spectrum to distinguish odd from even lengths and preserve the Nyquist term of an even-length signal. Omitting it for a spectrum retains the historical even output length and doubled final bin used by EEGMiner.
- Returns:
Analytic signal of shape
(..., n_times, 2), where the last dimension holds its real and imaginary parts. For a spectrum given withoutn_times, the length is2 * (n_freqs - 1).- Return type:
Examples
>>> import torch >>> x = torch.randn(10, 100) >>> hilbert_freq(x).shape torch.Size([10, 100, 2])
See also
scipy.signal.hilbertAnalytic signal of a real waveform.