Shortcuts

torch.rfft

torch.rfft(input, signal_ndim, normalized=False, onesided=True) → Tensor

Real-to-complex Discrete Fourier Transform

This method computes the real-to-complex discrete Fourier transform. It is mathematically equivalent with fft() with differences only in formats of the input and output.

This method supports 1D, 2D and 3D real-to-complex transforms, indicated by signal_ndim. input must be a tensor with at least signal_ndim dimensions with optionally arbitrary number of leading batch dimensions. If normalized is set to True, this normalizes the result by dividing it with i=1KNi\sqrt{\prod_{i=1}^K N_i} so that the operator is unitary, where NiN_i is the size of signal dimension ii .

The real-to-complex Fourier transform results follow conjugate symmetry:

X[ω1,,ωd]=X[N1ω1,,Ndωd],X[\omega_1, \dots, \omega_d] = X^*[N_1 - \omega_1, \dots, N_d - \omega_d],

where the index arithmetic is computed modulus the size of the corresponding dimension,  \ ^* is the conjugate operator, and dd = signal_ndim. onesided flag controls whether to avoid redundancy in the output results. If set to True (default), the output will not be full complex result of shape (,2)(*, 2) , where * is the shape of input, but instead the last dimension will be halfed as of size Nd2+1\lfloor \frac{N_d}{2} \rfloor + 1 .

The inverse of this function is irfft().

Note

For CUDA tensors, an LRU cache is used for cuFFT plans to speed up repeatedly running FFT methods on tensors of same geometry with same configuration. See cuFFT plan cache for more details on how to monitor and control the cache.

Warning

For CPU tensors, this method is currently only available with MKL. Use torch.backends.mkl.is_available() to check if MKL is installed.

Parameters
  • input (Tensor) – the input tensor of at least signal_ndim dimensions

  • signal_ndim (int) – the number of dimensions in each signal. signal_ndim can only be 1, 2 or 3

  • normalized (bool, optional) – controls whether to return normalized results. Default: False

  • onesided (bool, optional) – controls whether to return half of results to avoid redundancy. Default: True

Returns

A tensor containing the real-to-complex Fourier transform result

Return type

Tensor

Example:

>>> x = torch.randn(5, 5)
>>> torch.rfft(x, 2).shape
torch.Size([5, 3, 2])
>>> torch.rfft(x, 2, onesided=False).shape
torch.Size([5, 5, 2])

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources