fn

irfft

Tensor
irfft(input: Tensor, n: int | None = None, dim: int = -1, norm: str | None = None)
source

1-D inverse FFT for a Hermitian-symmetric spectrum.

Computes the inverse one-dimensional FFT of a conjugate-symmetric (Hermitian) spectrum, as produced by rfft, and returns a real-valued output.

Given an input of length m=N/2+1m = \lfloor N/2 \rfloor + 1, the full-length real output has length NN. The default assumption is that N=2(m1)N = 2(m-1) (even); supply n explicitly when the original signal length was odd.

Parameters

inputTensor
Complex Hermitian input tensor (the one-sided spectrum produced by rfft), of any shape.
nint= None
Length of the output (real) axis. If None, the output length defaults to 2(m1)2(m - 1) where mm is the input axis length. Pass the original signal length to avoid the even/odd ambiguity.
dimint= -1
Axis over which to compute the inverse transform. Default is -1 (last axis).
normstr or None= None
Normalisation mode — "backward" (default), "forward", or "ortho". See fftn for the full description.

Returns

Tensor

Real tensor (float32) with the same shape as input except that axis dim has length n (or 2(m1)2(m-1) when n is None).

Notes

Odd-length signals — if the original real signal had odd length NN, the rfft output has (N+1)/2(N+1)/2 bins. The default 2(m1)2(m-1) rule gives N1N-1 instead of NN. Always pass n=N explicitly when the original length was odd.

Normalisation parity — to faithfully invert rfft, use the same norm value for both the forward and inverse calls.

Examples

Round-trip with explicit length:
>>> x = lucid.randn(100)              # odd length
>>> X = lucid.fft.rfft(x)
>>> X.shape                           # 51
(51,)
>>> x_rec = lucid.fft.irfft(X, n=100)
>>> x_rec.shape
(100,)
Default (even-length assumption):
>>> X = lucid.fft.rfft(lucid.randn(128))
>>> lucid.fft.irfft(X).shape          # 2*(65-1) = 128
(128,)