% example script to run a known-channel multi-user ISI problem
%
% call x2_init and define SNR first
%
% R. Perry, June 2001

% generate each user's sequence
%
x = zeros( N, Nusers);
for u = 1:Nusers
  x(:,u) = 2*(rand(N,1) > 0.5) - 1;
end

% apply the FIR filters
%
y = zeros( N, Nusers);
for from = 1:Nusers
  xt = [flipud(states(1:Memory,1)); x(:,from)]; % initial -1's in the channels
  for to = 1:Nusers
    for t = 1:N
      y(t,to) = y(t,to) + xt(t+Memory:-1:t)' * FIR_save(:,t,from,to);
    end
  end
end

% SNR = 20; % set SNR before calling this routine

% constant noise variance for now
% maybe need different noise variances for each channel path?
%
var_noise = 10^(-SNR/10);

noise = sqrt(var_noise).*randn( N, Nusers);

z = y + noise; % signal plus noise
%
%%
%%%

format short g;

% initialize rand() and randn() with time-of-day
%
  seed=floor(sum(100*clock))
  rand( 'state', seed);
  randn( 'state', seed);

%%%
%%
% run Viterbi
%
L = 3;
Nv = 1;

vit_init( L, M, N, Nv);

for t=1:N
  vit_update;
end

paths = vit_paths;

ex = zeros( N, L, Nusers);

for u=1:Nusers
  ex(:,:,u) = get_ex_multi( paths, u);
end
