%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Creative Commons
% Attribution-Noncommercial 2.5 India
% You are free:
% to Share — to copy, distribute and transmit the work
% to Remix — to adapt the work
% Under the following conditions:
% Attribution. You must attribute the work in the manner 
% specified by the author or licensor (but not in any way 
% that suggests that they endorse you or your use of the work). 
% Noncommercial. You may not use this work for commercial purposes. 
% For any reuse or distribution, you must make clear to others the 
% license terms of this work. The best way to do this is with a 
% link to this web page.
% Any of the above conditions can be waived if you get permission 
% from the copyright holder.
% Nothing in this license impairs or restricts the author's moral rights.
% http://creativecommons.org/licenses/by-nc/2.5/in/

% Script for simulating binary phase shift keyed transmission and
% reception and compare the simulated and theoretical bit error
% probability
% Checked for proper operation with Octave Version 3.0.0
% Author	: Krishna
% Email		: krishna@dsplog.com
% Version	: 1.0
% Date		: 5 August 2007
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


clear
Eb_N0_dB = [-0:0.5:5]; % multiple Eb/N0 values


theoryBer = 0.5*erfc(sqrt(10.^(Eb_N0_dB/10))); % theoretical ber

% measurements entered as Eb/No (dB), BER
k7r12Ber = zeros(2,10);
k7r12Ber(:,1) = [0,0.186];
k7r12Ber(:,2) = [0.5,0.11];
k7r12Ber(:,3) = [1,5.5E-2];
k7r12Ber(:,4) = [1.5,2.4E-2];
k7r12Ber(:,5) = [2,9E-3];
k7r12Ber(:,6) = [2.5,2.7E-3];
k7r12Ber(:,7) = [3,7.5E-4];
k7r12Ber(:,8) = [3.5,1.40E-4];
k7r12Ber(:,9) = [4,1.9E-5];
k7r12Ber(:,10) = [4.5,2.5E-6];

k9r12Ber = zeros(2,9);
k9r12Ber(:,1) = [0,0.22];
k9r12Ber(:,2) = [0.5,0.121];
k9r12Ber(:,3) = [1,5.0E-2];
k9r12Ber(:,4) = [1.5,1.86E-2];
k9r12Ber(:,5) = [2,4.1E-3];
k9r12Ber(:,6) = [2.5,9.81E-4];
k9r12Ber(:,7) = [3,2E-4];
k9r12Ber(:,8) = [3.5,2.3E-5];
k9r12Ber(:,9) = [4,2.3E-6];

% plot
close all
figure
semilogy(Eb_N0_dB,theoryBer,'b-');
hold on;
semilogy(k7r12Ber(1,:),k7r12Ber(2,:),'r-');
semilogy(k9r12Ber(1,:),k9r12Ber(2,:),'m-');

axis([0 5 10^-5 0.5])
grid on
legend('uncoded', 'K=7', 'K=9');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('Bit error rate performance for rate 1/2');


