function bestseqs = mseqburitertest(n)
% bestseq = mseqburitertest(iters)
%
% This sequence will test all possible combinations of shifts.
%
% This function finds many 1st and 2nd order counterbalanced 9 level msequences and
% sees which has the lowest amount of autocorrelation.
%
% The msequences are created using the Buracas Method.  The msequence
% generator called in this function is subject to copyright.
%
% Contact Wesley Kerr
% wesleytk@sas.upenn.edu
 
if nargin<1
    n=1;
end
 
nlength=length(mseqburmeth(3));
corrmin=16;
counter=0;
 
for i=1:nlength
    count=0;
    seq=pseudomseq6(i);
    countbal=mtest(seq,0,2,1);
    if size(countbal)==[9 18]
        for k=1:8
            for l=1:16
                if countbal(k,l)==0
                    count=9;
                end
            end
        end
        if count<5
            corr=mtest(seq,1);
            counter=counter+1;
            seqs=[counter, corr, seq'];
        end
    end
    fprintf('Done %d %d \n',i,j)
    clear corr count seq countbal
end
 
seqord=sortrows(seqs,2);
bestseqs=zeros(nlength,n);
for i=1:n
    seqout=seqord(i,3:end)';
    bestseqs(:,i)=seqout;
end
 
csvwrite('/jet/kerr/class/mseq/burmseqs',bestseqs)