torch.fft.ifftshift
function ifftshift(x: Tensor, options?: ShiftOptions): Tensorfunction ifftshift(x: Tensor, dim: number | number[], options?: ShiftOptions): TensorInverse operation of fftshift - restores standard FFT ordering.
Undoes the shift performed by fftshift, moving zero frequency back to the start. Always use this before ifft if you previously applied fftshift. Essential for:
- Correct ifft results: Must be done before inverse FFT to get correct signal
- Frequency filtering: Processing centered spectrum then returning to standard form
- Round-trip processing: fftshift -> process -> ifftshift -> ifft pipeline
- Batch operations: Un-shifting multiple FFT outputs before ifft
- Pipeline correctness: Ensuring no frequency wrapping in reconstructed signal
Performs the inverse circular shift to restore the standard FFT bin ordering where zero frequency is at index 0. Always use ifftshift after fftshift if doing round-trip FFT -> process -> ifft operations.
- Reversibility: Perfectly reverses fftshift() operation
- Odd lengths: Correctly handles N=odd cases where shift is asymmetric
- Batching: Respects batch dimensions if dim is specified
Must match fftshift dim: Ensure you un-shift the same dimensions you shifted
Parameters
xTensor- Input tensor (typically shifted FFT output) of any shape
optionsShiftOptionsoptional- Shift options: -
dim: Dimension(s) along which to shift (default: all dimensions)
Returns
Tensor– Tensor with same shape and dtype as input, in standard FFT bin orderExamples
// Basic un-shifting
const spectrum = torch.fft.fft(signal);
const centered = torch.fft.fftshift(spectrum);
// ... process centered spectrum ...
const back = torch.fft.ifftshift(centered);
const reconstructed = torch.fft.ifft(back);// Specific dimension un-shift
const unshifted_dim1 = torch.fft.ifftshift(x, { dim: 1 });See Also
- PyTorch torch.fft.ifftshift()
- fftshift - Forward shift (center zero frequency)
- ifft - Inverse FFT (use after ifftshift)
- fft - Forward FFT (use before fftshift)