allysonsim
Junior Member level 2
paradata=reshape(seldata,para,nd*ml);
Help!
I need someone's help to guide me on Simulating my BER result on Matlab. This is the codes that I have for the moment. Which i modified a lil bit from the code provided by the book.
clc;
clear all;
close all;
para=128; % Number of parallel channel to transmit (points)
fftlen=128; % FFT length
noc=128; % Number of carrier
nd=6; % Number of information OFDM symbol for one loop
ml=8; % Modulation level : QPSK
sr=250000; % Symbol rate
br=sr.*ml; % Bit rate per carrier
gilen=32; % Length of guard interval (points)
ebno=[0:30]; % Eb/N0
%************************** main loop part **************************
nloop=500; % Number of simulation loops
noe = 0; % Number of error data
nod = 0; % Number of transmitted data
eop=0; % Number of error packet
nop=0; % Number of transmitted packet
for i = 1:length(ebno)
for iii=1:nloop
ebn0=ebno(i);
%************************** transmitter *********************************
%************************** Data generation ****************************
seldata=rand(1,para*nd*ml)>0.5; % rand : built in function
%****************** Serial to parallel conversion ***********************
paradata=reshape(seldata,para,nd*ml); % reshape : built in function
%************************** QPSK modulation *****************************
[ich,qch]=qpskmod(paradata,para,nd,ml);
kmod=1/sqrt(2); % sqrt : built in function
ich1=ich.*kmod;
qch1=qch.*kmod;
%******************* IFFT ************************
x=ich1+qch1.*i;
y=ifft(x); % ifft : built in function
ich2=real; % real : built in function
qch2=imag; % imag : built in function
%********* Gurad interval insertion **********
[ich3,qch3]= giins(ich2,qch2,fftlen,gilen,nd);
fftlen2=fftlen+gilen;
%********* Attenuation Calculation *********
spow=sum(ich3.^2+qch3.^2)/nd./para; % sum : built in function
attn=0.5*spow*sr/br*10.^(-ebn0/10);
attn=sqrt(attn);
%*************************** Receiver *****************************
%***************** AWGN addition *********
[ich4,qch4]=comb(ich3,qch3,attn);
%****************** Guard interval removal *********
[ich5,qch5]= girem(ich4,qch4,fftlen2,gilen,nd);
%****************** FFT ******************
rx=ich5+qch5.*i;
ry=fft(rx); % fft : built in function
ich6=real(ry); % real : built in function
qch6=imag(ry); % imag : built in function
%***************** demoduration *******************
ich7=ich6./kmod;
qch7=qch6./kmod;
[demodata]=qpskdemod(ich7,qch7,para,nd,ml);
%************** Parallel to serial conversion *****************
demodata1=reshape(demodata,1,para*nd*ml);
%************************** Bit Error Rate (BER) ****************************
% instantaneous number of error and data
noe2=sum(abs(demodata1-seldata)); % sum : built in function
nod2=length(seldata); % length : built in function
% cumulative the number of error and data in noe and nod
noe=noe+noe2;
nod=nod+nod2;
end
% theoretical Values for BER
ber=noe2/nod2;
BerAwgn = [0.5*erfc(sqrt(ebn0)) 0.5*(1-(1/(sqrt(1+1/ebn0)))) noe/nod]
for k=1:length(BerAwgn)
Berawgn = BerAwgn(k);
% theoretical value for fading
%********************** Output result ***************************
% per=eop/nop;
fprintf('%f\t%e\t%d\t%d\t\n',ebn0,ber,BerAwgn,noe);
markerchoice = '.xo*';
plotsym = [markerchoice(k),'b-']; % Plotting style for this curve
semilogy(ebn0, Berawgn, plotsym); % Plot one curve.
drawnow; % Update the plot instead of waiting until the end.
hold on; % Make sure next iteration does not remove this curve.
end
end
Help!
I need someone's help to guide me on Simulating my BER result on Matlab. This is the codes that I have for the moment. Which i modified a lil bit from the code provided by the book.
clc;
clear all;
close all;
para=128; % Number of parallel channel to transmit (points)
fftlen=128; % FFT length
noc=128; % Number of carrier
nd=6; % Number of information OFDM symbol for one loop
ml=8; % Modulation level : QPSK
sr=250000; % Symbol rate
br=sr.*ml; % Bit rate per carrier
gilen=32; % Length of guard interval (points)
ebno=[0:30]; % Eb/N0
%************************** main loop part **************************
nloop=500; % Number of simulation loops
noe = 0; % Number of error data
nod = 0; % Number of transmitted data
eop=0; % Number of error packet
nop=0; % Number of transmitted packet
for i = 1:length(ebno)
for iii=1:nloop
ebn0=ebno(i);
%************************** transmitter *********************************
%************************** Data generation ****************************
seldata=rand(1,para*nd*ml)>0.5; % rand : built in function
%****************** Serial to parallel conversion ***********************
paradata=reshape(seldata,para,nd*ml); % reshape : built in function
%************************** QPSK modulation *****************************
[ich,qch]=qpskmod(paradata,para,nd,ml);
kmod=1/sqrt(2); % sqrt : built in function
ich1=ich.*kmod;
qch1=qch.*kmod;
%******************* IFFT ************************
x=ich1+qch1.*i;
y=ifft(x); % ifft : built in function
ich2=real; % real : built in function
qch2=imag; % imag : built in function
%********* Gurad interval insertion **********
[ich3,qch3]= giins(ich2,qch2,fftlen,gilen,nd);
fftlen2=fftlen+gilen;
%********* Attenuation Calculation *********
spow=sum(ich3.^2+qch3.^2)/nd./para; % sum : built in function
attn=0.5*spow*sr/br*10.^(-ebn0/10);
attn=sqrt(attn);
%*************************** Receiver *****************************
%***************** AWGN addition *********
[ich4,qch4]=comb(ich3,qch3,attn);
%****************** Guard interval removal *********
[ich5,qch5]= girem(ich4,qch4,fftlen2,gilen,nd);
%****************** FFT ******************
rx=ich5+qch5.*i;
ry=fft(rx); % fft : built in function
ich6=real(ry); % real : built in function
qch6=imag(ry); % imag : built in function
%***************** demoduration *******************
ich7=ich6./kmod;
qch7=qch6./kmod;
[demodata]=qpskdemod(ich7,qch7,para,nd,ml);
%************** Parallel to serial conversion *****************
demodata1=reshape(demodata,1,para*nd*ml);
%************************** Bit Error Rate (BER) ****************************
% instantaneous number of error and data
noe2=sum(abs(demodata1-seldata)); % sum : built in function
nod2=length(seldata); % length : built in function
% cumulative the number of error and data in noe and nod
noe=noe+noe2;
nod=nod+nod2;
end
% theoretical Values for BER
ber=noe2/nod2;
BerAwgn = [0.5*erfc(sqrt(ebn0)) 0.5*(1-(1/(sqrt(1+1/ebn0)))) noe/nod]
for k=1:length(BerAwgn)
Berawgn = BerAwgn(k);
% theoretical value for fading
%********************** Output result ***************************
% per=eop/nop;
fprintf('%f\t%e\t%d\t%d\t\n',ebn0,ber,BerAwgn,noe);
markerchoice = '.xo*';
plotsym = [markerchoice(k),'b-']; % Plotting style for this curve
semilogy(ebn0, Berawgn, plotsym); % Plot one curve.
drawnow; % Update the plot instead of waiting until the end.
hold on; % Make sure next iteration does not remove this curve.
end
end