torch.fft.hfft
- torch.fft.hfft(input, n=None, dim=-1, norm=None, *, out=None) →
Computes the one dimensional discrete Fourier transform of a Hermitian
symmetric input signal.
input (Tensor) – the input tensor representing a half-Hermitian signal
n (int, optional) – Output signal length. This determines the length of the
real output. If given, the input will either be zero-padded or trimmed to this
length before computing the Hermitian FFT.
Defaults to even output: n=2*(input.size(dim) - 1).
dim (int, optional) – The dimension along which to take the one dimensional Hermitian FFT.
norm (str, optional) –
Normalization mode. For the forward transform (), these correspond to:
Taking a real-valued frequency signal and bringing it into the time domain gives Hermitian symmetric output:
>>> t = torch.linspace(0, 1, 5)
>>> t
tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000])
>>> T = torch.fft.ifft(t)
>>> T
tensor([ 0.5000-0.0000j, -0.1250-0.1720j, -0.1250-0.0406j, -0.1250+0.0406j,
-0.1250+0.1720j])
Note that T[1] == T[-1].conj() and T[2] == T[-2].conj() is
redundant. We can thus compute the forward transform without considering
negative frequencies:
>>> torch.fft.hfft(T[:3], n=5)
tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000])
Like with irfft(), the output length must be given in order
to recover an even length output:
>>> torch.fft.hfft(T[:3])
tensor([0.1250, 0.2809, 0.6250, 0.9691])
"forward" - normalize by 1/n
"backward" - no normalization
"ortho" - normalize by 1/sqrt(n) (making the Hermitian FFT orthonormal)
Calling the backward transform (ihfft()) with the same
normalization mode will apply an overall normalization of 1/n between
the two transforms. This is required to make ihfft()
the exact inverse.
Default is "backward" (no normalization).
out (Tensor, optional) – the output tensor.