clear all;
close all;
clc;
N=10000;
max_run=20;
Eb=1;
SNRdB=0:1:9;
SNR=10.^(SNRdB/10);
hand=waitbar(0,'Please Wait....');
for count=1:length(SNR)
avgError=0;
No=Eb/SNR(count);
for run_time=1:max_run
waitbar((((count-1)*max_run)+run_time-1)/(length(SNRdB)*max_run));
Error=0;
x_inp_I=sign(rand(1,N)- 0.5);
x_inp_Q=sign(rand(1,N)- 0.5);
Bit_wat = randi([0 1],1,N);
Theta = pi/12;
for k = 1:N
if Bit_wat(k)==1
Bit_enviado(k) = x_inp_I(k)*(cos(Theta)+sin(Theta))+ 1i*x_inp_Q(k)*(cos(Theta)-sin(Theta));
else
Bit_enviado(k) = x_inp_I(k)*(cos(Theta)-sin(Theta))+ 1i*x_inp_Q(k)*(cos(Theta)+sin(Theta));
end
end
noise=1/sqrt(2)*[randn(1,N) + 1i*randn(1,N)];
Y= Bit_enviado + noise;
y_re = real(Y);
y_im = imag(Y);
for m=1:N
if sign(real(Bit_enviado(m)))==sign(real(Y(m))) && sign(imag(Bit_enviado(m)))==sign(imag(Y(m)))
Error = Error + 0;
elseif sign(real(Bit_enviado(m)))~=sign(real(Y(m))) && sign(imag(Bit_enviado(m)))~=sign(imag(Y(m)))
Error= Error + 1;
elseif sign(real(Bit_enviado(m)))~=sign(real(Y(m))) && sign(imag(Bit_enviado(m)))==sign(imag(Y(m)))
Error= Error + 1;
else
Error= Error + 2;
end
end
Error=Error/N;
avgError=avgError+Error;
end
BER_sim(count)=avgError/max_run;
end
BER_th=(1/2)*erfc(sqrt(SNR));
close(hand);
semilogy(SNRdB,BER_th,'b.-');
hold on
semilogy(SNRdB,BER_sim,'mx-');
hold on
legend('Teórica','Simulada');
axis([min(SNRdB) max(SNRdB) 10^(-5) 1]);
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('Curva De Probabilidade De Erro De Bit Para Modulação BPSK ');
hold on
grid on