function [X] = EightPSK_mod(B, e)
% Returns a vector of complex numbers representing the complex baseband
% 8PSK symbols derived from a bit stream.
% Arguments:
%   B is a vector of binary digits.
%   e is the energy per symbol.
%
% D.Bozarth, March 2007, SSU Engineering Science
%
table = [3*pi/4 3*pi/2 pi/2 7*pi/4 pi 5*pi/4 pi/4 0];
table = sqrt(e) * exp(i .* table);
n_B = size(B);  % B is a (1 x n) vector.
n_B = n_B(2);   % Second element is the #columns in B.
n_sym = floor(n_B ./ 3);
X = zeros(1, n_sym);
ptr = 0;

for k = 0:(n_sym - 1)
    ptr = k * 3 + 1;
    a3 = B(ptr:(ptr + 2));
    
    ndx = a3(1)*4 + a3(2)*2 + a3(3)*1 + 1;
    X(k + 1) = table(ndx);
end
% end function