from BER of BPSK DS-SS System by Sanjeet Kumar
This shows the BER performance of BPSK DS-SS system in AWGN as well as fading channel.

fading_per.m
function[prob]=fading_per(snr,T)
s=10^(snr/10);
ec=(2/T)*s;
n=10000;
num=0;
for i=1:n
    t=round(rand(1,1));
    if t==0;
        d=-ones(1,T);
    else
        d=ones(1,T);
    end

    redata=[d];
    
    pn=randsrc(1,T);
     
   trs=sqrt(ec)*redata.*pn;
   
   trs=rand*trs+randn(size(pn));
   de=trs.*pn;
   dc=sum(de);
   if(dc<0)
       deci=-1;
   else
       deci=1;
   end
   if(deci~=d)
       num=num+1;
   end
end
   prob=num/n;

Contact us at files@mathworks.com