torch.fft.rfft¶
-
torch.fft.
rfft
(input, n=None, dim=- 1, norm=None, *, out=None) → Tensor¶ Computes the one dimensional Fourier transform of real-valued
input
.The FFT of a real signal is Hermitian-symmetric,
X[i] = conj(X[-i])
so the output contains only the positive frequencies below the Nyquist frequency. To compute the full output, usefft()
- Parameters
input (Tensor) – the real input tensor
n (int, optional) – Signal length. If given, the input will either be zero-padded or trimmed to this length before computing the real FFT.
dim (int, optional) – The dimension along which to take the one dimensional real FFT.
norm (str, optional) –
Normalization mode. For the forward transform (
rfft()
), these correspond to:"forward"
- normalize by1/n
"backward"
- no normalization"ortho"
- normalize by1/sqrt(n)
(making the FFT orthonormal)
Calling the backward transform (
irfft()
) with the same normalization mode will apply an overall normalization of1/n
between the two transforms. This is required to makeirfft()
the exact inverse.Default is
"backward"
(no normalization).
- Keyword Arguments
out (Tensor, optional) – the output tensor.
Example
>>> t = torch.arange(4) >>> t tensor([0, 1, 2, 3]) >>> torch.fft.rfft(t) tensor([ 6.+0.j, -2.+2.j, -2.+0.j])
Compare against the full output from
fft()
:>>> torch.fft.fft(t) tensor([ 6.+0.j, -2.+2.j, -2.+0.j, -2.-2.j])
Notice that the symmetric element
T[-1] == T[1].conj()
is omitted. At the Nyquist frequencyT[-2] == T[2]
is it’s own symmetric pair, and therefore must always be real-valued.