fn
rfft
→Tensorrfft(input: Tensor, n: int | None = None, dim: int = -1, norm: str | None = None)1-D FFT of a real-valued input along a single axis.
Computes the one-dimensional DFT of a real signal and returns only the non-redundant complex output bins. For a real input of length , the DFT satisfies , so only unique complex values need to be stored.
The mathematical definition is identical to fft:
Parameters
inputTensorReal-valued input tensor of any shape.
nint= NoneNumber of input samples used (along
dim). The axis is
zero-padded or truncated to this length before the transform.
If None, the full axis length is used.dimint= -1Axis over which to compute the transform. Default is
-1
(last axis).normstr or None= NoneNormalisation mode —
"backward" (default), "forward", or
"ortho". See fftn for the full description.Returns
TensorComplex tensor (complex64) with the same shape as input
except that axis dim has length
(where is the effective input length along that axis).
Notes
Output size — for an input axis of length the output has complex bins:
- Bin 0 is the DC component (purely real for a real input).
- Bins 1 through are complex (positive frequencies).
- Bin is the Nyquist component (purely real for even ).
Inverse — use irfft to reconstruct the real signal.
You must pass the original length n to resolve the even/odd
ambiguity when the output of rfft has an odd number of bins.
Examples
Real FFT of a length-128 signal:
>>> x = lucid.randn(128)
>>> X = lucid.fft.rfft(x)
>>> X.shape # 128 // 2 + 1 = 65
(65,)
Round-trip:
>>> x_rec = lucid.fft.irfft(X, n=128)
>>> x_rec.shape
(128,)