fn

hfftn

Tensor
hfftn(input: Tensor, s: int | Sequence[int] | None = None, dim: int | Sequence[int] | None = None, norm: str | None = None)
source

N-dimensional FFT of a Hermitian-symmetric complex signal.

Computes the N-dimensional DFT of a signal that is known to be Hermitian (conjugate-symmetric), producing a real-valued output. The input is the half-spectrum as conventionally stored by rfftn or constructed manually: the first n//2+1n//2 + 1 bins along the last transformed axis, with no redundancy stored.

The implementation uses the identity:

hfftn(x,n,norm)=irfftn(x,n,norm=dual(norm)),\text{hfftn}(x, n, \text{norm}) = \text{irfftn}(x^*, n, \text{norm}=\text{dual}(\text{norm})),

where xx^* is the element-wise complex conjugate and dual swaps "backward""forward" while leaving "ortho" unchanged. This is mathematically equivalent to a forward DFT on a Hermitian signal: conjugating the input flips the sign in the exponent, converting the inverse-real transform into a forward-real one.

Parameters

inputTensor
Complex Hermitian half-spectrum tensor of any shape. The last transformed axis is the compressed one-sided axis (length N/2+1\lfloor N/2 \rfloor + 1).
sint or sequence of int= None
Full output signal length(s) along each transformed axis. The last value gives the full real length of the last axis. If None, the last axis defaults to 2(m1)2(m-1) where mm is the input last-axis length.
dimint or sequence of int= None
Axis or axes over which to compute the transform. Defaults to all axes.
normstr or None= None
Normalisation mode — "backward" (default), "forward", or "ortho". Note that the dual normalisation is applied internally; the semantics mirror those of fftn.

Returns

Tensor

Real tensor (float32) whose shape matches input except that the last transformed axis has length s[-1] (or 2(m1)2(m-1) when s is None), and all other transformed axes have lengths s[i].

Notes

Relationship to rfft / irfft — the Hermitian FFT pair (hfftn / ihfftn) is the Fourier-domain dual of the real FFT pair (rfftn / irfftn):

  • rfftn takes a real time-domain signal → half complex spectrum.
  • hfftn takes a half complex Hermitian signal (frequency domain) → real output in the transform domain.

Sign conventionhfftn uses the forward FFT sign convention (ei2πkn/Ne^{-i2\pi kn/N}) applied to the Hermitian input. This means applying hfftn followed by ihfftn recovers the original half-spectrum (up to floating-point rounding).

Examples

Recover a real spectrum from a Hermitian half-spectrum:
>>> x_complex = lucid.randn(33)   # half-spectrum for N=64
>>> y = lucid.fft.hfftn(x_complex, s=[64])
>>> y.shape
(64,)
N-dimensional example:
>>> x = lucid.randn(16, 33)           # last axis: 33 = 64//2+1
>>> y = lucid.fft.hfftn(x, s=[16, 64])
>>> y.shape
(16, 64)