QPSK Modulation and Demodulation In Rayleigh Fading
MATLAB PROGRAM
clear; clc;
%---------Input Fields------------------------
N=1000000;%Number of input bits
EbN0dB = 0:1:35; % Eb/N0 range in dB for simulation
%---------------------------------------------
data=randn(1,N)>=0; %Generating a uniformly distributed random 1s and 0s
oddData = data(1:2:end);
evenData = data(2:2:end);
qpskModulated = sqrt(1/2)*(1i*(2*oddData-1)+(2*evenData-1)); %QPSK Mapping
M=4; %Number of Constellation points M=2^k for QPSK k=2
Rm=log2(M); %Rm=log2(M) for QPSK M=4
BER = zeros(1,length(EbN0dB)); %Place holder for BER values for each Eb/N0
index=1;
for i=EbN0dB,
%-------------------------------------------
%Channel Noise for various Eb/N0
%-------------------------------------------
%Adding noise with variance according to the required Eb/N0
EbN0 = 10.^(i/10); %Converting Eb/N0 dB value to linear scale
%Creating a complex noise for adding with QPSK modulated signal
noise = 1/sqrt(2*Rm)*(randn(1,length(qpskModulated))+1i*randn(1,length(qpskModulated)));
n = noise*10^(-EbN0dB(index)/20); %Scaling the noise for required Eb/N0
%Rayleigh Flat Fading factor- single tap
h=1/sqrt(2)*(randn(1,length(qpskModulated))+1i*randn(1,length(qpskModulated)));
received = h.*qpskModulated + n;
%-------------------------------------------
%Coherent Receiver for Rayleigh Channel
received_cap=received./h; %Assuming that h is known at the signal accurately
%Threshold Detector
detected_real = real(received_cap)>=0;
detected_img = imag(received_cap)>=0;
estimatedBits=reshape([detected_img;detected_real],1,[]);
%------------------------------------------
%Bit Error rate Calculation
BER(index) = sum(xor(data,estimatedBits))/length(data);
index=index+1;
end
%Plot
figure;
semilogy(EbN0dB,BER,'r--');
hold on;
EbN0=10.^(EbN0dB/10); %Eb/N0 in Linear Scale
theoreticalBER = 0.5*(1-sqrt(EbN0./(1+EbN0)));
semilogy(EbN0dB,theoreticalBER,'b*');
title('SNR per bit (Eb/N0) Vs BER Curve for QPSK Modulation Scheme');
xlabel('SNR per bit (Eb/N0) in dB');
ylabel('Bit Error Rate (BER)');
legend('Simulated','Theoretical-QPSK','Theoretical-QPSK');
grid on;
SIMULATED OUTPUT
DOWNLOAD LINK