torch.fft.rfft — PyTorch 2.7 documentation (original) (raw)

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, use fft()

Note

Supports torch.half on CUDA with GPU Architecture SM53 or greater. However it only supports powers of 2 signal length in every transformed dimension.

Parameters

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 frequency T[-2] == T[2] is it’s own symmetric pair, and therefore must always be real-valued.