function [ aDigitalSignal ] = BPSKMod( aBitStream, A, f, fs, rate)
% A simple BPSK modulator
% Inputs
%   aBitStream = an array of bits
%   A = max amplitude of carrier (in Volts)
%   f = carrier frequency (in Hz)
%   fs = sampling rate (in sps)
%   rate = data rate (in bps)
% Output
%   aDigitalSignal = modulated digital signal
% determine the number of samples per bit
spb = fs / rate; % samples/bit
% determine sample period
ts = 1 / fs;
% generate corresponding time instants
t = (0:spb-1) * ts;
% initialize the output
aDigitalSignal = [];
for i=1:length(aBitStream)
    % build the BPSK signal bit-by-bit
    aDigitalSignal = [ aDigitalSignal ...
        ( not(aBitStream(i)) + -aBitStream(i) ) * A * ...
        cos(2*pi*f*t) ];
end
end

