% cost_init() - initialize time-varying ISI FIR and G
%
function cost_init()

global trans;
global states;
global FIR;
global FIR_save;
global Memory;

global G;

global N;
global B;
global inv_Rh;
global inv_Rh_d;
global var_noise;
global z;

% disp('cost_init');

if( isempty(B) ) % called from x4_em_init
  FIR = FIR_save(:,1);
  if( ~isempty(G) )
    G = inv( diag( (N-[0:Memory]) ./ (sum(var_noise)/N)) + inv_Rh);
  end
else
  if( isempty(G))
    FIR = B\(z');
  else
    t = B(1,:)';
    G = inv( t*(t'/var_noise(1)) + inv_Rh);
    FIR = G * (t*(z(1)/var_noise(1)) + inv_Rh_d);
  end
end

trans = FSM_trans( states, FIR);
