simulation of ofdm with QPSK in Rayleigh channel

Started by September 29, 2008
i have simulated a general ofdm system but i am not having correct results. can any one rectify problems in this code. have i used correct formulas in this code? i mean does RAYLEIGHCHAN command hold for it? do i need to equalize the receiver signal? if so then how and at what stage? and have i used right command for theoritical BER of OFDM in Rayleigh channel?

% Script for computing the BER for PSK in OFDM modulation in the
% presence of Rayeligh fading channel

clear all
nFFT = 64; % fft size
nDSC = 32; % number of data subcarriers
nBitPerSym = 32; % number of bits per OFDM symbol (same as the number of subcarriers)
nSym = 10^2; % number of symbols
M = 4; % qpsk modulation
CP; % no. of CP samples
EbN0dB = [0:5:30]; % bit to noise ratio
EsN0dB = EbN0dB + 10*log10(nDSC/nFFT) + 10*log10(64/80);
% converting to symbol to noise ratio

for ii = 1:length(EbN0dB)

% Transmitter
ipBit = randint(1,nBitPerSym*nSym,M); % random 1's and 0's
ipMod = pskmod(ipBit,M);
ipMod = reshape(ipMod,nSym,nBitPerSym); % grouping into multiple symbols
% Assigning modulated symbols to subcarriers from [-16 to -1, +1 to +16]
xF = [zeros(nSym,6) ipMod(:,[1:nBitPerSym/2]) zeros(nSym,1) ipMod(:,[nBitPerSym/2+1:nBitPerSym]) zeros(nSym,5)] ;

% Taking FFT, the term (nFFT/sqrt(nDSC)) is for normalizing the power of transmit symbol to 1
xt = (nFFT/sqrt(nDSC))*ifft(fftshift(xF.'),nFFT).';

% Appending cylic prefix 16 samples
xt = [xt(:,[end-CP:end]) xt];

% multipath channel
xt = reshape(xt.',1,prod(size(xt)));

% Gaussian noise of unit variance, 0 mean
nt = 1/sqrt(2)*[randn(1,prod(size(xt))) + j*randn(1,prod(size(xt)))];

% Adding noise, the term sqrt(80/64) is to account for the wasted energy due to cyclic prefix
yt = sqrt(60/44)*xt + 10^(-EsN0dB(ii)/20)*nt;

% Receiver
% formatting the received vector into symbols
yt = reshape(yt,nSym,length(yt)/nSym);
yt = yt(:,[CP+1:end]); % removing cyclic prefix

% converting to frequency domain
yF = (sqrt(nDSC)/nFFT)*fftshift(fft(yt.')).';

% extracting the required data subcarriers
yMod = yF(:,[6+[1:nBitPerSym/2] 7+[nBitPerSym/2+1:nBitPerSym] ]);

% PSK demodulation

rx_ipBit = pskdemod(yMod,M);
rx_ipBit = reshape(rx_ipBit.',nBitPerSym*nSym,1).';

% counting the errors
[nErr(ii) ber(ii)]=biterr(ipBit,rx_ipBit);
theoryBer = berfading(EbN0dB,'psk',2,1);

close all; figure
semilogy(EbN0dB,theoryBer,'b.-');hold on
semilogy(EbN0dB,ber,'r.:');grid on
legend('Rayleigh-Theoritical BER', 'Rayleigh-Simulated BER');
xlabel('Eb/No, dB');ylabel('Bit Error Rate');
title('BER for QPSK using OFDM in Rayleigh channel');