function [Br] = frameLink_8PSK(Bt, Es, Rs, fD, EbN)
% Simulate one frame 8PSK link.
% Br: 1 x n vector: Received bit stream after compensation & demodulation.
% Bt: 1 x n vector: Bit stream to be transmitted.
%   Precondition: Length of Bt corresponds to exactly one frame.
% Es: Energy per symbol (no dimension)
% Rs: Desired symbol rate, baud
% fD: Max Doppler frequency, Hz
% EbN: Bit energy per noise, dB
%
% D.Bozarth 03-31-07 SSU Engineering Science 
% mod 04-19-07: Corrected na (noise amplitude).
% mod 03-24-07: Changed names of 2 called functions.
%
bsz = size(Bt, 2);  % length of binary sequence
ssz = bsz / 3;      % length of symbol sequence
Ts = 1 / Rs;         % symbol period, s

% Convert to complex baseband.
C = eightPSK_mod(Bt, Es);

% Transmit with flat Rayleigh fading.
N = ssz;
h = Rayleigh(N, fD, Ts);
Y = C .* h(2, :);

% Add noise and form the received signal.
na = sqrt( Es / (3 * 2 * 10 ^ (EbN / 10)) ); % noise amplitude
n = zeros(1, ssz);
for k = 1:ssz; a = randn(1, 1); b = randn(1, 1); n(k) = na * (a + i*b); end
r = Y + n;

% Receiver fading compensation.
rc = r ./ h(2, :);

% Demodulation -> binary sequence at receiver.
Br = eightPSK_demod(rc, Es);
%
% End function