scico.numpy.fft#

Discrete Fourier Transform functions.

Functions

fft(a[, n, axis, norm])

Compute the one-dimensional discrete Fourier Transform.

fft2(a[, s, axes, norm])

Compute the 2-dimensional discrete Fourier Transform.

fftfreq(n[, d, dtype])

Return the Discrete Fourier Transform sample frequencies.

fftn(a[, s, axes, norm])

Compute the N-dimensional discrete Fourier Transform.

fftshift(x[, axes])

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

hfft(a[, n, axis, norm])

Compute the FFT of a signal that has Hermitian symmetry, i.e., a real

ifft(a[, n, axis, norm])

Compute the one-dimensional inverse discrete Fourier Transform.

ifft2(a[, s, axes, norm])

Compute the 2-dimensional inverse discrete Fourier Transform.

ifftn(a[, s, axes, norm])

Compute the N-dimensional inverse discrete Fourier Transform.

ifftshift(x[, axes])

The inverse of fftshift.

ihfft(a[, n, axis, norm])

Compute the inverse FFT of a signal that has Hermitian symmetry.

irfft(a[, n, axis, norm])

Computes the inverse of rfft.

irfft2(a[, s, axes, norm])

Computes the inverse of rfft2.

irfftn(a[, s, axes, norm])

Computes the inverse of rfftn.

rfft(a[, n, axis, norm])

Compute the one-dimensional discrete Fourier Transform for real input.

rfft2(a[, s, axes, norm])

Compute the 2-dimensional FFT of a real array.

rfftfreq(n[, d, dtype])

Return the Discrete Fourier Transform sample frequencies

rfftn(a[, s, axes, norm])

Compute the N-dimensional discrete Fourier Transform for real input.

scico.numpy.fft.fft(a, n=None, axis=-1, norm=None)#

Compute the one-dimensional discrete Fourier Transform.

LAX-backend implementation of numpy.fft.fft.

Original docstring below.

This function computes the one-dimensional n-point discrete Fourier Transform (DFT) with the efficient Fast Fourier Transform (FFT) algorithm [CT].

Parameters:
  • a (array_like) – Input array, can be complex.

  • n (int, optional) – Length of the transformed axis of the output. If n is smaller than the length of the input, the input is cropped. If it is larger, the input is padded with zeros. If n is not given, the length of the input along the axis specified by axis is used.

  • axis (int, optional) – Axis over which to compute the FFT. If not given, the last axis is used.

  • norm ({"backward", "ortho", "forward"}, optional) –

Return type:

Array

Returns:

out (complex ndarray) – The truncated or zero-padded input, transformed along the axis indicated by axis, or the last one if axis is not specified.

scico.numpy.fft.fft2(a, s=None, axes=(-2, -1), norm=None)#

Compute the 2-dimensional discrete Fourier Transform.

LAX-backend implementation of numpy.fft.fft2.

Original docstring below.

This function computes the n-dimensional discrete Fourier Transform over any axes in an M-dimensional array by means of the Fast Fourier Transform (FFT). By default, the transform is computed over the last two axes of the input array, i.e., a 2-dimensional FFT.

Parameters:
  • a (array_like) – Input array, can be complex

  • s (sequence of ints, optional) – Shape (length of each transformed axis) of the output (s[0] refers to axis 0, s[1] to axis 1, etc.). This corresponds to n for fft(x, n). Along each axis, if the given shape is smaller than that of the input, the input is cropped. If it is larger, the input is padded with zeros. if s is not given, the shape of the input along the axes specified by axes is used.

  • axes (sequence of ints, optional) – Axes over which to compute the FFT. If not given, the last two axes are used. A repeated index in axes means the transform over that axis is performed multiple times. A one-element sequence means that a one-dimensional FFT is performed.

  • norm ({"backward", "ortho", "forward"}, optional) –

Return type:

Array

Returns:

out (complex ndarray) – The truncated or zero-padded input, transformed along the axes indicated by axes, or the last two axes if axes is not given.

scico.numpy.fft.fftfreq(n, d=1.0, *, dtype=None)#

Return the Discrete Fourier Transform sample frequencies.

LAX-backend implementation of numpy.fft.fftfreq.

