fn

ihfft

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

1-D inverse FFT of a real signal, giving a Hermitian half-spectrum.

Computes the inverse of hfft: given a real-valued input, returns the conjugate of its one-sided real FFT. The output is complex and has length N/2+1\lfloor N/2 \rfloor + 1 along axis dim.

Mathematically:

Y[k]=rfft(x)[k],k=0,1,,N/2,Y[k] = \overline{\text{rfft}(x)[k]}, \quad k = 0, 1, \ldots, \lfloor N/2 \rfloor,

where ()\overline{(\cdot)} denotes complex conjugation and the dual normalisation is applied to match hfft.

Parameters

inputTensor
Real-valued input tensor of any shape.
nint= None
Number of input samples to use. If None, the full axis length is used.
dimint= -1
Axis over which to compute the transform. Default is -1.
normstr or None= None
Normalisation mode — "backward" (default), "forward", or "ortho". See fftn for the full description.

Returns

Tensor

Complex tensor (complex64) with the same shape as input except that axis dim has length n/2+1\lfloor n/2 \rfloor + 1.

Notes

Round-trip with hfft — for a real tensor x of length NN:

hfft(ihfft(x,N),N)x.\text{hfft}(\text{ihfft}(x, N), N) \approx x.

Negative imaginary parts — because ihfft conjugates the rfft output, the imaginary parts of the result are the negatives of those from rfft. For a real input, rfft(x)[0] and rfft(x)[N//2] (for even NN) are both real, so ihfft(x)[0] and ihfft(x)[N//2] are also real.

Examples

Compute the Hermitian half-spectrum:
>>> x = lucid.randn(64)
>>> H = lucid.fft.ihfft(x)
>>> H.shape   # 64 // 2 + 1 = 33
(33,)
Round-trip check:
>>> x_rec = lucid.fft.hfft(H, n=64)
>>> x_rec.shape
(64,)