How to generate BER performance for different dB?

82 views Asked by At

I want to create a graph that generates BER vs Eb/N0 for different signal-to-noise ratios. Try to create a for loop but it is not working, can you help me with that? I am quite new to this Matlab and don't know where things are getting wrong.

figure(1)
for j = 1:length(SIR)
    for i = 1:10
        BER     = []; 
        BER_az  = [];
        Pj      = 2*Lc / (10^(SIR(j)/10));
        jammer  = sqrt(Pj/2)*jam_mod.*exp(1i*2*pi*0.12*(1:Ldata*Lc)).';
        [P,x]   = pwelch(jammer+x_in,[],[],[4096], Lc,'twoside');
        %clear jam_mod;
        EB2N(i)  = (i-1);
        EB2N_num = 10^(EB2N(i)/10);
        Var_n    = Lc/(2*EB2N_num); %variance
        signois  = sqrt(Var_n);     %standard deviation
        awgnois  = signois*noise;
        y_out    = x_in+awgnois+jammer;
        Y_out = reshape(y_out,Lc,Ldata).';
        clear y_out awgnois;
        z_out = Y_out*Pcode;
  
  %decision based on the sign of the samPles
        dec1 = sign(real(z_out))+j*sign(imag(z_out));
  
  %comPare against the original data to calcuate BER
        BER       = [BER;sum([real(data_sym)~=real(dec1);...
              imag(data_sym)~=imag(dec1)])/(2*Ldata)];
        BER_az    = [BER_az;0.5*erfc(sqrt(EB2N_num))];
    end
    
   if (j == 1)
        figber = semilogy(EB2N,BER_az, 'k-'); 
        hold on;
    end
        figber = semilogy(EB2N,BER);
        clear BER;
        clear BER_az;
        legend('No jamming','SNR:-5 dB', 'SNR:-8 dB', 'SNR:-10 dB', 'SNR:-20 dB');
        set(figber,'Linewidth',2);
        xfont = xlabel('E_b/N in dB');
        yfont = ylabel('bit error rate');
        title('DSSS with sPreading gain 11');

end  
 
1

There are 1 answers

1
m2016b On

You must first initialize your SIR variable just before the start of the loop. Also specify the SIR value before the for loop.

SIR = [0:1:10];  % For example for a SIR from 0 to 10 in steps of 1.

In the program, specify the following values : Lc, Jam_mod, Ldata, X_in, noise and data_sym.

This post will give you other openings as well.