matlab误码率分析,误码率分析 请大神帮忙解释下程序

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

% QPSK误码率分析

SNRindB1=0:2:10;

SNRindB2=0:0.1:10;

for i=1:length(SNRindB1)

[pb,ps]=cm_sm32(SNRindB1(i));

smld_bit_err_prb(i)=pb;

smld_symbol_err_prb(i)=ps;

end;

for i=1:length(SNRindB2)

SNR=exp(SNRindB2(i)*log(10)/10);

theo_err_prb(i)=Qfunct(sqrt(2*SNR));

end;

title('QPSK误码率分析');

semilogy(SNRindB1,smld_bit_err_prb,'*');

axis([0 10 10e-8 1]);

hold on;

% semilogy(SNRindB1,smld_symbol_err_prb,'o');

semilogy(SNRindB2,theo_err_prb);

legend('仿真比特误码率','理论比特误码率');

hold off;

%定义Qfunct

function[y]=Qfunct(x)

y=(1/2)*erfc(x/sqrt(2));

%定义cm_sm32

function[pb,ps]=cm_sm32(SNRindB)

N=10000;

E=1;

SNR=10^(SNRindB/10);

sgma=sqrt(E/SNR)/2;

s00=[1 0];

s01=[0 1];

s11=[-1 0];

s10=[0 -1];

for i=1:N

temp=rand;

if (temp<0.25)

dsource1(i)=0;

dsource2(i)=0;

elseif (temp<0.5)

dsource1(i)=0;

dsource2(i)=1;

elseif (temp<0.75)

dsource1(i)=1;

dsource2(i)=0;

else

dsource1(i)=1;

dsource2(i)=1;

end;

end;

numofsymbolerror=0;

numofbiterror=0;

for i=1:N

n=sgma*randn(size(s00));

if((dsource1(i)==0)&(dsource2(i)==0))

r=s00+n;

elseif((dsource1(i)==0)&(dsource2(i)==1))

r=s01+n;

elseif((dsource1(i)==1)&(dsource2(i)==0))

r=s10+n;

else

r=s11+n;

end;

c00=dot(r,s00);

c01=dot(r,s01);

c10=dot(r,s10);

c11=dot(r,s11);

c_max=max([c00 c01 c10 c11]);

if (c00==c_max)

decis1=0;decis2=0;

elseif(c01==c_max)

decis1=0;decis2=1;

elseif(c10==c_max)

decis1=1;decis2=0;

else

decis1=1;decis2=1;

end;

symbolerror=0;

if(decis1~=dsource1(i))

numofbiterror=numofbiterror+1;

symbolerror=1;

end;

if(decis2~=dsource2(i))

numofbiterror=numofbiterror+1;

symbolerror=1;

end;

if(symbolerror==1)

numofsymbolerror=numofsymbolerror+1;

end;

end;

ps=numofsymbolerror/N;

pb=numofbiterror/(2*N);

你可能感兴趣的:(matlab误码率分析)