Original docstring below.

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
Parameters:
  • n (int) – Window length.

  • d (scalar, optional) – Sample spacing (inverse of the sampling rate). Defaults to 1.

  • dtype (Optional) – The dtype of the returned frequencies. If not specified, JAX’s default floating point dtype will be used.

Return type:

Array

Returns:

f (ndarray) – Array of length n containing the sample frequencies.

scico.numpy.fft.fftn(a, s=None, axes=None, norm=None)#

Compute the N-dimensional discrete Fourier Transform.

LAX-backend implementation of numpy.fft.fftn.

Original docstring below.

This function computes the N-dimensional discrete Fourier Transform over any number of axes in an M-dimensional array by means of the Fast Fourier Transform (FFT).

Parameters:
  • a (array_like) – Input array, can be complex.

  • s (sequence of ints, optional) – Shape (length of each transformed axis) of the output (s[0] refers to axis 0, s[1] to axis 1, etc.). This corresponds to n for fft(x, n). Along any axis, if the given shape is smaller than that of the input, the input is cropped. If it is larger, the input is padded with zeros. if s is not given, the shape of the input along the axes specified by axes is used.

  • axes (sequence of ints, optional) – Axes over which to compute the FFT. If not given, the last len(s) axes are used, or all axes if s is also not specified. Repeated indices in axes means that the transform over that axis is performed multiple times.

  • norm ({"backward", "ortho", "forward"}, optional) –

Return type:

Array

Returns:

out (complex ndarray) – The truncated or zero-padded input, transformed along the axes indicated by axes, or by a combination of s and a, as explained in the parameters section above.

scico.numpy.fft.fftshift(x, axes=None)#

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

LAX-backend implementation of numpy.fft.fftshift.

Original docstring below.

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.

Return type:

Array

Returns:

y (ndarray) – The shifted array.

scico.numpy.fft.hfft(a, n=None, axis=-1, norm=None)#

Compute the FFT of a signal that has Hermitian symmetry, i.e., a real

LAX-backend implementation of numpy.fft.hfft.

Original docstring below.

spectrum.

Parameters:
  • a (array_like) – The input array.

  • n (int, optional) – Length of the transformed axis of the output. For n output points, n//2 + 1 input points are necessary. If the input is longer than this, it is cropped. If it is shorter than this, it is padded with zeros. If n is not given, it is taken to be 2*(m-1) where m is the length of the input along the axis specified by axis.

  • axis (int, optional) – Axis over which to compute the FFT. If not given, the last axis is used.

  • norm ({"backward", "ortho", "forward"}, optional) –

Return type:

Array

Returns:

out (ndarray) – The truncated or zero-padded input, transformed along the axis indicated by axis, or the last one if axis is not specified. The length of the transformed axis is n, or, if n is not given, 2*m - 2 where m is the length of the transformed axis of the input. To get an odd number of output points, n must be specified, for instance as 2*m - 1 in the typical case,

scico.numpy.fft.ifft(a, n=None, axis=-1, norm=None)#

Compute the one-dimensional inverse discrete Fourier Transform.

LAX-backend implementation of numpy.fft.ifft.

Original docstring below.

This function computes the inverse of the one-dimensional n-point discrete Fourier transform computed by fft. In other words, ifft(fft(a)) == a to within numerical accuracy. For a general description of the algorithm and definitions, see numpy.fft.

