flopscope.

flopscope.numpy.fft.fftshift

fnp.fft.fftshift(x, axes=None)[flopscope source][numpy source]

Shift the zero-frequency component to the center of the spectrum.

Adapted from NumPy docs np.fft.fftshift

Areafft
Typefree
Cost
0
Flopscope Context

Shift zero-frequency component to center. No arithmetic; index reordering only.

This function swaps half-spaces for all axes listed (defaults to all). Note that y[0] is the Nyquist component only if len(x) is even.

Parameters

x:array_like

Input array.

axes:int or shape tuple, optional

Axes over which to shift. Default is None, which shifts all axes.

Returns

y:ndarray

The shifted array.

See also

Examples

>>> import flopscope.numpy as fnp
>>> freqs = flops.fft.fftfreq(10, 0.1)
>>> freqs
array([ 0.,  1.,  2., ..., -3., -2., -1.])
>>> flops.fft.fftshift(freqs)
array([-5., -4., -3., -2., -1.,  0.,  1.,  2.,  3.,  4.])

Shift the zero-frequency component only along the second axis:

>>> freqs = flops.fft.fftfreq(9, d=1./9).reshape(3, 3)
>>> freqs
array([[ 0.,  1.,  2.],
       [ 3.,  4., -4.],
       [-3., -2., -1.]])
>>> flops.fft.fftshift(freqs, axes=(1,))
array([[ 2.,  0.,  1.],
       [-4.,  3.,  4.],
       [-1., -3., -2.]])