fn

ifftshift

Tensor
ifftshift(input: Tensor, dim: int | Sequence[int] | None = None)
source

Undo the zero-frequency centring performed by fftshift.

Performs the inverse of fftshift: given a centred spectrum (with DC at the middle of each axis), restores the standard FFT frequency ordering (DC at index 0).

For an axis of length NN, the operation is a circular shift of (N//2)-(N//2) positions, which is exactly N/2\lceil N/2 \rceil positions in the forward direction (i.e., the ceiling variant rather than the floor used by fftshift). For even NN the two shifts have the same magnitude; for odd NN they differ by one.

Parameters

inputTensor
Tensor in centred-spectrum ordering (typically the output of fftshift), of any shape.
dimint or sequence of int= None
Axis or axes along which to shift. Defaults to all axes.

Returns

Tensor

Tensor with the same shape and dtype as input, rearranged back to the standard FFT ordering (DC at index 0 of each specified axis).

Notes

Exact inverse — for any tensor x and any axis selection dim:

ifftshift(fftshift(x,dim),dim)=x,\text{ifftshift}(\text{fftshift}(x, \text{dim}), \text{dim}) = x, fftshift(ifftshift(x,dim),dim)=x.\text{fftshift}(\text{ifftshift}(x, \text{dim}), \text{dim}) = x.

Even vs. odd — for even NN, fftshift and ifftshift are identical (both shift by N/2N/2). For odd NN, fftshift shifts by N/2\lfloor N/2 \rfloor and ifftshift shifts by N/2-\lfloor N/2 \rfloor (= shift by N/2\lceil N/2 \rceil forward), so they are distinct operations. Always use the matching call to guarantee an exact round-trip.

Typical use — when a signal has been constructed or modified in centred-frequency space (e.g. a 2-D optical transfer function defined as centred), ifftshift must be applied before feeding it into ifftn to recover the correct spatial-domain signal.

Examples

Round-trip through fftshift / ifftshift:
>>> X = lucid.fft.fft(lucid.randn(16))
>>> X_c = lucid.fft.fftshift(X)
>>> X_back = lucid.fft.ifftshift(X_c)
>>> # X_back ≈ X  (exact, not approximate)
Typical pipeline for constructing a centred filter:
>>> N = 64
>>> freqs = lucid.fft.fftshift(lucid.fft.fftfreq(N))
>>> # Build H_centred (e.g. Gaussian low-pass) in centred coords
>>> # H = ...
>>> # Then convert back to FFT ordering before inverting:
>>> # x_filtered = lucid.fft.ifft(lucid.fft.ifftshift(H))