The input should be ordered in the same way as is returned by fft, i.e.,

  • a[0] should contain the zero frequency term,

  • a[1:n//2] should contain the positive-frequency terms,

  • a[n//2 + 1:] should contain the negative-frequency terms, in increasing order starting from the most negative frequency.

For an even number of input points, A[n//2] represents the sum of the values at the positive and negative Nyquist frequencies, as the two are aliased together. See numpy.fft for details.

Parameters:
  • a (array_like) – Input array, can be complex.

  • n (int, optional) – Length of the transformed axis of the output. If n is smaller than the length of the input, the input is cropped. If it is larger, the input is padded with zeros. If n is not given, the length of the input along the axis specified by axis is used. See notes about padding issues.

  • axis (int, optional) – Axis over which to compute the inverse DFT. If not given, the last axis is used.

  • norm ({"backward", "ortho", "forward"}, optional) –

Return type:

Array

Returns:

out (complex ndarray) – The truncated or zero-padded input, transformed along the axis indicated by axis, or the last one if axis is not specified.

scico.numpy.fft.ifft2(a, s=None, axes=(-2, -1), norm=None)#

Compute the 2-dimensional inverse discrete Fourier Transform.

LAX-backend implementation of numpy.fft.ifft2.

Original docstring below.

This function computes the inverse of the 2-dimensional discrete Fourier Transform over any number of axes in an M-dimensional array by means of the Fast Fourier Transform (FFT). In other words, ifft2(fft2(a)) == a to within numerical accuracy. By default, the inverse transform is computed over the last two axes of the input array.

The input, analogously to ifft, should be ordered in the same way as is returned by fft2, i.e. it should have the term for zero frequency in the low-order corner of the two axes, the positive frequency terms in the first half of these axes, the term for the Nyquist frequency in the middle of the axes and the negative frequency terms in the second half of both axes, in order of decreasingly negative frequency.

Parameters:
  • a (array_like) – Input array, can be complex.

  • s (sequence of ints, optional) – Shape (length of each axis) of the output (s[0] refers to axis 0, s[1] to axis 1, etc.). This corresponds to n for ifft(x, n). Along each axis, if the given shape is smaller than that of the input, the input is cropped. If it is larger, the input is padded with zeros. if s is not given, the shape of the input along the axes specified by axes is used. See notes for issue on ifft zero padding.

  • axes (sequence of ints, optional) – Axes over which to compute the FFT. If not given, the last two axes are used. A repeated index in axes means the transform over that axis is performed multiple times. A one-element sequence means that a one-dimensional FFT is performed.

  • norm ({"backward", "ortho", "forward"}, optional) –

Return type:

Array

Returns:

out (complex ndarray) – The truncated or zero-padded input, transformed along the axes indicated by axes, or the last two axes if axes is not given.

scico.numpy.fft.ifftn(a, s=None, axes=None, norm=None)#

Compute the N-dimensional inverse discrete Fourier Transform.

LAX-backend implementation of numpy.fft.ifftn.

Original docstring below.

This function computes the inverse of the N-dimensional discrete Fourier Transform over any number of axes in an M-dimensional array by means of the Fast Fourier Transform (FFT). In other words, ifftn(fftn(a)) == a to within numerical accuracy. For a description of the definitions and conventions used, see numpy.fft.

The input, analogously to ifft, should be ordered in the same way as is returned by fftn, i.e. it should have the term for zero frequency in all axes in the low-order corner, the positive frequency terms in the first half of all axes, the term for the Nyquist frequency in the middle of all axes and the negative frequency terms in the second half of all axes, in order of decreasingly negative frequency.

Parameters:
  • a (array_like) – Input array, can be complex.

  • s (sequence of ints, optional) – Shape (length of each transformed axis) of the output (s[0] refers to axis 0, s[1] to axis 1, etc.). This corresponds to n for ifft(x, n). Along any axis, if the given shape is smaller than that of the input, the input is cropped. If it is larger, the input is padded with zeros. if s is not given, the shape of the input along the axes specified by axes is used. See notes for issue on ifft zero padding.

  • axes (sequence of ints, optional) – Axes over which to compute the IFFT. If not given, the last len(s) axes are used, or all axes if s is also not specified. Repeated indices in axes means that the inverse transform over that axis is performed multiple times.

  • norm ({"backward", "ortho", "forward"}, optional) –

Return type:

Array

Returns:

out (complex ndarray) – The truncated or zero-padded input, transformed along the axes indicated by axes, or by a combination of s or a, as explained in the parameters section above.

scico.numpy.fft.ifftshift(x, axes=None)#

The inverse of fftshift. Although identical for even-length x, the

LAX-backend implementation of numpy.fft.ifftshift.

Original docstring below.

functions differ by one sample for odd-length x.

Parameters:
  • x (array_like) – Input array.

  • axes (int or shape tuple, optional) – Axes over which to calculate. Defaults to None, which shifts all axes.

Return type:

Array

Returns:

y (ndarray) – The shifted array.

scico.numpy.fft.ihfft(a, n=None, axis=-1, norm=None)#

Compute the inverse FFT of a signal that has Hermitian symmetry.

LAX-backend implementation of numpy.fft.ihfft.

Original docstring below.

Parameters:
  • a (array_like) – Input array.

  • n (int, optional) – Length of the inverse FFT, the number of points along transformation axis in the input to use. If n is smaller than the length of the input, the input is cropped. If it is larger, the input is padded with zeros. If n is not given, the length of the input along the axis specified by axis is used.

  • axis (int, optional) – Axis over which to compute the inverse FFT. If not given, the last axis is used.

  • norm ({"backward", "ortho", "forward"}, optional) –

Return type:

Array

Returns:

out (complex ndarray) – The truncated or zero-padded input, transformed along the axis indicated by axis, or the last one if axis is not specified. The length of the transformed axis is n//2 + 1.

scico.numpy.fft.irfft(a, n=None, axis=-1, norm=None)#

Computes the inverse of rfft.

LAX-backend implementation of numpy.fft.irfft.

Original docstring below.

This function computes the inverse of the one-dimensional n-point discrete Fourier Transform of real input computed by rfft. In other words, irfft(rfft(a), len(a)) == a to within numerical accuracy. (See Notes below for why len(a) is necessary here.)

The input is expected to be in the form returned by rfft, i.e. the real zero-frequency term followed by the complex positive frequency terms in order of increasing frequency. Since the discrete Fourier Transform of real input is Hermitian-symmetric, the negative frequency terms are taken to be the complex conjugates of the corresponding positive frequency terms.

Parameters:
  • a (array_like) – The input array.

  • n (int, optional) – Length of the transformed axis of the output. For n output points, n//2+1 input points are necessary. If the input is longer than this, it is cropped. If it is shorter than this, it is padded with zeros. If n is not given, it is taken to be 2*(m-1) where m is the length of the input along the axis specified by axis.

  • axis (int, optional) – Axis over which to compute the inverse FFT. If not given, the last axis is used.

  • norm ({"backward", "ortho", "forward"}, optional) –

Return type:

Array

Returns:

out (ndarray) – The truncated or zero-padded input, transformed along the axis indicated by axis, or the last one if axis is not specified. The length of the transformed axis is n, or, if n is not given, 2*(m-1) where m is the length of the transformed axis of the input. To get an odd number of output points, n must be specified.

scico.numpy.fft.irfft2(a, s=None, axes=(-2, -1), norm=None)#

Computes the inverse of rfft2.

LAX-backend implementation of numpy.fft.irfft2.

Original docstring below.

Parameters:
  • a (array_like) – The input array

  • s (sequence of ints, optional) – Shape of the real output to the inverse FFT.

  • axes (sequence of ints, optional) – The axes over which to compute the inverse fft. Default is the last two axes.

  • norm ({"backward", "ortho", "forward"}, optional) –

Return type:

Array

Returns:

out (ndarray) – The result of the inverse real 2-D FFT.

scico.numpy.fft.irfftn(a, s=None, axes=None, norm=None)#

Computes the inverse of rfftn.

LAX-backend implementation of numpy.fft.irfftn.

Original docstring below.

This function computes the inverse of the N-dimensional discrete Fourier Transform for real input over any number of axes in an M-dimensional array by means of the Fast Fourier Transform (FFT). In other words, irfftn(rfftn(a), a.shape) == a to within numerical accuracy. (The a.shape is necessary like len(a) is for irfft, and for the same reason.)

The input should be ordered in the same way as is returned by rfftn, i.e. as for irfft for the final transformation axis, and as for ifftn along all the other axes.

Parameters:
  • a (array_like) – Input array.

  • s (sequence of ints, optional) – Shape (length of each transformed axis) of the output (s[0] refers to axis 0, s[1] to axis 1, etc.). s is also the number of input points used along this axis, except for the last axis, where s[-1]//2+1 points of the input are used. Along any axis, if the shape indicated by s is smaller than that of the input, the input is cropped. If it is larger, the input is padded with zeros. If s is not given, the shape of the input along the axes specified by axes is used. Except for the last axis which is taken to be 2*(m-1) where m is the length of the input along that axis.

  • axes (sequence of ints, optional) – Axes over which to compute the inverse FFT. If not given, the last len(s) axes are used, or all axes if s is also not specified. Repeated indices in axes means that the inverse transform over that axis is performed multiple times.

  • norm ({"backward", "ortho", "forward"}, optional) –

Return type:

Array

Returns:

out (ndarray) – The truncated or zero-padded input, transformed along the axes indicated by axes, or by a combination of s or a, as explained in the parameters section above. The length of each transformed axis is as given by the corresponding element of s, or the length of the input in every axis except for the last one if s is not given. In the final transformed axis the length of the output when s is not given is 2*(m-1) where m is the length of the final transformed axis of the input. To get an odd number of output points in the final axis, s must be specified.

scico.numpy.fft.rfft(a, n=None, axis=-1, norm=None)#

Compute the one-dimensional discrete Fourier Transform for real input.

LAX-backend implementation of numpy.fft.rfft.

Original docstring below.

This function computes the one-dimensional n-point discrete Fourier Transform (DFT) of a real-valued array by means of an efficient algorithm called the Fast Fourier Transform (FFT).

Parameters:
  • a (array_like) – Input array

  • n (int, optional) – Number of points along transformation axis in the input to use. If n is smaller than the length of the input, the input is cropped. If it is larger, the input is padded with zeros. If n is not given, the length of the input along the axis specified by axis is used.

  • axis (int, optional) – Axis over which to compute the FFT. If not given, the last axis is used.

  • norm ({"backward", "ortho", "forward"}, optional) –

Return type:

Array

Returns:

out (complex ndarray) – The truncated or zero-padded input, transformed along the axis indicated by axis, or the last one if axis is not specified. If n is even, the length of the transformed axis is (n/2)+1. If n is odd, the length is (n+1)/2.

scico.numpy.fft.rfft2(a, s=None, axes=(-2, -1), norm=None)#

Compute the 2-dimensional FFT of a real array.

LAX-backend implementation of numpy.fft.rfft2.

Original docstring below.

Parameters:
  • a (array) – Input array, taken to be real.

  • s (sequence of ints, optional) – Shape of the FFT.

  • axes (sequence of ints, optional) – Axes over which to compute the FFT.

  • norm ({"backward", "ortho", "forward"}, optional) –

Return type:

Array

Returns:

out (ndarray) – The result of the real 2-D FFT.

scico.numpy.fft.rfftfreq(n, d=1.0, *, dtype=None)#

Return the Discrete Fourier Transform sample frequencies

LAX-backend implementation of numpy.fft.rfftfreq.

Original docstring below.

(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.

Parameters:
  • n (int) – Window length.

  • d (scalar, optional) – Sample spacing (inverse of the sampling rate). Defaults to 1.

  • dtype (Optional) – The dtype of the returned frequencies. If not specified, JAX’s default floating point dtype will be used.

Return type:

Array

Returns:

f (ndarray) – Array of length n//2 + 1 containing the sample frequencies.

scico.numpy.fft.rfftn(a, s=None, axes=None, norm=None)#

Compute the N-dimensional discrete Fourier Transform for real input.

LAX-backend implementation of numpy.fft.rfftn.

Original docstring below.

This function computes the N-dimensional discrete Fourier Transform over any number of axes in an M-dimensional real array by means of the Fast Fourier Transform (FFT). By default, all axes are transformed, with the real transform performed over the last axis, while the remaining transforms are complex.

Parameters:
  • a (array_like) – Input array, taken to be real.

  • s (sequence of ints, optional) – Shape (length along each transformed axis) to use from the input. (s[0] refers to axis 0, s[1] to axis 1, etc.). The final element of s corresponds to n for rfft(x, n), while for the remaining axes, it corresponds to n for fft(x, n). Along any axis, if the given shape is smaller than that of the input, the input is cropped. If it is larger, the input is padded with zeros. if s is not given, the shape of the input along the axes specified by axes is used.

  • axes (sequence of ints, optional) – Axes over which to compute the FFT. If not given, the last len(s) axes are used, or all axes if s is also not specified.

  • norm ({"backward", "ortho", "forward"}, optional) –

Return type:

Array

Returns:

out (complex ndarray) – The truncated or zero-padded input, transformed along the axes indicated by axes, or by a combination of s and a, as explained in the parameters section above. The length of the last axis transformed will be s[-1]//2+1, while the remaining transformed axes will have lengths according to s, or unchanged from the input.