Hi Ala.
I just came across your question. Just answering, so that people in the future can get help from.
Here is a MATLAB code to model a Rayleigh channel.
% Final code
% Simulation of Rayleigh channel
clc;
clear all;
close all;
warning off;
% Parameters
nobpc = 10^6;
Es = 1;
SNRdb = 0:20;
M = 4;
Rm = log2(M);
% Transmitting data generation
Tx_bits = round(rand(1,nobpc));
oddData = Tx_bits(1:2:end);
evenData = Tx_bits(2:2:end);
Tx_symb = sqrt(1/2)*(1i*(2*oddData-1)+(2*evenData-1)); %QPSK Mapping
figure, polar(angle(Tx_symb),abs(Tx_symb),'*');
BER = zeros(1,length(SNRdb));
index = 1;
for i =SNRdb
SNR = 10.^(i/10);
noiseSigma = sqrt(1./(2*Rm*SNR));
errors = 0;
%Creating a complex noise for adding with QPSK modulated signal
noise = noiseSigma*(randn(1,length(Tx_symb))+1i*randn(1,length(Tx_symb)));
% Creating a Rayleigh channel with variance 0.5
h = sqrt(0.5*((randn(1,length(Tx_symb))).^2+(randn(1,length(Tx_symb))).^2));
% Transmitted signal
Rx_symb = Tx_symb.*h + noise;
% Equalizer
Rx_symb = Rx_symb./h;
%ML Detector
detected_real = real(Rx_symb)>=0;
detected_img = imag(Rx_symb)>=0;
Rx_bits=reshape([detected_img;detected_real],1,nobpc);
%Bit Error rate Calculation
BER(index) = sum(xor(Tx_bits,Rx_bits))/nobpc;
index=index+1;
end
% Theoretical BER for Rayleigh channel
SNR1 = 10.^(SNRdb/10);
theoreticalBER =0.5*(1 - sqrt(SNR1./(SNR1+1)));
figure,semilogy(SNRdb,BER,'r--'),title('SNR vs BER for Rayleigh channel');
grid on;
hold on;
semilogy(SNRdb,theoreticalBER,'b*');
xlabel("SNRdb");
ylabel("BER");
legend('Simulated','Theoretical-QPSK');
grid on;
figure, semilogy(SNRdb,theoreticalBER,'b'), title("Theoretical curve of SNR Vs BER for Rayleigh Channel"), xlabel("SNRdb"),ylabel("BER");