viterbi_generator/tests/utils/make_increment.m
function [ INCREMENT ] = make_increment(SYMBOLS,NEXT,Rhh)
%
% MAKE_INCREMENT:
%           This function returns a lookuptable containing the
%           metric increments related to moving from state n to m.
%           The data is arranged so that the increment accosiated 
%           with a move from state n to m is located in 
%           INCREMENT(n,m). To minimize computations only legal
%           transitions are considdered.
%
% SYNTAX:   [ INCREMENT ] = make_increment(SYMBOLS,NEXT,Rhh)
%
% INPUT:    SYMBOLS: The table of symbols corresponding the the state-
%                    numbers.
%           NEXT:    A transition table containing the next legal
%                    states, as it is generated by the code make_next.
%           Rhh:     The autocorrelation as estimated by mf.m.
%
% OUTPUT:   INCREMENT:
%                    The increment table as described above.
%
% SUB_FUNC: None
%
% WARNINGS: There is no syntax checking on input or output.
%
% TEST(S):  By hand, against expected values.
%
% AUTOR:    Jan H. Mikkelsen / Arne Norre Ekstrm
% EMAIL:    hmi@kom.auc.dk / aneks@kom.auc.dk
%
% $Id: make_increment.m,v 1.6 1997/09/22 11:39:34 aneks Exp $

% IN THIS PEACE OF CODE THE SYNTAX CHECKING IS MINIMAL
% THIS HAS BEEN CHOSEN TO AVOID THE OVERHEAD. RECALL THAT
% THIS CODE IS EXECUTED EACH TIME A BURST IS RECEIVED.

% FIND THE NUMBER OF SYMBOLS THAT WE HAVE
%
[M,Lh]=size(SYMBOLS);

% INITIALIZE THE INCREMENT MATRIX
%
INCREMENT=zeros(M);

% RECALL THAT THE I SEQUENCE AS IT IS STORED IN STORED AS:
% [ I(n-1) I(n-2) I(n-3) ... I(n-Lh) ]
%
% ALSO RECALL THAT Rhh IS STORED AS:
% [ Rhh(1) Rhh(2) Rhh(3) ... Rhh(Lh) ]
%
% THE FORMULA TO USE IS:
% INCREMENT(n,m)
% =
% real(conj(I(n))*(I(n-Lh)*Rhh(Lh)+I(n-Lh+1)*Rhh(Lh-1)+...+I(n-1)*Rhh(1))
%
% THEY CAN THUS BE MULTIPLIED DIRECTLY WITH EACH OTHER

% LOOP OVER THE STATES, AS FOUND IN THE ROWS IN SYMBOLS.
%
for n=1:M, 
  % ONLY TWO LEGAL NEXT STATES EXIST, SO THE LOOP IS UNROLLED
  %
  m=NEXT(n,1);

  INCREMENT(n,m)=real((conj(SYMBOLS(m,1))*SYMBOLS(n,:))*Rhh(2:Lh+1).');
  m=NEXT(n,2);

  INCREMENT(n,m)=real((conj(SYMBOLS(m,1))*SYMBOLS(n,:))*Rhh(2:Lh+1).');
end

