Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

NumPy - Inverse Fourier Transform



NumPy Inverse Fourier Transform

The Inverse Fourier Transform is the process of converting a frequency-domain representation of a signal back into the time-domain.

In NumPy, the Inverse Fourier Transform can be computed using the numpy.fft.ifft() function for one-dimensional arrays and numpy.fft.ifftn() function for multi-dimensional arrays.

The inverse transform is essential when you need to reconstruct a signal after manipulating its frequency components, such as in filtering, noise reduction, or spectral analysis.

Inverse Fast Fourier Transform

The numpy.fft.ifft() function computes the Inverse Fast Fourier Transform (IFFT) of a one-dimensional array. It transforms a signal from the frequency domain back to the time domain, essentially reconstructing the original signal.

ifft(x) = Inverse FFT of the input array x

Example: Computing the Inverse FFT

In the following example, we compute the Inverse Fast Fourier Transform of a one-dimensional array (frequency-domain signal) using the ifft() function −

import numpy as np

# Define a frequency-domain signal (computed via FFT previously)
fft_signal = np.array([10+0j, -2+2j, -2+0j, -2-2j])

# Compute the Inverse Fast Fourier Transform
time_signal = np.fft.ifft(fft_signal)

print("Reconstructed time-domain signal:", time_signal)

We get the output as shown below −

Reconstructed time-domain signal: [1.+0.j 2.+0.j 3.+0.j 4.+0.j]

IFFT for Real Signals

The numpy.fft.irfft() function is used to compute the inverse FFT for real-valued signals. This function is optimized for reconstructing the original time-domain signal from its non-negative frequency components, which is particularly useful for real-valued input data.

irfft(x) = Inverse FFT of a real-valued input array x

Example: Inverse FFT for Real Signals

In the following example, we compute the inverse FFT for a real-valued frequency-domain signal −

import numpy as np

# Define a real-valued frequency-domain signal (computed via rfft previously)
fft_real_signal = np.array([10+0j, -2+2j])

# Compute the Inverse FFT of the real-valued signal
reconstructed_real_signal = np.fft.irfft(fft_real_signal)

print("Reconstructed real-valued time-domain signal:", reconstructed_real_signal)

The result produced is as follows −

Reconstructed real-valued time-domain signal: [4. 6.]

IFT in Multi-dimensional Arrays

For multi-dimensional arrays, NumPy provides the numpy.fft.ifftn() function to compute the n-dimensional inverse FFT. This function can be used to reconstruct signals in multiple dimensions (e.g., 2D or 3D signals).

ifftn(x) = N-dimensional Inverse FFT of the input array x

Example: 2D Inverse FFT

In the following example, we compute the 2-dimensional inverse FFT of a 2D frequency-domain array −

import numpy as np

# Define a 2D frequency-domain signal (computed via fftn previously)
fft_2d_signal = np.array([[10+0j, -2+2j], [-2+0j, -2-2j]])

# Compute the 2D Inverse Fast Fourier Transform
reconstructed_2d_signal = np.fft.ifftn(fft_2d_signal)

print("Reconstructed 2D time-domain signal:", reconstructed_2d_signal)

After executing the above code, we get the following output −

Reconstructed 2D time-domain signal: 
[[1.+0.j 3.+0.j]
 [3.+1.j 3.-1.j]]

Important Considerations for IFT

Following are the important considerations for inverse Fourier Transforms −

  • When performing an inverse Fourier transform, the result may contain complex numbers, even if the input was real-valued. The real part of the result can be extracted using np.real() function, or the imaginary part can be discarded if it is negligible.
  • The inverse FFT is highly sensitive to the quality of the frequency-domain data. If any data is lost or corrupted in the frequency domain, the reconstruction in the time domain may be inaccurate.
  • The sampling rate and spacing between points in the original signal (before applying FFT) are important when interpreting the reconstructed signal, as they determine the frequency resolution and the temporal resolution of the transform.
Advertisements