% Rodrigo Parra - June 2004 
function B=dirty_beam(u,v);


M = max( max ( abs( u ) , abs( v ) ) );

u = u / M;
v = v / M;

Np = length( u );

a = 20;             % Range for the space domain
Ng = 100;           % Number of points in the space grid

l = linspace ( -a , a , Ng );

[ x , y ] = meshgrid ( l );


% Main loop
% creates a CUBE of size Ng x Ng x Np
% each plane contains the IFT of each uv point
% suming along the third dimension one obtains
% the IFT of the uv coverage.

B = zeros(size(x));
for i = 1 : Np
  
% K( : , : , i ) = exp ( j * ( u(i) * x + v(i) * y ) );

temp( : , : ) = exp ( j * ( u(i) * x + v(i) * y ) );

B = B + temp;

end

% Suming along the 3d dimension
%B = sum( K , 3 );

% Normalization
B = B / max ( B ( : ) );

% Sexy image
surf(l,l,abs(B),'EdgeColor','none','FaceColor','interp','FaceLighting','phong')
camlight
xlabel( 'x' );ylabel( 'y' );zlabel( '|B(x,y)|' )
