Phase of 2D Rect Fourier Transform
Show older comments
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
vittorio todisco
on 7 Jun 2017
David Goodmanson
on 9 Jun 2017
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.
vittorio todisco
on 9 Jun 2017
Answers (0)
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!
