grozdov
Newbie level 2
ofdm ber
Hello;
I am new in MATLAB, I got this MATLAB code from one book... I want to plot BER versus Eb/No... can someone help me in this?
Thanks
% ****** This is a simultion to realize OFDM transmission
para = 128; % No. of parallel channels
fftlen = 128; % FFT length
noc = 128; % No. of carriers
nd = 6; % No. of information OFDM symbol for one loop
ml = 2; % Modulation level
sr = 250000 % Symbol rate
br = sr*ml % Bit rate per carrier
gilen = 32; % Length of guard interval points
ebno = 1:5; % Eb/No try also 100
% ****** main loop *************************
nloop = 100; % No. of simulation loops
noe = 0; % No. of error data
nod = 0; % No. No. of transmitted data
eop = 0; % No. of error packets
nop = 0; % NO. of transmitted packets
for i = 1:nloop
% **********Transmitter
% Data generator
for k = 1:length(ebno)
seldata = rand(1,para*nd*ml)>0.5;
% Serial to parralel conversion
paradata = reshape(seldata,para,nd*ml);
%QPSK modulation
[ich,qch] = qpskmod(paradata,para,nd,ml);
% The I and Q data are increased kmod times to normalize the data
kmod = 1/sqrt(2);
ich1 = ich.*kmod;
qch1 = qch.*kmod;
% IFFT
x = ich1+qch1.*i; % Parellel are converted to serial
y = ifft(x);
ich2 = real;
qch2 = imag;
% Guard interval insertion
[ich3,qch3] = giins(ich2,qch2,fftlen,gilen,nd);
fftlen2 = fftlen + gilen
% Attenuation
spow = sum(ich3.^2 + qch3.^2)/nd./para;
attn = 0.5*spow*sr/br*10.^(-ebno/10);
attn = sqrt(attn);
% Receiver plus noise
[ich4,qch4] = comb(ich3,qch3,attn(k));
% Guard removal
[ich5,qch5] = girem(ich4,qch4,fftlen2,gilen,nd);
% FFT
rx = ich5 + qch.*i;
ry = fft(rx);
ich6 = real(ry);
qch6 = imag(ry);
% Demodulation
ich7 = ich6./kmod;
qch7 = qch6./kmod;
[demodata] = qpskdemod(ich7,qch7,para,nd,ml);
% Parallel to serial conversion
demodata1 = reshape(demodata,1,para*nd*ml);
% BER calculations
noe2(k) = sum(abs(demodata1-seldata));
nod2(k) = length(seldata);
% Cummulative the no. of errors and data in noe and nod
noe = noe(k) + noe2;
nod = nod (k)+ nod2;
% Calculating PER
if noe2 ~=0;
eop = eop
end
nop = nop + 1;
ber = noe/nod
per = eop/nop;
ber(k) = noe/nod
end
end
% *********** Output results
Hello;
I am new in MATLAB, I got this MATLAB code from one book... I want to plot BER versus Eb/No... can someone help me in this?
Thanks
% ****** This is a simultion to realize OFDM transmission
para = 128; % No. of parallel channels
fftlen = 128; % FFT length
noc = 128; % No. of carriers
nd = 6; % No. of information OFDM symbol for one loop
ml = 2; % Modulation level
sr = 250000 % Symbol rate
br = sr*ml % Bit rate per carrier
gilen = 32; % Length of guard interval points
ebno = 1:5; % Eb/No try also 100
% ****** main loop *************************
nloop = 100; % No. of simulation loops
noe = 0; % No. of error data
nod = 0; % No. No. of transmitted data
eop = 0; % No. of error packets
nop = 0; % NO. of transmitted packets
for i = 1:nloop
% **********Transmitter
% Data generator
for k = 1:length(ebno)
seldata = rand(1,para*nd*ml)>0.5;
% Serial to parralel conversion
paradata = reshape(seldata,para,nd*ml);
%QPSK modulation
[ich,qch] = qpskmod(paradata,para,nd,ml);
% The I and Q data are increased kmod times to normalize the data
kmod = 1/sqrt(2);
ich1 = ich.*kmod;
qch1 = qch.*kmod;
% IFFT
x = ich1+qch1.*i; % Parellel are converted to serial
y = ifft(x);
ich2 = real;
qch2 = imag;
% Guard interval insertion
[ich3,qch3] = giins(ich2,qch2,fftlen,gilen,nd);
fftlen2 = fftlen + gilen
% Attenuation
spow = sum(ich3.^2 + qch3.^2)/nd./para;
attn = 0.5*spow*sr/br*10.^(-ebno/10);
attn = sqrt(attn);
% Receiver plus noise
[ich4,qch4] = comb(ich3,qch3,attn(k));
% Guard removal
[ich5,qch5] = girem(ich4,qch4,fftlen2,gilen,nd);
% FFT
rx = ich5 + qch.*i;
ry = fft(rx);
ich6 = real(ry);
qch6 = imag(ry);
% Demodulation
ich7 = ich6./kmod;
qch7 = qch6./kmod;
[demodata] = qpskdemod(ich7,qch7,para,nd,ml);
% Parallel to serial conversion
demodata1 = reshape(demodata,1,para*nd*ml);
% BER calculations
noe2(k) = sum(abs(demodata1-seldata));
nod2(k) = length(seldata);
% Cummulative the no. of errors and data in noe and nod
noe = noe(k) + noe2;
nod = nod (k)+ nod2;
% Calculating PER
if noe2 ~=0;
eop = eop
end
nop = nop + 1;
ber = noe/nod
per = eop/nop;
ber(k) = noe/nod
end
end
% *********** Output results