Rate this Page

torch.fft.irfft#

torch.fft.irfft(input,n=None,dim=-1,norm=None,*,out=None)Tensor#

Computes the inverse ofrfft().

input is interpreted as a one-sided Hermitian signal in the Fourierdomain, as produced byrfft(). By the Hermitian property, theoutput will be real-valued.

Note

Some input frequencies must be real-valued to satisfy the Hermitianproperty. In these cases the imaginary component will be ignored.For example, any imaginary component in the zero-frequency term cannotbe represented in a real output and so will always be ignored.

Note

The correct interpretation of the Hermitian input depends on the length ofthe original data, as given byn. This is because each input shapecould correspond to either an odd or even length signal. By default, thesignal is assumed to be even length and odd signals will not round-tripproperly. So, it is recommended to always pass the signal lengthn.

Note

Supports torch.half and torch.chalf on CUDA with GPU Architecture SM53 or greater.However it only supports powers of 2 signal length in every transformed dimension.With default arguments, size of the transformed dimension should be (2^n + 1) as argumentn defaults to even output size = 2 * (transformed_dim_size - 1)

Parameters:
  • input (Tensor) – the input tensor representing a half-Hermitian signal

  • n (int,optional) – Output signal length. This determines the length of theoutput signal. If given, the input will either be zero-padded or trimmed to thislength before computing the real IFFT.Defaults to even output:n=2*(input.size(dim)-1).

  • dim (int,optional) – The dimension along which to take the one dimensional real IFFT.

  • norm (str,optional) –

    Normalization mode. For the backward transform(irfft()), these correspond to:

    • "forward" - no normalization

    • "backward" - normalize by1/n

    • "ortho" - normalize by1/sqrt(n) (making the real IFFT orthonormal)

    Calling the forward transform (rfft()) with the samenormalization mode will apply an overall normalization of1/n betweenthe two transforms. This is required to makeirfft()the exact inverse.

    Default is"backward" (normalize by1/n).

Keyword Arguments:

out (Tensor,optional) – the output tensor.

Example

>>>t=torch.linspace(0,1,5)>>>ttensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000])>>>T=torch.fft.rfft(t)>>>Ttensor([ 2.5000+0.0000j, -0.6250+0.8602j, -0.6250+0.2031j])

Without specifying the output length toirfft(), the outputwill not round-trip properly because the input is odd-length:

>>>torch.fft.irfft(T)tensor([0.1562, 0.3511, 0.7812, 1.2114])

So, it is recommended to always pass the signal lengthn:

>>>roundtrip=torch.fft.irfft(T,t.numel())>>>torch.testing.assert_close(roundtrip,t,check_stride=False)