module documentation

Discrete Fourier Transforms - helper.py

Function fftfreq Return the Discrete Fourier Transform sample frequencies.
Function fftshift Shift the zero-frequency component to the center of the spectrum.
Function ifftshift The inverse of fftshift. Although identical for even-length x, the functions differ by one sample for odd-length x.
Function rfftfreq Return the Discrete Fourier Transform sample frequencies (for usage with rfft, irfft).
Variable integer_types Undocumented
Function _fftshift_dispatcher Undocumented
@set_module('numpy.fft')
def fftfreq(n, d=1.0): (source)

Return the Discrete Fourier Transform sample frequencies.

The returned float array f contains the frequency bin centers in cycles per unit of the sample spacing (with zero at the start). For instance, if the sample spacing is in seconds, then the frequency unit is cycles/second.

Given a window length n and a sample spacing d:

f = [0, 1, ...,   n/2-1,     -n/2, ..., -1] / (d*n)   if n is even
f = [0, 1, ..., (n-1)/2, -(n-1)/2, ..., -1] / (d*n)   if n is odd

Examples

>>> signal = np.array([-2, 8, 6, 4, 1, 0, 3, 5], dtype=float)
>>> fourier = np.fft.fft(signal)
>>> n = signal.size
>>> timestep = 0.1
>>> freq = np.fft.fftfreq(n, d=timestep)
>>> freq
array([ 0.  ,  1.25,  2.5 , ..., -3.75, -2.5 , -1.25])
Parameters
n:intWindow length.
d:scalar, optionalSample spacing (inverse of the sampling rate). Defaults to 1.
Returns
ndarrayf - Array of length n containing the sample frequencies.
@array_function_dispatch(_fftshift_dispatcher, module='numpy.fft')
def fftshift(x, axes=None): (source)

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

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.

See Also

ifftshift
The inverse of fftshift.

Examples

>>> freqs = np.fft.fftfreq(10, 0.1)
>>> freqs
array([ 0.,  1.,  2., ..., -3., -2., -1.])
>>> np.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 = np.fft.fftfreq(9, d=1./9).reshape(3, 3)
>>> freqs
array([[ 0.,  1.,  2.],
       [ 3.,  4., -4.],
       [-3., -2., -1.]])
>>> np.fft.fftshift(freqs, axes=(1,))
array([[ 2.,  0.,  1.],
       [-4.,  3.,  4.],
       [-1., -3., -2.]])
Parameters
x:array_likeInput array.
axes:int or shape tuple, optionalAxes over which to shift. Default is None, which shifts all axes.
Returns
ndarrayy - The shifted array.
@array_function_dispatch(_fftshift_dispatcher, module='numpy.fft')
def ifftshift(x, axes=None): (source)

The inverse of fftshift. Although identical for even-length x, the functions differ by one sample for odd-length x.

See Also

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

Examples

>>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3)
>>> freqs
array([[ 0.,  1.,  2.],
       [ 3.,  4., -4.],
       [-3., -2., -1.]])
>>> np.fft.ifftshift(np.fft.fftshift(freqs))
array([[ 0.,  1.,  2.],
       [ 3.,  4., -4.],
       [-3., -2., -1.]])
Parameters
x:array_likeInput array.
axes:int or shape tuple, optionalAxes over which to calculate. Defaults to None, which shifts all axes.
Returns
ndarrayy - The shifted array.
@set_module('numpy.fft')
def rfftfreq(n, d=1.0): (source)

Return the Discrete Fourier Transform sample frequencies (for usage with rfft, irfft).

The returned float array f contains the frequency bin centers in cycles per unit of the sample spacing (with zero at the start). For instance, if the sample spacing is in seconds, then the frequency unit is cycles/second.

Given a window length n and a sample spacing d:

f = [0, 1, ...,     n/2-1,     n/2] / (d*n)   if n is even
f = [0, 1, ..., (n-1)/2-1, (n-1)/2] / (d*n)   if n is odd

Unlike fftfreq (but like scipy.fftpack.rfftfreq) the Nyquist frequency component is considered to be positive.

Examples

>>> signal = np.array([-2, 8, 6, 4, 1, 0, 3, 5, -3, 4], dtype=float)
>>> fourier = np.fft.rfft(signal)
>>> n = signal.size
>>> sample_rate = 100
>>> freq = np.fft.fftfreq(n, d=1./sample_rate)
>>> freq
array([  0.,  10.,  20., ..., -30., -20., -10.])
>>> freq = np.fft.rfftfreq(n, d=1./sample_rate)
>>> freq
array([  0.,  10.,  20.,  30.,  40.,  50.])
Parameters
n:intWindow length.
d:scalar, optionalSample spacing (inverse of the sampling rate). Defaults to 1.
Returns
ndarrayf - Array of length n//2 + 1 containing the sample frequencies.
integer_types = (source)

Undocumented

def _fftshift_dispatcher(x, axes=None): (source)

Undocumented