A.
number_Frame=200; N_bits=400; Max_SNR=10; step=2; errs=zeros(1, fix(Max_SNR/step)+1); %___________________________________________________ for nframe=1:number_Frame nframe s_bits = round(rand(1, N_bits)); % info. bits Eav=1; d=sqrt(Eav./10); sig=qam16mapping(s_bits,d); A_WGN=randn(1,N_bits/4)+j.*randn(1,N_bits/4); %___________________________________________ nEN=0; for EbN0db= 0:step:Max_SNR snr=10.^(EbN0db/10); nEN=nEN+1; Eb_av=Eav/4; sigma =sqrt(Eb_av /(2*snr)); r = sig+sigma*A_WGN; de_bits=(hard_demap(r,d)+1)./2; err(1,nEN) = length(find(de_bits~=s_bits)); end % EbN0db %__________________________________________________ errs = errs + err; end %nframe ber= errs/number_Frame/N_bits; %________________________________________________________ snr_db=[0:step:Max_SNR]; snr=10.^(snr_db./10); M=16; xqam16=sqrt(3.*log2(M)./(M-1).*snr); SER_T=4.*(1-1./sqrt(M)).*Qfunct(xqam16); BER_T=SER_T./log2(M); %________________________________________________________ i=0:step:Max_SNR; figure semilogy(i,ber,'r-',i,BER_T,':*'); xlabel('E_{b}/N_{0}') ylabel('BER') legend('Monte Claro','Theoretical result'); grid on function sig=qam16mapping(msg, d) N_bit=length(msg); mapping =[ d, d; d, 3*d; 3*d, d; 3*d, 3*d;... d, -d; d, -3*d; 3*d, -d; 3*d, -3*d;... -d, d; -d, 3*d; -3*d, d; -3*d, 3*d;... -d, -d; -d, -3*d; -3*d, -d; -3*d, -3*d]; %matrix 16 X 2 %--------------------------------------------------------------------- %qam modulation dsource=[]; sig=[]; for i=1:4:N_bit temp=[msg(i),msg(i+1),msg(i+2),msg(i+3)]; s_index = int_state( temp ); dsource=[dsource,s_index+1]; end %dsouce element in{1,...,16} N_QAM=length(dsource); %(N_bit/4) for i=1:N_QAM sig1=mapping(dsource(i),1); sig2=mapping(dsource(i),2); sig=[sig,sig1+j.*sig2]; % symbol row vector with N_bit/4 16QAM symbols end function hardbits=hard_demap(r,d) N_symbol=length(r); hardbits=[]; sbits=zeros(1,4); for k=1:N_symbol sk=r(k); sbits(1)=-real(sk); sbits(2)=-imag(sk); sbits(3)=abs(real(sk))-2.*d; sbits(4)=abs(imag(sk))-2.*d; hardbits=[hardbits,sign(sbits)]; end