function s=SpectralPartition(G);
% SPECTRALPARTITION find approximate two frequency partition
%   s=SpectralPartition(G); finds for a given link gain matrix G an
%   approximation to the best partition into four submatrices, such
%   that the maximum of the largest eigenvalues of the two diagonal
%   blocks is minimized.  The result is given by the binary index s
%   for one of the submatrices.

n=size(G,1);
G2=G.^2;
[V,E]=eig(G2);
[dummy,k]=min(diag(E));
[v,id]=sort(V(:,k));
for p=1:n-1
  r(p)=max([max(eig(G(id(1:p),id(1:p))))...
       max(eig(G(id(p+1:n),id(p+1:n))))]);
end
[rmin,p]=min(r); 
disp(rmin)
s=zeros(1,n);
s(id(1:p))=1;
s=logical(s);