% Plot BER versus Eb/No in dB for Hamming(7,4) and 3 times repetition code
%
% Rich Kozick, October 2001

% Hamming code parameters:
k = 4;    % Number of message bits per block
n = 7;    % Number of codeword bits per block

pfine = logspace(-4, 0, 200);
zi = find(pfine <= 0.5);
pfine = pfine(zi);
PeU = 1 - (1-pfine).^7 - 7*(pfine).*(1-pfine).^6;
PeL = PeU/k;

PeRep3 = pfine.^3 + 3*(pfine.^2).*(1-pfine);

figure(1)
loglog(pfine, PeU, 'r-', pfine, PeL, 'b-', ...
pfine, pfine, 'k-', pfine, PeRep3, 'c--')
legend('HAMMING (7,4) U.B.', 'HAMMING (7,4) L.B.', 'UNCODED', ...
'3 \times REPETITION CODE')
xlabel('ERROR PROBABILITY FOR BSC (p)')
ylabel('BER')
title('BER VERSUS p FOR BSC')
axis([1e-4 0.5 1e-7 1])

% Now make the same plot versus Eb/N0 for BPSK signals

