Shortcuts

torch.fft.fftn

torch.fft.fftn(input, s=None, dim=None, norm=None, *, out=None)Tensor

Computes the N dimensional discrete Fourier transform of input.

Note

The Fourier domain representation of any real signal satisfies the Hermitian property: X[i_1, ..., i_n] = conj(X[-i_1, ..., -i_n]). This function always returns all positive and negative frequency terms even though, for real inputs, half of these values are redundant. rfftn() returns the more compact one-sided representation where only the positive frequencies of the last dimension are returned.

Parameters
  • 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 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 (fftn()), these correspond to:

    • "forward" - normalize by 1/n

    • "backward" - no normalization

    • "ortho" - normalize by 1/sqrt(n) (making the FFT orthonormal)

    Where n = prod(s) is the logical FFT size. Calling the backward transform (ifftn()) with the same normalization mode will apply an overall normalization of 1/n between the two transforms. This is required to make ifftn() the exact inverse.

    Default is "backward" (no normalization).

Keyword Arguments

out (Tensor, optional) – the output tensor.

Example

>>> x = torch.rand(10, 10, dtype=torch.complex64)
>>> fftn = torch.fft.fftn(x)

The discrete Fourier transform is separable, so fftn() here is equivalent to two one-dimensional fft() calls:

>>> two_ffts = torch.fft.fft(torch.fft.fft(x, dim=0), dim=1)
>>> torch.testing.assert_close(fftn, two_ffts, check_stride=False)

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