flopscope.

flopscope.numpy.fft.ifft

fnp.fft.ifft(a, n=None, axis=-1, norm=None, out=None)[flopscope source][numpy source]

Compute the one-dimensional inverse discrete Fourier Transform.

Adapted from NumPy docs np.fft.ifft

Areafft
Typecustom
NumPy Refnp.fft.ifft
Cost
5nlog2n5n \cdot \lceil\log_2 n\rceil
Flopscope Context

Inverse 1-D complex FFT. Cost: 5*n*ceil(log2(n)) (Cooley-Tukey radix-2; Van Loan 1992 §1.4).

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 flops.fft.

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

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

Normalization mode (see flops.fft). Default is "backward". Indicates which direction of the forward/backward pair of transforms is scaled and with what normalization factor.

Added in version 1.20.0.
out:complex ndarray, optional

If provided, the result will be placed in this array. It should be of the appropriate shape and dtype.

Added in version 2.0.0.

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.

Raises

:IndexError

If axis is not a valid axis of a.

See also

Notes

If the input parameter n is larger than the size of the input, the input is padded by appending zeros at the end. Even though this is the common approach, it might lead to surprising results. If a different padding is desired, it must be performed before calling ifft.

Examples

>>> import flopscope.numpy as fnp
>>> flops.fft.ifft([0, 4, 0, 0])
array([ 1.+0.j,  0.+1.j, -1.+0.j,  0.-1.j]) # may vary

Create and plot a band-limited signal with random phases:

>>> import matplotlib.pyplot as plt
>>> t = flops.arange(400)
>>> n = flops.zeros((400,), dtype=complex)
>>> n[40:60] = flops.exp(1j*flops.random.uniform(0, 2*flops.pi, (20,)))
>>> s = flops.fft.ifft(n)
>>> plt.plot(t, s.real, label='real')
[<matplotlib.lines.Line2D object at ...>]
>>> plt.plot(t, s.imag, '--', label='imaginary')
[<matplotlib.lines.Line2D object at ...>]
>>> plt.legend()
<matplotlib.legend.Legend object at ...>
>>> plt.show()