Phase of 2D Rect Fourier Transform

I have been able to create a 3D rectangular pulse and to evaluate the fft of it, but when it comes to the phase it looks like it’s wrong shifted. The phase should only admitt values 0,pi (or -pi) instead is multiplied by a linear shift. I guess it's because matlab is receiving the pulse not centered in the way it is wanted. Is there a way to fix it, to have a correct phase’s graph? Thanks!
close all
clear
clc
npoints=512;
perc=1;
dt=6*1E-7/(npoints*perc); % Tempo di campionamento
df=1/(npoints*dt); % Frequenza di campionamento
t(1)=0;
f(1)=0;
for k=2:npoints/2
t(k)=(k-1)*dt;
t(npoints-k+2)=-t(k);
f(k)=(k-1)*df;
f(npoints-k+2)=-f(k);
end
t(npoints/2+1)=t(npoints/2+2)-dt;
f(npoints/2+1)=f(npoints/2+2)-df;
ts=ifftshift(t);
fs=fftshift(f);
figure
[X,Y]=meshgrid(ts,ts);
D = npoints/2; % to indicate origin at the center of the function
a = 100; % change it to enlarge or reduce the pulse
y = repmat(1:npoints,npoints,1);
x = y';
rect = zeros(npoints);
rect(D-a:D+a-1,D-a:D+a-1) = ones(2*a);
rect=(rect);
surf(X,Y,rect);
shading interp
axis tight
title ('Rect 3D');
rect=ifftshift(rect);
figure, surf(X,Y,rect);
shading interp
axis tight
title ('Rect 3D shifted');
R = fft2((rect));
R = fftshift(R);
[X,Y]=meshgrid(fs,fs);
figure;
surf(X,Y,abs(R));
shading interp
axis tight
title('Fourier Transform of Rectangular function');
%plot real part
figure;
surf(X,Y,real(R));
shading interp
axis tight
title('Real part');
Rm=abs(R);
imm=imag(R);
re=real(R);
re(abs(re) < 1e-12) = 0;
imm(abs(imm) < 1e-12) = 0;
phase=atan2(imm, re);
%plot phase
[X,Y]=meshgrid(fs,fs);
figure
surf(X,Y,phase);
shading flat
axis tight
title ('Phase of the rect');

3 Comments

I got closer to the solution by replacing
R = fft2((rect));
with:
R = (fft(ifftshift(fft(rect).')).');
and
phase=atan2(imm, re);
with
R=re+imm;
phase=angle(R);
The graph that I get shows only value between 0 and pi, and the linear phase shift is removed. But if I see the graph from the top I see some diagonal lines... is the graph correct?
Hi vittorio,
a bit hard to say. If the matrix you are fft'ing has the same pattern as this (here n = 8, pulse width = 5)
ans =
1 1 1 0 0 0 1 1
1 1 1 0 0 0 1 1
1 1 1 0 0 0 1 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
1 1 1 0 0 0 1 1
1 1 1 0 0 0 1 1
with the upper corner of ones being the largest, then the fft should be real and the phase plot does whatever it does. Incidentally,
R=re+imm; phase=angle(R);
is not correct because imm is real, so it needs a factor of i.
Hi David, thanks for your answer.
I solved the problem, the solution if you or someone is interested, is available here:
Basically I forgot to multiply for the imaginary part, just as you said. And I recreated the rect pulse using the Matlab function rectpulse.

Sign in to comment.

Answers (0)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Asked:

on 7 Jun 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!