% cost_update( col, v, vl) - update FIR and G for time-varying ISI
%
function cost_update( col, v, vl)

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

global G;

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

% disp('cost_update'), col

if( col < N)
  c1 = col + 1;
  if( isempty(B) ) % called from x4_em_init
    FIR = FIR_save(:,c1);
    trans = FSM_trans( states, FIR);
  else
    if( ~isempty(G))
      t = B(c1,:)';
      G = inv( t*(t'/var_noise(c1)) + inv_Rh);
      FIR = G * (t*(z(c1)/var_noise(c1)) + inv_Rh_d);
      trans = FSM_trans( states, FIR);
    end
  end
end
