
WHY IS MY BER CURVE NOT RIGHT? (QPSK)
    7 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
folks!!
I have a problem. This is my code but I don't know where I can be wrong. my BER curve is not correct nor does it look like the theoretical curve.
Can someone help me?
follow the code:
clear all; 
close all; 
clc;
% Número de bits
N=10000;        
% Número máximo de iterações para um único SNR
max_run=20;              
% Bit de energia
Eb=1;  
% Relação Sinal-Ruído (em dB)
SNRdB=0:1:9;                             
SNR=10.^(SNRdB/10);       
% Cria caixa de diálogo da barra de espera
hand=waitbar(0,'Please Wait....');
% Início do loop para SNR diferente
 for count=1:length(SNR)                  
     % erro médio
     avgError=0;
     % Calcule a potência de ruído do SNR
     No=Eb/SNR(count);                    
     % Início do loop para diferentes execuções
     for run_time=1:max_run          
         waitbar((((count-1)*max_run)+run_time-1)/(length(SNRdB)*max_run));
         % erro inicial
         Error=0;
         % 1 ou -1 para sinal em fase
         x_inp_I=sign(rand(1,N)- 0.5);
         % 1 ou -1 para sinal de quadratura
         x_inp_Q=sign(rand(1,N)- 0.5); 
         % Gera bits de marca d'água aleatórios
         Bit_wat = randi([0 1],1,N);
         % Ângulo da marca d'água
         Theta = pi/12;
         % loop para identificar bit com a marca d'água
         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)]; 
         % Adicionando sinal ruído ao bit enviado
         Y= Bit_enviado + noise;                           
         y_re = real(Y);    % real
         y_im = imag(Y);    % imaginary
        % Dispositivo de decisão tomando decisões difíceis e erro de decodificação
        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
         % Calcular erro/bit
         Error=Error/N;                   
         % Calcular erro / bit para diferentes execuções
         avgError=avgError+Error;    
     % Término do loop para diferentes execuções
     end                                  
     % Calcule BER para um SNR particular 
     BER_sim(count)=avgError/max_run;       
 % Término do loop para SNR diferente    
 end                                      
% Calcular BER analítico
BER_th=(1/2)*erfc(sqrt(SNR));            
close(hand);
%Plot BER
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
0 Commenti
Risposte (1)
  Shashi Kiran
 il 19 Set 2024
        I see you are having trouble getting the simulation and theoretical curves to match. 
After checking the code, I noticed issues with how noise and error rates are calculated. Here's a simpler way to fix it:  
% Correct noise scaling
noise = sqrt(No/2) * (randn(1, N) + 1i * randn(1, N));
% Add noise to the transmitted signal
Y = Bit_enviado + noise;                           
% Decision device and error counting
for m = 1:N
    % Decision based on real part for BPSK
    if sign(real(Bit_enviado(m))) ~= sign(real(Y(m)))
        Error = Error + 1;
    end
end
These changes should help your simulation match the theoretical graph as shown. 

Hope this helps.
0 Commenti
Vedere anche
Categorie
				Scopri di più su PHY Components in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

