% FIX_CHANNAL finds the probability of bit error for the given value of
% snr_in_dB, when the signal passes through the fixed satellite channel.
% zhang xiaojuan 2010-1-22
N=100000; % symbol number
% the signal mapping
s0=1;
s1=-1;
% generation of the data source
s=round(rand(1,N))*2-1; % BPSK symbol sequence
% effects of weather conditions
em=0.662; % signal envelope mean
esigma=0.02; % signal envelope variance
pm=-0.0089; % signal phase mean
psigma=0.03077; % signal phase variance
evpe=gngauss(em,sqrt(esigma)); % signal envelope
fai=gngauss(pm,sqrt(psigma));
efai=exp(sqrt(-1)*fai); % signal phase
ch_mul=evpe*efai; % multiplicative factor
ss=ch_mul*s; % multiplicative fading
SNRindB1=0:2:20;
E=1; % energy per symbol
for j=1:length(SNRindB1)
snr=10^(SNRindB1(j)/10); % signal-to-noise ratio
sigma=sqrt(E/snr/2); % noise variance
for i=1:N
n(i)=gngauss(sigma);
end
r=ss+n; % additional noise
% detection and the probability of error calculation
numofbiterror=0;
for i=1:N
% The correlation metrics are computed below.
c0=dot(real(r(i)),s0);
c1=dot(real(r(i)),s1);
% The decision on the ith symbol is made next.
c_max=max([c0 c1]);
if (c0==c_max),
decis=1;
else
decis=-1;
end;
% Increment the error counter, if the decision is not correct.
if (decis~=s(i)),
numofbiterror=numofbiterror+1;
end;
end;
pb=numofbiterror/N; % since there are totally N symbols
smld_err(j)=pb;
end
%for i=1:length(SNRindB1),
%SNR=10^(SNRindB1(i)/10); % signal-to-noise ratio
%theo_err(i)=qfunct(sqrt(2*SNR)); % theoretical bit-error rate
%end;
% Plotting commands follow
%semilogy(SNRindB1,theo_err,'-r');
%hold on
semilogy(SNRindB1,smld_err,'-ch');
hold on
ylim([10^-5 1])