1

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 
user6210457
  • 397
  • 1
  • 7
  • 22

3 Answers3

1

Something like this should work;

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;

    var = 1/(2*sqrt(snr(i)));%variance

    noise = var*(randn(1,M)) + var*j*(randn(1,M));

    r=symbols+noise;%adding noise

    c1 = exp(j*pi/4);
    c2 = exp(-j*pi/4);

    symbols1 = sign(real(symbols .* c1));
    symbols2 = sign(imag(symbols .* c1));

    symbols3 = sign(real(symbols .* c2));
    symbols4 = sign(imag(symbols .* c2));

    symbols1r = sign(real(r .* c1));
    symbols2r = sign(imag(r .* c1));

    symbols3r = sign(real(r .* c2));
    symbols4r = sign(imag(r .* c2));


    ind = find(symbols1==symbols1r & symbols2==symbols2r & symbols3==symbols3r & symbols4==symbols4r);

    sError(i) = (M-length(ind))/M;
    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
0

I also think something is wrong with demodulation. You shouldn't use atan here. I suggest you should work on real and imaginary parts seperately. Delete the line with atan and replace with these lines:

resymbols = real(r);
imsymbols = imag(r);
symbols1 = resymbols + 1i*imsymbols;
harold_finch
  • 80
  • 3
  • 11
0

Please keep in mind, that it is rather uncommon to use the following constellation for QPSK {1, -1, 1j, -1j}

Usually you use: {1+1j, 1-1j, -1+1j, -1-1j}