主程序:SNRindB1=0:1:12
SNRindB2=0:0.01:12;
for i=1:length(SNRindB1)
smld_err_prb(i)=exa038_Fun_doublePe(SNRindB1(i));
end
semilogy(SNRindB1,smld_err_prb,'r*');
for i=1:length(SNRindB2)
SNR=10^(SNRindB2(i)/10);
theo_err_prb(i)=(1/2)*erfc(sqrt(SNR/2));
end
hold on
semilogy(SNRindB2,theo_err_prb);
grid on
子程序:
function [p]=exa038_Fun_doublePe(snr_in_dB)
E=1;
SNR=10^(snr_in_dB/10);
sgma=E/sqrt(SNR);
N=10000;
disource=(sign(rand(1,N)-0.5)+1)/2;
numoferr=0;
for i=1:length(disource)
if disource(i)==1
r=E+randn*sgma;
else
r=-E+randn*sgma;
end
if(r>0)
decis=1;
else
decis=0;
end
if(decis~=disource(i))
numoferr=numoferr+1;
end
end
p=numoferr/N;