We have previously looked at a simple OFDM modulation and demodulation scheme. We saw that the BER performance of OFDM in AWGN was the same as the BER performance of the underlying modulation scheme (QPSK in this case). We will now continuously improve upon our basic simulation to get a more realistic picture. In this regard we introduce the cyclic prefix which is used in OFDM to overcome Intersymbol Interference. The duration of the cyclic prefix is 0.8usec (16 samples at 20MHz) resulting in a symbol duration of 4usec (IEEE 802.11a). Given below is the code for OFDM modulation and demodulation with cyclic prefix.

```
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FUNCTION TO CALCULATE BER OF OFDM IN AWGN
% seq_len: Input, number of OFDM symbols
% n_carr: Input, number of subcarriers
% EbNo: Input, energy per bit to noise PSD
% ber: Output, bit error rate
% Copyright RAYmaps (www.raymaps.com)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[ber]=OFDM_err(seq_len,n_carr,EbNo)
n_pre=16;
n_tot=n_carr+n_pre;
for n=1:seq_len
si=2*(round(rand(1,n_carr))-0.5);
sq=2*(round(rand(1,n_carr))-0.5);
s=si+j*sq;
s_ofdm=sqrt(n_carr)*ifft(s,n_carr);
s_cyc=sqrt(n_carr/n_tot)*([s_ofdm(49:64),s_ofdm]);
wn=(1/sqrt(2*10^(EbNo/10)))*(randn(1,n_tot)+j*randn(1,n_tot));
r=s_cyc+wn;
r_ext=r(17:80);
s_est=fft(r_ext,n_carr);
si_est=sign(real(s_est));
sq_est=sign(imag(s_est));
ber1(n)=(n_carr-sum(si==si_est))/n_carr;
ber2(n)=(n_carr-sum(sq==sq_est))/n_carr;
end
ber=mean([ber1 ber2]);
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
```

Since the number of samples is increased from 64 to 80 their is an increase in symbol energy. Therefore the signal level needs to be scaled by a factor of sqrt(64/80) to keep the total symbol energy to be the same. This results in approximately 1dB of loss in BER performance as shown in the figure below.