0
0
SciPydata~5 mins

Inverse FFT (ifft) in SciPy

Choose your learning style9 modes available
Introduction

Inverse FFT helps us change data from frequency back to time or space. It is useful to understand original signals after analyzing their frequencies.

You have frequency data from a sound and want to hear the original sound again.
You analyzed an image in frequency form and want to see the original picture.
You processed sensor data in frequency and want to return to the original measurements.
You want to check how changes in frequency affect the original signal.
You want to reconstruct a signal after filtering in the frequency domain.
Syntax
SciPy
scipy.fft.ifft(x, n=None, axis=-1, norm=None, overwrite_x=False, workers=None, plan=None)

x is the input array in frequency domain.

n is the length of the output. If not given, it matches input length.

Examples
Basic inverse FFT on a simple list of frequency data.
SciPy
from scipy.fft import ifft
x = [1, 2, 3, 4]
time_signal = ifft(x)
Inverse FFT on complex frequency data.
SciPy
import numpy as np
from scipy.fft import ifft
x = np.array([1+0j, 0+1j, -1+0j, 0-1j])
time_signal = ifft(x)
Inverse FFT with output length longer than input, zero-padding frequency data.
SciPy
from scipy.fft import ifft
x = [1, 2, 3, 4]
time_signal = ifft(x, n=8)
Sample Program

This program shows how to convert time data to frequency data using FFT, then back to time data using inverse FFT. The recovered data is complex due to computation but the real part matches the original.

SciPy
from scipy.fft import fft, ifft
import numpy as np

# Original time data: a simple wave
time_data = np.array([1, 2, 3, 4])

# Convert to frequency domain
freq_data = fft(time_data)

# Convert back to time domain using inverse FFT
recovered_time_data = ifft(freq_data)

print("Original time data:", time_data)
print("Frequency data:", freq_data)
print("Recovered time data (complex):", recovered_time_data)
print("Recovered time data (real part):", recovered_time_data.real)
OutputSuccess
Important Notes

The output of ifft is complex even if input is real. Usually, the imaginary part is very close to zero and can be ignored.

Use .real to get the real part of the inverse FFT result if you expect real signals.

Inverse FFT length n can be different from input length to pad or truncate the signal.

Summary

Inverse FFT changes frequency data back to original time or space data.

Output is complex; usually, the real part is the meaningful signal.

Useful to reconstruct signals after frequency analysis or filtering.