% get_cost( zz, cur, next, j, el) - compute cost of state transition
%
% for EM algorithm and the uniform channel coefficient distribution
% derived in ~/src/viterbi.papers/em/isi.txt
%
function w = OLD_get_cost( zz, cur, next, j, el)

global trans;
global states;
global HUGE_VAL;
global FIR;
global Memory;

global G;

w = HUGE_VAL;

% handle initial times when the channel contains 0's
%
if( j <= Memory)
  if( j == 1)
    s_cur = zeros(1,Memory);
  else
    s_cur = [states(1:j-1,cur)' zeros(1,Memory-j+1)];
  end
  if( j == Memory)
    s_next = states(:,next)';
  else
    s_next = [states(1:j,next)' zeros(1,Memory-j)];
  end
  if( Memory > 1)
    a = all( s_cur(1:Memory-1) == s_next(2:Memory));
  else
    a = 0;
  end
  if( (Memory == 1) | (a ~= 0))
    y = [s_next s_cur(Memory)];
  else
    return;
  end
else
  w = trans( cur, next); % just to check for feasible state transitions
  if( w == HUGE_VAL)
    return;
  else
    y = [states(:,next)' states(Memory,cur)];
  end
end

w = y * FIR;

w = zz - w;

w = w * w + y*G*y';
