% evaluate f on search grid
% r(row,col) = f([phi0(row) phi1(col)])
%
function [r,row,col] = f2d( phi0, phi1, N, x, y)
 e0 = exp(i*phi0); e1 = exp(i*phi1); sN1 = sqrt(N-1);
 r = zeros( length(phi0), length(phi1) );
 col = 1; row = 1; rmin = 1e99;
 for j=1:length(phi1)
  z = (e1(j)*(1-e0)*sN1/N)*x + ((-e0*(N-1)-1)/N)*y;
  [zmin,zi] = min(abs(z));
  if( zmin < rmin) col=j; row=zi; rmin=zmin; end;
  r(:,j) = z;
 end
end
