torch.fft.rfftn
- torch.fft.rfftn(input, s=None, dim=None, norm=None, *, out=None) →
Computes the N-dimensional discrete Fourier transform of real input.
The FFT of a real signal is Hermitian-symmetric,
X[i_1, ..., i_n] = conj(X[-i_1, ..., -i_n]) so the full
fftn() output contains redundant information.
rfftn() instead omits the negative frequencies in the
last dimension.
input (Tensor) – the input tensor
s (Tuple[int], optional) – Signal size in the transformed dimensions.
If given, each dimension dim[i] will either be zero-padded or
trimmed to the length s[i] before computing the real FFT.
If a length -1 is specified, no padding is done in that dimension.
Default: s = [input.size(d) for d in dim]
dim (Tuple[int], optional) – Dimensions to be transformed.
Default: all dimensions, or the last len(s) dimensions if s is given.
norm (str, optional) –
Normalization mode. For the forward transform
(rfftn()), these correspond to:
"forward" - normalize by 1/n
"backward" - no normalization
"ortho" - normalize by 1/sqrt(n) (making the real FFT orthonormal)
Where n = is the logical FFT size.
Calling the backward transform () with the same
normalization mode will apply an overall normalization of between
the two transforms. This is required to make
the exact inverse.
out (Tensor, optional) – the output tensor.
>>> t = torch.rand(10, 10)
>>> rfftn = torch.fft.rfftn(t)
>>> rfftn.size()
torch.Size([10, 6])
Compared against the full output from fftn(), we have all
elements up to the Nyquist frequency.
>>> fftn = torch.fft.fftn(t)
>>> torch.testing.assert_close(fftn[..., :6], rfftn, check_stride=False)
The discrete Fourier transform is separable, so rfftn()
here is equivalent to a combination of fft() and
rfft():
>>> two_ffts = torch.fft.fft(torch.fft.rfft(t, dim=1), dim=0)
>>> torch.testing.assert_close(rfftn, two_ffts, check_stride
1/nDefault is "backward" (no normalization).