%
% BoxCar2b        Mitch Withers 20070405
% Example matlab script to demonstrate 2d FT on a boxcar
% by doing the 1d fft twice.
%
% close any old figures and clear any old variables
clear all
close all

% number of points in matrix
N=2^9;

% set matrix to zero
x=zeros(N,N);

% boxcar halfwidth
dx=2^2;

% set the center of the box car equal to one
% this will have an odd number of points in each dimension
x(N/2-dx:N/2+dx,N/2-dx:N/2+dx)=1;

% normalize by the number of ones to make the sinc max height 1
x=x/sum(sum(x));

% get the 1-d fft and shift it to center the response
y1d=fft(x);

y=fftshift(fft(y1d'));

% get a normalized vector for the frequency (and space (or time) in this case)
% axes
%x1=0:1/N:1-1/N;
x1=-0.5:1/N:0.5-1/N;

disp(' ')
disp('Plotting the space (or time domain) 2-d Boxcar function')
% plot the space (or time) domain in 3-d
mesh(x1,x1,x)
xlabel('normalized distance')
ylabel('normalized distance')
zlabel('amplitude')
orient tall
%print -depsc BoxCar2blength.ps
pause

figure
disp(' ')
disp('Plot the 1-d fft of the 2-d box car')
% plot the frequency domain in 3-d for the first 1d fft
mesh(x1,x1,abs(fftshift(y1d,1)))
xlabel('normalized frequency')
ylabel('normalized frequency')
zlabel('amplitude')
title('First 1d fft')
orient tall
%print -dpsc BoxCar2bfrequency1.ps
pause

figure
disp(' ')
disp('Plot the second 1-d fft of the transpose of the results from the previous 1-d fft')
% plot the frequency domain in 3-d for the second 1d fft
mesh(x1,x1,abs(y))
xlabel('normalized frequency')
ylabel('normalized frequency')
zlabel('amplitude')
title('Second 1d fft on output of first')
orient tall
%print -dpsc BoxCar2bfrequency2.ps

