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.
1-D Inverse FFT: ifft
Section titled “1-D Inverse FFT: ifft”The ifft function computes the Inverse Discrete Fourier Transform (IDFT) of a vector or the columns of a matrix.
Syntax Overview
Section titled “Syntax Overview”x = ifft(Y)x = ifft(Y, n)x = ifft(Y, [], dim)x = ifft(Y, ..., 'symmetric')x = ifft(Y): Computes the inverse transform ofY.x = ifft(Y, n): Computes then-point inverse transform.Yis padded with zeros or truncated to lengthn.x = ifft(Y, [], dim): Performs the IFFT along a specific dimensiondim.'symmetric'flag: An important optimization. Use it when the inputYis 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.
Example 1: Reconstructing a Signal
Section titled “Example 1: Reconstructing a Signal”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 componentsFs = 1000; % Sampling frequencyt = 0:1/Fs:1-1/Fs; % Time vectorsignal = sin(2*pi*50*t) + 0.5*sin(2*pi*120*t);
% 2. Compute the Fourier TransformY = 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 Plotfigure;tiledlayout(2, 1);
% Original Signalnexttile;plot(t, signal);title('Original Signal');xlabel('Time (s)');ylabel('Amplitude');grid on;
% Reconstructed Signalnexttile;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)]);2-D Inverse FFT: ifft2
Section titled “2-D Inverse FFT: ifft2”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 imageI = imread('cameraman.tif'); % Load a standard demo imageI = 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 filteringF = 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 pixelsmask = sqrt(u.^2 + v.^2) < cutoff_freq;
% 4. Apply the mask to the frequency dataF_filtered = F .* mask;
% 5. Compute the Inverse 2-D FFT% Use ifftshift to move the zero-frequency back before IFFTI_filtered = ifft2(ifftshift(F_filtered), 'symmetric');
% 6. Display resultsfigure;tiledlayout(1, 2);
nexttile;imshow(I);title('Original Image');
nexttile;imshow(I_filtered);title('Low-Pass Filtered Image');Important Considerations
Section titled “Important Considerations”Normalization and Power
Section titled “Normalization and Power”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.
Zero-Padding
Section titled “Zero-Padding”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.
Debugging Tips
Section titled “Debugging Tips”- Real vs. Complex Output: If your original signal
xwas real,ifft(fft(x))should also be real. Due to floating-point errors, it might have a tiny, negligible imaginary part. Usereal(ifft(...))or the'symmetric'flag to discard it. fftshift/ifftshift: When visualizing or filtering in the frequency domain, always usefftshiftto center the spectrum. Remember to useifftshiftto reverse the process before applyingifft2.