clear
% ----------------------------------------------------------
%
% Two dimensional Fourier transform example:
% It shows the Fourier amplitude of an image
% consisting of two gaussian sources.
% One source is fixed at the origine while the
% other one can be moved using the mouse.
% click on the image to enable draggig
% click again to disable (like a FLIP-FLOP)
%
% TO DO:
%
% 1) write everything in a single file (I'm sure is possible)
% 2) combine gpos0 and gpos1 in one single function
%    using a binary switch (I'm sure is possible too)
%
% (c) Rodrigo Parra 2005 -----------------------------------

a = 10;
L=linspace( -a , a , 2^7 );

[ x , y ]=meshgrid( L , L );
[ u , v ]=meshgrid( L/2 , L/2 );

FWHM1 = 1.5;
FWHM2 = 1.5;

a1 = FWHM1^2 / ( 8 * log( 2 ) );
a2 = FWHM2^2 / ( 8 * log( 2 ) );



x10 = 0 ; y10 = 0;
f1 = ( 1 / ( 4 * pi * a1 ) ) * exp( -( ( x - x10 ).^2 + ( y - y10 ).^2 ) / ( 4 * a1 ) );
F1 = exp( -a1 * ( u.^2 + v.^2 ) ) .* exp( -j * ( u * x10 + v * y10 ) );

x20 = -4; y20 = 0;
f2 = ( 1 / ( 4 * pi * a2 ) ) * exp( -( ( x - x20 ).^2 + ( y - y20 ).^2 ) / ( 4 * a2 ) );

h=figure('WindowButtonDownFcn','gpos1(h,a,f1,F1,L,x,y,u,v,a2);'...
	,'Toolbar','none'...
	,'Pointer','crosshair'...
	,'Units','normalized'...
	,'Name','2D Fourier transform example'...
	,'NumberTitle','off');

h2=subplot(122)
imagesc( L/2 , L/2 , abs(F1) );axis square;axis xy
xlabel('u');ylabel('v');title('Fourier Amplitude')
h1=subplot(121)
imagesc( L , L , f1 );axis square;axis xy
xlabel('x');ylabel('y');title('Image')
