samedi 21 juillet 2018

Calculating Error Rates for QPSK(for AWGN channel) in MATLAB

I want to simulate the QPSK for AWGN Channel and compare the errors I get with the theoritical ones on a plot. I want to do this on MATLAB for different SNR values from 1 to 10. When I plot this I get a huge difference between simulated and theoritical errors. I suspect I might have done with the demodulation part. I used atan function there but I am not %100 sure that it works. Can you help me?

M=100000;
snrdB=1:10;
snr=10.^(snrdB/10);
sError = zeros(1,10);%simulated error
tError = zeros(1,10);%theoritical error
for i=1:10
    symbols = randi([1,4],1,M);
    symbols(symbols == 1) = 1;
    symbols(symbols == 2) = 1i;
    symbols(symbols == 3) = -1;
    symbols(symbols == 4) = -1i;

    %calculating total energy
    Eb = 0;
    for k=1:M
        Eb = Eb + abs(symbols(k).^2);
    end
    Eb = Eb/2;

    var = abs(sqrt(Eb/(2*snr(i))));%variance
    noise = var*rand(1,M) + var*1i*rand(1,M);%noise

    r=symbols+noise;%adding noise

    symbols1 = atan(r);%demodulation

    error = abs((symbols - symbols1)./abs(symbols));%error
    sError(i) = mean(error);
    tError(i) = 2*qfunc(sqrt(2*snr(i)));%theoritical error
end
%comparison
semilogy(snrdB, tError,'x-')  
hold on
semilogy(snrdB, sError,'o-')                                 
xlabel('snr(dB)')                                    
ylabel('error')                                         
grid on 




Aucun commentaire:

Enregistrer un commentaire