numpy.fft.ifft#
- fft.ifft(a,n=None,axis=-1,norm=None,out=None)[source]#
Compute the one-dimensional inverse discrete Fourier Transform.
This function computes the inverse of the one-dimensionaln-pointdiscrete Fourier transform computed by
fft. In other words,ifft(fft(a))==ato within numerical accuracy.For a general description of the algorithm and definitions,seenumpy.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, inincreasing order starting from the most negative frequency.
For an even number of input points,
A[n//2]represents the sum ofthe values at the positive and negative Nyquist frequencies, as the twoare aliased together. Seenumpy.fftfor details.- Parameters:
- aarray_like
Input array, can be complex.
- nint, optional
Length of the transformed axis of the output.Ifn is smaller than the length of the input, the input is cropped.If it is larger, the input is padded with zeros. Ifn is not given,the length of the input along the axis specified byaxis is used.See notes about padding issues.
- axisint, optional
Axis over which to compute the inverse DFT. If not given, the lastaxis is used.
- norm{“backward”, “ortho”, “forward”}, optional
Normalization mode (see
numpy.fft). Default is “backward”.Indicates which direction of the forward/backward pair of transformsis scaled and with what normalization factor.New in version 1.20.0:The “backward”, “forward” values were added.
- outcomplex ndarray, optional
If provided, the result will be placed in this array. It should beof the appropriate shape and dtype.
New in version 2.0.0.
- Returns:
- outcomplex ndarray
The truncated or zero-padded input, transformed along the axisindicated byaxis, or the last one ifaxis is not specified.
- Raises:
- IndexError
Ifaxis is not a valid axis ofa.
See also
Notes
If the input parametern is larger than the size of the input, the inputis padded by appending zeros at the end. Even though this is the commonapproach, it might lead to surprising results. If a different padding isdesired, it must be performed before calling
ifft.Examples
>>>importnumpyasnp>>>np.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:
>>>importmatplotlib.pyplotasplt>>>t=np.arange(400)>>>n=np.zeros((400,),dtype=complex)>>>n[40:60]=np.exp(1j*np.random.uniform(0,2*np.pi,(20,)))>>>s=np.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()
