Skip to content

MATLAB - Inverse Fourier transform

Modern Fourier Analysis: The Inverse Transform

Section titled “Modern Fourier Analysis: The Inverse Transform”

The Inverse Fast Fourier Transform (IFFT) is the counterpart to the Fast Fourier Transform (FFT). While the fft function converts a signal from the time (or spatial) domain to the frequency domain, the ifft function transforms it back. This transform pair is fundamental to modern signal and image processing, enabling frequency-domain filtering, analysis, and data compression.

The ifft function computes the Inverse Discrete Fourier Transform (IDFT) of a vector or the columns of a matrix.

x = ifft(Y)
x = ifft(Y, n)
x = ifft(Y, [], dim)
x = ifft(Y, ..., 'symmetric')
  • x = ifft(Y): Computes the inverse transform of Y.
  • x = ifft(Y, n): Computes the n-point inverse transform. Y is padded with zeros or truncated to length n.
  • x = ifft(Y, [], dim): Performs the IFFT along a specific dimension dim.
  • 'symmetric' flag: An important optimization. Use it when the input Y is known to be conjugate symmetric (the typical result of an FFT on a real signal). It enforces a purely real output and can be faster.

This example shows the round-trip process: creating a signal, transforming it to the frequency domain with fft, and transforming it back with ifft.

% 1. Create a signal with two frequency components
Fs = 1000; % Sampling frequency
t = 0:1/Fs:1-1/Fs; % Time vector
signal = sin(2*pi*50*t) + 0.5*sin(2*pi*120*t);
% 2. Compute the Fourier Transform
Y = fft(signal);
% 3. Compute the Inverse Fourier Transform
% Use the 'symmetric' flag because the original signal was real.
x_reconstructed = ifft(Y, 'symmetric');
% 4. Verify and Plot
figure;
tiledlayout(2, 1);
% Original Signal
nexttile;
plot(t, signal);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Reconstructed Signal
nexttile;
plot(t, x_reconstructed, '--');
title('Reconstructed Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Check the reconstruction error (should be very small)
reconstruction_error = max(abs(signal - x_reconstructed));
disp(['Max reconstruction error: ', num2str(reconstruction_error)]);

The ifft2 function performs the 2-D inverse transform, which is essential for image processing. It transforms a 2-D frequency representation back into a spatial image.

Practical Application: Frequency-Domain Image Filtering

Section titled “Practical Application: Frequency-Domain Image Filtering”

A powerful application is filtering images in the frequency domain. Here, we’ll create a low-pass filter to blur an image by attenuating its high-frequency components (which correspond to edges and details).

% 1. Load and prepare an image
I = imread('cameraman.tif'); % Load a standard demo image
I = im2double(I); % Convert to double for calculations
% 2. Compute the 2-D FFT
% fftshift is used to move the zero-frequency component to the center for easier filtering
F = fftshift(fft2(I));
% 3. Create a Low-Pass Filter Mask
[rows, cols] = size(I);
[u, v] = meshgrid(-(cols-1)/2:(cols-1)/2, -(rows-1)/2:(rows-1)/2);
cutoff_freq = 30; % Radius of the filter in pixels
mask = sqrt(u.^2 + v.^2) < cutoff_freq;
% 4. Apply the mask to the frequency data
F_filtered = F .* mask;
% 5. Compute the Inverse 2-D FFT
% Use ifftshift to move the zero-frequency back before IFFT
I_filtered = ifft2(ifftshift(F_filtered), 'symmetric');
% 6. Display results
figure;
tiledlayout(1, 2);
nexttile;
imshow(I);
title('Original Image');
nexttile;
imshow(I_filtered);
title('Low-Pass Filtered Image');

MATLAB’s fft/ifft pair is not unitary. The ifft function includes a 1/N normalization factor. This means ifft(fft(x)) correctly recovers x, but the energy is not conserved in the frequency domain without manual scaling. For power spectrum calculations, you must scale the fft output correctly.

Using ifft(Y, n) with n > length(Y) is equivalent to zero-padding Y in the frequency domain. This results in interpolation in the time domain, producing a smoother-looking signal by increasing the number of sample points.

  • Real vs. Complex Output: If your original signal x was real, ifft(fft(x)) should also be real. Due to floating-point errors, it might have a tiny, negligible imaginary part. Use real(ifft(...)) or the 'symmetric' flag to discard it.
  • fftshift/ifftshift: When visualizing or filtering in the frequency domain, always use fftshift to center the spectrum. Remember to use ifftshift to reverse the process before applying ifft2.