jeudi 25 octobre 2018

BER of QPSK for AWGN channel in MATLAB

I want to simulate the BER of QPSK for AWGN channel. Get the BER and compare it with the theoretical one but i am stuck with some parts of the code. Can you please help me with the code?

//////////////////////QPSK BER//////////////////////////
%Initial Condition
Ndata = 10000;
SNRdB = 6;

% Data generation
dataSeq = MYrandData(Ndata);

% QPSK modulation
spcOutput = reshape(dataSeq,2,Ndata/2); %reshape 2 row 5000 column
qpskSymbolIndex = [1,2]*spcOutput; % get random data from 0~3. 
qpskSymbol = ones(1,Ndata/2) * exp(j*pi/4); %0~3, 1 row 5000 column
qpskSymbol(find(qpskSymbolIndex==1)) =____; %<- try to put qpskSymbol = ones(1,Ndata/2) * exp(j*3*pi/4) but false
qpskSymbol(find(qpskSymbolIndex==3)) =____; %<- try to put qpskSymbol = ones(1,Ndata/2) * exp(j*5*pi/4) but false
qpskSymbol(find(qpskSymbolIndex==2)) =____; %<- try to put qpskSymbol = ones(1,Ndata/2) * exp(j*7*pi/4) but false

% AWGN channel
Pn = 10^(-SNRdB/10);
r = qpskSymbol + MYcompNoise([1,___],Pn); % noise of AWGN

% Demodulation
demodData = zeros(2,Ndata/2);
demodData(2,find(imag(r)<=0)) = 1;
demodData(1,find(real(r)<=0)) = 1;
qpskDemod = demodData(:);

%BER calculation
BER = sum(abs(dataSeq - qpskDemod))/Ndata;

SNR = 10^(SNRdB/10);
BER_theory = qfunc(___);

disp(['QPSKsBER=',num2str(BER),'   QPSKs BERs theory=',num2str(BER_theory)])

/////////////////My Random Data////////////////////////////
function[data] = MYrandData(Ndata)

dataSeq = randn(Ndata,1); % generate data
data = zeros(Ndata,1); 
data(find(dataSeq>0)) = 1;
return

//////////////////MyRandomNoise/////////////////
function[noise] = MYcompnoise(noiseSize,Pn) %generate noise
noise = (randn(noiseSize) + j * randn(noiseSize)) * sqrt(Pn/2);
return




Aucun commentaire:

Enregistrer un commentaire