/* x7.m */

void get_x( int _K)
{
/* KB ECE 8770 Spring 1998 MSLE computer assignment */

  if( narg == 0) {

    LOADED=7;

    KALMAN = 0;

    N = 15;	/* N data samples */
    M = 9;	/* M symbol values */
    K = 1;	/* find K best completely unmerged paths */
  
    states = FSM( [0 -1 1], 2);
  
    zstate = 1;			/* zero initial state */
  
    x = [ 1  1  1  1  -1  1  1  1  1  1  -1  -1  1  -1  1];	/* input sequence */
  
    f = [0.407 0.815 0.407]'; 	/* impulse resp. coefficients of ISI channel */

    trans = FSM_trans( states, f);	/* get state transition matrix */
  
    trans(2:9,[1 4 7]) = HUGE_VAL * ones( 8, 3);

    trans(1,1) = HUGE_VAL;

    /* y = FSM_out( x, states, zstate, f);	/* get FSM output */
  
    y = [0.6260 1.2690 2.3079 2.3083 1.7497 0.3825 1.3344 2.4600 1.6636 1.6825 1.3447 -0.1439 -0.8073 0.3844 0.0658];

    noise = 0;	/* "random" noise */
  
    z = y + noise;			/* signal plus noise */

    return;
  }

  /* narg > 0 */

  if( LOADED != 2) {
    print( "get_x: call get_x with no args first.");
    return;
  }

  M = rows(states);

  if( _K > M) {
    printf( "get_x: K > M not allowed!");
    return;
  }

  K = _K;
  combos = combinations( 1:M, K);
  perms = permutations( 1:K);
  M = rows(combos);

  zstate = 0;
}


double get_yval( int _cur, int _next)
{
  return trans(_cur,_next);
}

double get_cost( double _zz, int _cur, int _next, int _j)
{
  double yval = get_yval( _cur, _next);

  if( yval == HUGE_VAL)
    return yval;

  return pn( _zz - yval);
}

vector get_ex( vector _index)
{
  vector t = states(:,1)';

  return t( _index);
}


matrix get_paths( vector _index, matrix _vp)
{
  int j, c;
  matrix xex;
  vector combo;

  c = cols(_index);
  xex = zeros( K, c);

  for( j = 1; j <= c; ++j) {
    combo = combos(_index(j),:);
    xex(:,j) = states( combo( perms( _vp(_index(j),j+1), :)));
  }

  return xex;
}

/*
From buckley@ece.vill.edu Mon Apr 20 09:27:58 1998
Received: from vu-vlsi.ee.vill.edu (vu-vlsi.ee.vill.edu [153.104.63.20]) by perry.ee.vill.edu (8.8.7/8.8.2) with ESMTP id JAA10496 for <perry@perry.ee.vill.edu>; Mon, 20 Apr 1998 09:27:55 -0400 (EDT)
Received: (from perry@localhost) by vu-vlsi.ee.vill.edu (8.8.7/8.8.2) id JAA01995 for perry@perry.ee.vill.edu; Mon, 20 Apr 1998 09:27:54 -0400 (EDT)
Received: from rigel.ee.vill.edu (rigel.ee.vill.edu [153.104.63.56]) by vu-vlsi.ee.vill.edu (8.8.7/8.8.2) with ESMTP id JAA01971 for <perry>; Mon, 20 Apr 1998 09:23:29 -0400 (EDT)
From: Kevin Buckley <buckley@ece.vill.edu>
Received: (from buckley@localhost) by rigel.ee.vill.edu (8.8.7/8.8.2) id JAA01649 for perry; Mon, 20 Apr 1998 09:23:28 -0400 (EDT)
Date: Mon, 20 Apr 1998 09:23:28 -0400 (EDT)
Message-Id: <199804201323.JAA01649@rigel.ee.vill.edu>
To: perry@vu-vlsi.ee.vill.edu
Subject: Com. Course Final Project
Sender: perry@ece.vill.edu
Content-Length:  1873
Status: O



Hi Rick,

This is for your information.  As a final computer assignment, I've asked
the ECE8770 students to do some Max. Likelihood sequence estimation (MLSE). 
They have write a "brute force" MLSE program, and for the second set of
data below they have to draw the 1-st five stages of the trellis for the 
Viterbi algorithm, and put branch and path costs in.  (I backed off of 
having them write a Viterbi program after you stated your thoughts on what 
it would take the students to do it - thanks!)    

I'll see you tomorrow.

Kevin

________________________________________________________________________
fvect = [0.407 0.815 0.407]; % impulse resp. coefficients of ISI channel
K=15;                        % number of data pts.
SNR=0. dB;                   % SNR - considered very low (AWGN)
cp6                          % program function

% Input to the channel
Iin =      1  1  1  1  -1  1  1  1  1  1  -1  -1  1  -1  1

% Output from the channel
vin = 0.6260  1.2690  2.3079  2.3083  1.7497  0.3825  1.3344  2.4600  1.6636  
       1.6825  1.3447  -0.1439  -0.8073  0.3844  0.0658

% Minimum MLSE cost
emin = 3.8401

% MLSE Estimate
Ivalmin =  1  1  1  1  -1  1  1  1  1  1  -1  -1  1  -1  1

____________________________________________________________________________
fvect = [0.407 0.815 0.407]; % impulse resp. coefficients of ISI channel
K=15;                        % number of data pts.
SNR= infty;                  % SNR - considered very low (AWGN)
cp6                          % program function

% Input to the channel
Iin =      1  1  1  1  -1  1  1  1  1  1  -1  -1  1  -1  1

% Output from the channel
vin = 0.4070  1.2220  1.6290  1.6290  0.8150  -0.0010  0.8150  1.6290  1.6290
        1.6290  0.8150  -0.8150  -0.8150  0.0010  -0.0010

% Minimum MLSE cost
emin = 0

% MLSE Estimate
Ivalmin =  1  1  1  1  -1  1  1  1  1  1  -1  -1  1  -1  1

*/

