matlab程序仿真,matlab仿真程序

附录一AWGN信道下的BPSK系统仿真的MATLAB程序main.m

echo on

SNRindB1=0:1:10;

for i=1:length(SNRindB1)

%simulated error rate

smld_err_prb(i)=smldPe_awgn(SNRindB1(i));

echo off;

end;

%Plotting commands follow

semilogy(SNRindB1,smld_err_prb,'*');

smldPe_awgn.m

function[p]=smldPe_awgn(snr_in_dB)

E=1;

SNR=exp(snr_in_dB*log(10)/10);%signal to noise ratio sgma=E/sqrt(2*SNR);%sigma,standard deviation of noise N=2^14;

%generation of the binary data source

for i=1:N

temp=rand;

if(temp<0.5)

dsource(i)=0;

else

dsource(i)=1;

end

end;

%detection,and probability of error calculation numoferr=0;

for i=1:N

%matched filter outputs

if(dsource(i)==0)

r=-E+gngauss(sgma);%if the source output is"0"

else

r=E+gngauss(sgma);%if the source output is"1"

end;

%detector follows

if(r<0)

decis=0;

else

decis=1;

end;

if(decis~=dsource(i))

numoferr=numoferr+1;

end;

end;

p=numoferr/N;%probability of error estimate gngauss.m

function[gsrv1,gsrv2]=gngauss(m,sgma)

if nargin==0

m=0;

sgma=1;

elseif nargin==1

sgma=m;

你可能感兴趣的:(matlab程序仿真)