% x4 - data setup for data values (-1,1) and time-varying Gauss/Gauss-Markov FIR
% 

if( K == 1)

  G = [];

% SNR would be time-varying with fixed var_noise.
% To get constant SNR, var_noise must be time varying...

% set FIR_save, SNR, var_noise, N, etc. before calling x4

  LOADED = 4;

  Memory = FIR_length - 1;     % channel memory size

  states = FSM( [-1 1], Memory);

  MM_max = size(states,2);      % number of symbol values

  M = MM_max;			% number of states

  zstate_0 = 0;			% NOT initial 0's in the channel

  zstate = 1;			% initial state

  x = 2*(rand(1,N) > 0.5) - 1;	% input sequence

  xt = [fliplr(states(:,zstate)'), x];

  y = zeros(1,N);

  for i=1:N
    y(i) = xt(i+Memory:-1:i) * FIR_save(:,i);
  end

% for fixed var_noise and varying SNR
%
%  noise = sqrt(var_noise)*randn(1,N);	% random noise
%
% for fixed SNR and varying var_noise
%
%  var_noise = 10^(-SNR/10) * sum(FIR_save.*FIR_save);   % noise variance
%
%  noise = sqrt(var_noise).*randn(1,N);  % random noise
%
% for fixed SNR and fixed average noise.
%
  var_noise = 10^(-SNR/10) * sum( sum(FIR_save.*FIR_save)) / N;

  noise = sqrt(var_noise).*randn(1,N);  % random noise


  z = y + noise;			% signal plus noise

else	% K > 1

  error( 'sorry... isi stuff only works with K=1');

  if( LOADED ~= 4)
    error( 'initialize with K = 1 first');
  end

end
