% generate FIR_0 and channel coefficients

  G = [];

  FIR_save = zeros(FIR_length,N);

  count = 0;

  while( 1)

    count = count + 1;

    FIR_0 = avg_h/(1-alpha) + inv_T * ((stdev_h/sqrt(1-alpha2)) * randn(FIR_length,1));

    FIR_save(:,1) = alpha*FIR_0 + avg_h + inv_T * (stdev_h * randn(FIR_length,1));

    for i=2:N
      FIR_save(:,i) = alpha*FIR_save(:,i-1) + avg_h + inv_T * (stdev_h * randn(FIR_length,1));
    end
  
    hnorm2 = sum(FIR_save .* FIR_save);

    if( min(hnorm2) > 0.10 * max(hnorm2)) % found good coefficients
      break;
    end

  end

% generate symbols and noise

  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

  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

 
