Binary Phase shift keying
clc;clear all;close all;
% Getting Input binary bits and frequency
g=[1 0 1 1 0 1];
f=10;
t=0:2*pi/99:2*pi;
binary=[];carrier=[];
mult=[];
c=sin(f*t);
% BPSK algorithm
for n=1:length(g)
if g(n)==0
x=zeros(1,100);
y=-ones(1,100);
else g(n)==1
x=ones(1,100);
y=ones(1,100);
end
carrier=[carrier c];
binary=[binary x];
mult=[mult y];
end
bpsk=mult.*carrier;
% Plotting
subplot(2,1,1);plot(binary);grid on;
title('Input Binary Signal');
axis([0 100*length(g) -2.5 2.5]);
subplot(2,1,2);plot(bpsk);grid on;
title('BPSK Modulated Signal');
axis([0 100*length(g) -2.5 2.5]);
% Calculation of BER
N=10^6;
rand('state',100);
randn('state',200);
ip=rand(1,N)>0.5;
s=2*ip-1;
n=1/sqrt(2)*[randn(1,N)+j*randn(1,N)];
Eb_No_db=[-3:10];
for ii=1:length(Eb_No_db)
y=s+10^(-Eb_No_db(ii)/20)*n;
iphat=real(y)>0;
nerr(ii)=size(find([ip-iphat]),2);
end
simber=nerr/N;
theoryber=0.5*erfc(sqrt(10.^(Eb_No_db/10)));
figure
semilogy(Eb_No_db,theoryber,'b.-');
hold on;
semilogy(Eb_No_db,simber,'mx-');
axis([-3 10 10^-5 0.5]);
grid on;
legend('theory','simulation');
xlabel('Eb/No,,db');ylabel('Bit Error Rate');
title('Bit Error Probability for BPSK');
No comments:
Post a Comment