You are on page 1of 2

%QPSK with diversity order L = 2,4,8 over a Rayleigh fading channel

clc; clear all; close all;


for L = 2.^[1 2 3]
N = 100000;
x = repmat(2*randi(2,N,1)-3 + 1i*(2*randi(2,N,1)-3),1,L); % Generate a qpsk
signal

h = randn(N,L)/sqrt(2) + 1i*randn(N,L)/sqrt(2);%channel
n = randn(N,L) + 1i*randn(N,L);%noise

SNR_dB = 0.1:1:12;
BER = zeros(1,length(SNR_dB));

for l = 1:length(SNR_dB)
y = h.*x + 10^(-SNR_dB(l)/20)*n;
% MRC equalizer that is W' = conj(h./sqrt(sum( abs(h).^2 , 2)))
y_e = sum(conj(h./repmat(sqrt(sum( abs(h).^2 , 2)),1,L)).*y,2);
r_ye = sign(real(y_e));
i_ye = sign(imag(y_e));
count = length(find(r_ye - real(x(:,1))));
count = count + length(find(i_ye - imag(x(:,1))));
BER(l) = count/(2*N);
end
figure(L);
semilogy(SNR_dB,BER,'Linewidth',3,'Marker','o');grid on;
hold;
lmbda = sqrt(10.^(SNR_dB/10)./(2 + 10.^(SNR_dB/10)));
BER2 = zeros(1,length(SNR_dB));
for r = 0:L-1
BER2 = BER2 + (((1-lmbda)/2).^L).*(nchoosek(L-1+r,r)*((1+lmbda)/2).^r);
end
semilogy(SNR_dB,BER2,'-r*','Linewidth',2);
legend('simulated','theoretical')
end
0
10
simulated
theoretical

-1
10

-2
10

-3
10
0 2 4 6 8 10 12
-1
10
simulated
theoretical

-2
10

-3
10

-4
10

-5
10
0 2 4 6 8 10 12

-2
10
simulated
theoretical

-3
10

-4
10

-5
10

-6
10

-7
10

-8
10
0 2 4 6 8 10 12

You might also like