% To observe the BER performance of a MRC system with two receive antennas
% and spatially independent rayleigh fading channel
clc;
clear all;
format long;
f = sqrt(0.5); % Scaling factor for complex variables
N = 10000; % No. of samples taken for processing
index = 1; % Variable for no. of points on the graph
for k=1:2:20 % Various values of SNR in dB
s = 10^(k/10); % SNR
p = sqrt(1/s); % Noise scaling factor
mu = sqrt(s/(s+1));
bera(index) = 0.25*(2-3*mu+mu^3); % Analytical expression for BER
data = randint(1,N);
x = 2*data-1;
h1 = f*(randn(1,N)+j*randn(1,N)); % Generation of channel coefficient for 1st channel:
% complex normal with mean=0,variance=1
h2 = f*(randn(1,N)+j*randn(1,N)); % Generation of channel coefficient for 1st channel:
% complex normal with mean=0,variance=1
n1 = f*(randn(1,N)+j*randn(1,N)); % Complex AWGN for first instant
n2 = f*(randn(1,N)+j*randn(1,N)); % Complex AWGN for second instant
y1 = h1.*x+p*n1; % Received symbol at first instant
y2 = h2.*x+p*n2; % Received symbol at second instant
error = 0;
d = (conj(h1).*y1)+(conj(h2).*y2); % Detection rule
for kk=1:N
if(real(d(kk))>=0)
data_detect(kk)=1; % Decision
else
data_detect(kk)=0;
end
end
error = xor(data,data_detect);
bers(index) = sum(error)/N; % BER calculation
snr(index) = k;
N = N+2000; % Considering more no. of samples
index = index+1;
end
semilogy(snr,bera,snr,bers);
legend('Analytical','Simulation');
xlabel('SNR dB');
ylabel('BER');