ifftshift
→Tensorifftshift(input: Tensor, dim: int | Sequence[int] | None = None)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 , the operation is a circular shift
of positions, which is exactly
positions in the forward direction (i.e., the ceiling variant
rather than the floor used by fftshift). For even
the two shifts have the same magnitude; for odd
they differ by one.
Parameters
inputTensorfftshift), of any shape.dimint or sequence of int= NoneReturns
TensorTensor 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:
Even vs. odd — for even , fftshift and
ifftshift are identical (both shift by ). For
odd , fftshift shifts by
and ifftshift shifts by (= shift
by 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))