% ML exhaustive search for Gauss-Markov h
%
% originally written by Hai Chen, May 2000
%
% assumes that the symbols are -1 and +1
%
% for N=13, Memory=2, a runtime test
%  using get_A.m and FSM_inc.m:	    64.502 secs.
%  using get_A_C.c and FSM_inc_C.c: 52.986 secs,
%  a decrease of 17.854%
%
function min_b = get_GM_ML()

global N;
global HUGE_VAL;

global pilot;
global pilot_index;

s = [-1; 1];
nsyms = size(s,1);
nstates = prod( nsyms*ones(1,N));	% nstates = nsyms ** N

c = ones( 1, N);

min_cost = HUGE_VAL;

if( isempty(pilot))
  pb = [];
else
  pb = pilot(pilot_index);
end

for i = 1:nstates

  b = s(c);

  if( isempty(pb) | all( b(pilot_index) == pb) )

    cost = get_GM_ML_cost( b);
  
    if( cost < min_cost)
      min_cost = cost;
      min_b = b;
    end
  
  end

  FSM_inc_C( c, nsyms);
  
end
