2D phase of Fourier transform is not behaving as expected
Show older comments
Hello. I am trying to compute the 2D FFT of a very simple image, a 2000x2000 matrix of zeros with a small 100x100 square of 1s in the center. I can obtain the complex amplitude correctly (a 2D sinc function), but I am having trouble when computing the phase. First, I have seen that I obtain a phase that is wrapped between -pi and pi. I have therefore tried unwrapping the phase first along rows and then unwrap that along the columns as well. Still, I obtain a phase which looks like a 45 degrees gradient. My understanding is that the phase of a centered square should be zero across the entire image. My suspicion is that MATLAB considers the zero frequency component of the image to be on the top left corner, and a centered rectangle would mean a shift in both vertical and horizontal direction. I have tried applying fftshift to get rid of this problem, but it persists. I think I have tried almost all combinations, using fftshift, ifftshift, unwrapping in different orders, etc... No matter what I do, I do not get the expected result. What can I try?
Here is my code for the complex phase:
canvas = zeros(2000,2000); % Create empty matrix of 2000x2000 zeros
canvas(950:1050,950:1050)=1; % Place 100x100 rectangle in the center
% Calculate 2D FFT
canvas_FFT2=(fft2(canvas)); % Take the bidimensional FFT of the canvas, shift it such that it's in the center of the image with fftshift
canvas_FFT2_ampl=abs(fftshift(canvas_FFT2)); % Extract the complex amplitude
canvas_FFT2_phase=(angle(fftshift(canvas_FFT2))); % Extracts the complex phase
canvas_FFT2_phase1=unwrap(canvas_FFT2_phase,[],1); % Unwrap it along the rows
canvas_FFT2_phase=unwrap(canvas_FFT2_phase1,[],2); % Unwrap the result along the columns to complete the 2D unwrapping
% Display results
figure(1)
subplot(1,2,1) % Plot the real space on the left in figure 1
imagesc(canvas)
colormap parula
colorbar
title("Real space")
xlabel("Pixel x")
ylabel("Pixel y")
axis equal
xlim([1,2000])
ylim([1,2000])
subplot(1,2,2) % Plot the reciprocal space on the right (complex phase) in figure 1
imagesc((canvas_FFT2_phase));
colormap parula
colorbar
title("Reciprocal space (complex phase)")
xlabel("Pixel x")
ylabel("Pixel y")
axis equal
xlim([1,2000])
ylim([1,2000])
Thank you very much!
Accepted Answer
More Answers (1)
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







