%% EQBER_SIGGEN - Generate a noisy, channel-filtered signal to be equalized
% This script generates a noisy, channel-filtered signal to be processed by a
% linear equalizer, a DFE equalizer, and an MLSE equalizer.  The channel state
% information is retained between blocks of signal data.  The script also sets
% the state of the data and noise generators for its first run, then allows the
% states to update automatically.

%   Copyright 1996-2004 The MathWorks, Inc.
%   $Revision: 1.1.12.2 $  $Date: 2004/10/08 20:20:38 $


% Generate a PSK signal
if (firstRun)
    msg = randint(nBits, 1, M, dataState);
else
    msg = randint(nBits, 1, M);
end
txSig = pskmod(msg, M);

% Pass the signal through the channel
[filtSig, chanState] = filter(chnl, 1, txSig, chanState);

% Add AWGN to the signal
SNR = EbNo(EbNoIdx) + 10*log10(Rb/Fs);
if (firstRun)
    noisySig = awgn(filtSig, SNR, 'measured', noiseState);
    firstRun = false;
else
    noisySig = awgn(filtSig, SNR, 'measured');
end