【正文】
dsource2(i)=1。 end。 end。 % detection and the probability of error calculation numofsymbolerror=0。 numofbiterror=0。 for i=1:N, % The received signal at the detector, for the ith symbol, is: n(1)=gngauss(sgma)。 n(2)=gngauss(sgma)。 if ((dsource1(i)==0) amp。 (dsource2(i)==0)), r=s00+n。 elseif ((dsource1(i)==0) amp。 (dsource2(i)==1)), r=s01+n。 elseif ((dsource1(i)==1) amp。 (dsource2(i)==0)), r=s10+n。 else r=s11+n。 end。 rr=r(1)+j*r(2)。 13 if (angle(rr)(3*pi/4)amp。angle(rr)=pi), decis1=1。 decis2=1。 elseif (angle(rr)(pi)amp。angle(rr)=(3*pi/4)), decis1=1。 decis2=1。 elseif (angle(rr)(pi/4)amp。angle(rr)=(3*pi/4)), decis1=0。 decis2=1。 elseif (angle(rr)(pi/4)amp。angle(rr)=(pi/4)), decis1=0。 decis2=0。 elseif(angle(rr)(3*pi/4)amp。angle(rr)=(pi/4)) decis1=1。 decis2=0。 end。 % Increment the error counter, if the decision is not correct. 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。 % since there are totally N symbols pb=numofbiterror/(2*N)。 % since 2N bits are transmitted function [gsrv1,gsrv2]=gngauss(m,sgma) % [gsrv1,gsrv2]=gngauss(m,sgma) % [gsrv1,gsrv2]=gngauss(sgma) % [gsrv1,gsrv2]=gngauss % GNGAUSS generates two independent Gaussian random variables with mean % m and standard deviation sgma. If one of the input arguments is missing % it takes the mean as 0, and the standard deviation as the given parameter. % If neither mean nor the variance is given, it generates two standard % Gaussian random variables. 14 if nargin == 0, m=0。 sgma=1。 elseif nargin == 1, sgma=m。 m=0。 end。 u=rand。 % a uniform random variable in (0,1) z=sgma*(sqrt(2*log(1/(1u))))。 % a Rayleigh distributed random variable u=rand。 % another uniform random variable in (0,1) gsrv1=m+z*cos(2*pi*u)。 gsrv2=m+z*sin(2*pi*u)。 function [y]=Qfunct(x) % [y]=Qfunct(x) % QFUNCT evaluates the Qfunction. % y = 1/sqrt(2*pi) * integral from x to inf of exp(t^2/2) dt. % y = (1/2) * erfc(x/sqrt(2)). y=(1/2)*erfc(x/sqrt(2))。