ReComm
Member level 2
AA
The following code gives higher BER than the theoretical.
Can anyone help me why? and give me the way to modify the code.
code of BPSK- OFDM
===============
clc;
clear all
nFFT = 4; % fft size
nDSC = 4; % number of data subcarriers
nBitPerSym = 4; % number of bits per OFDM symbol (same as the number of subcarriers for BPSK)
nSym = 10^3; % number of symbols
carriers = (1:nBitPerSym) ;
ep =0;
EbN0dB = [1:15]; % bit to noise ratio
% Transmitter
ipBit = rand(1,nBitPerSym*nSym) > 0.5; % random 1's and 0's
modulated_data = 2*ipBit-1; % BPSK modulation 0 --> -1, 1 --> +1
for ll= 1:length(ep)
for iii=EbN0dB,
k = 1;
for n = 1:nSym
ofdm_symbol = zeros(1,nFFT);
% Map modulated data to FFT bins in OFDM symbol
ofdm_symbol(carriers) = modulated_data(k:k+nBitPerSym-1);
% Time Signal to transmit
tx_signal = (nFFT/sqrt(nDSC))*ifft(ofdm_symbol,nFFT);
% DOPPLER SHIFT
rx_signal1= tx_signal.*exp((2*j*pi*ep(ll)/nFFT ).*(0:length(tx_signal) -1));
rx_signal = awgn(rx_signal1, EbN0dB(iii),0);
% FFT
received_ofdm = (sqrt(nDSC)/nFFT)*fft(rx_signal, nFFT);
% Extract data from carriers in OFDM symbol
received_symbols(k:k+nBitPerSym-1) = received_ofdm(carriers);
k = k + nBitPerSym;
end
% PERFROM DEMODULATION
yF=received_symbols;
yF = reshape(yF,nBitPerSym,nSym).'; % formatting the received vector into symbo
ipModHat = 2*floor(real(yF/2)) + 1;
ipModHat(find(ipModHat>1)) = +1;
ipModHat(find(ipModHat<-1)) = -1;
% converting modulated values into bits
ipBitHat = (ipModHat+1)/2;
ipBitHat = reshape(ipBitHat.',nBitPerSym*nSym,1).';
% counting the errors
nErr(iii) = size(find(ipBitHat - ipBit),2)/(nSym*nBitPerSym);
end
end
Thanks in advance
The following code gives higher BER than the theoretical.
Can anyone help me why? and give me the way to modify the code.
code of BPSK- OFDM
===============
clc;
clear all
nFFT = 4; % fft size
nDSC = 4; % number of data subcarriers
nBitPerSym = 4; % number of bits per OFDM symbol (same as the number of subcarriers for BPSK)
nSym = 10^3; % number of symbols
carriers = (1:nBitPerSym) ;
ep =0;
EbN0dB = [1:15]; % bit to noise ratio
% Transmitter
ipBit = rand(1,nBitPerSym*nSym) > 0.5; % random 1's and 0's
modulated_data = 2*ipBit-1; % BPSK modulation 0 --> -1, 1 --> +1
for ll= 1:length(ep)
for iii=EbN0dB,
k = 1;
for n = 1:nSym
ofdm_symbol = zeros(1,nFFT);
% Map modulated data to FFT bins in OFDM symbol
ofdm_symbol(carriers) = modulated_data(k:k+nBitPerSym-1);
% Time Signal to transmit
tx_signal = (nFFT/sqrt(nDSC))*ifft(ofdm_symbol,nFFT);
% DOPPLER SHIFT
rx_signal1= tx_signal.*exp((2*j*pi*ep(ll)/nFFT ).*(0:length(tx_signal) -1));
rx_signal = awgn(rx_signal1, EbN0dB(iii),0);
% FFT
received_ofdm = (sqrt(nDSC)/nFFT)*fft(rx_signal, nFFT);
% Extract data from carriers in OFDM symbol
received_symbols(k:k+nBitPerSym-1) = received_ofdm(carriers);
k = k + nBitPerSym;
end
% PERFROM DEMODULATION
yF=received_symbols;
yF = reshape(yF,nBitPerSym,nSym).'; % formatting the received vector into symbo
ipModHat = 2*floor(real(yF/2)) + 1;
ipModHat(find(ipModHat>1)) = +1;
ipModHat(find(ipModHat<-1)) = -1;
% converting modulated values into bits
ipBitHat = (ipModHat+1)/2;
ipBitHat = reshape(ipBitHat.',nBitPerSym*nSym,1).';
% counting the errors
nErr(iii) = size(find(ipBitHat - ipBit),2)/(nSym*nBitPerSym);
end
end
Thanks in advance