w_bwr
Member level 3
- Joined
- Feb 4, 2010
- Messages
- 66
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Karachi, Pakistan
- Activity points
- 1,810
Hi
i have written code for OFDM using Single Tap Raylaigh Fading Channel. But the result seems incorrect.
Please help finding out the mistake.
%BPSK OFDM over Rayleigh Fading Channel
%08-DCET-73
clear all;
clc;
% OFDM Parameters
N=1024; % Total number of Subcarriers
ofdmBW=2.5e6; % OFDM Bandwitdh
deltaf=ofdmBW/256; %data on each subcarriers
Tfft=1/deltaf; % ifft period
Tgi=Tfft/4; %guard interval duration duration of cyclic prefix 1/4rth portion of ofdm symbols
Tsignal=Tgi+Tfft; %total duration of BPSK-OFDM symbols=guard time+ifft period
Ncp=N*Tgi/Tfft; %number of symbols allocated to cyclic prefix
nbitspersymbol=N; % For BPSK, the number of Bits/Symbol is the same as N
% Simulation Parameters
samples=10; %Number of the OFDM Symbols to transmit
EbNOdB= 0:20; % Bit to noise ratio
EsNOdB = EbNOdB + 10*log10(N/(Ncp+N)); % Symbol to Noise Ratio
SimulatedBER = zeros(1,length(EsNOdB)); %Place Holder for Simulated BER
TheoreticalBER = zeros(1,length(EsNOdB)); %Place Holder for Theoretical BER
% Monte Carlo Simulation
for i=1:length(EsNOdB),
%Transmitter
data=randint(1,N*samples); % Generating Random Data
A=reshape(data,samples,N); % Serial to Parallel
s=2*A-1; % BPSK Modulation (1=1 & 0=-1)
d_ifft=ifft(s); % Applying IFFT
ofdm_signal=[d_ifft,N-Ncp+1:N) d_ifft]; % Cyclic Prefix
[rows cols]=size(ofdm_signal);
TxSignal = reshape(ofdm_signal,1,rows*cols);
%Single Tap Rayleigh Fading Channel
ht = 1/sqrt(2)*(randn(1,rows*cols));
noise=1/sqrt(2)*(randn(1,rows*cols));
Tdata= sqrt((N+Ncp)/N).*ht.*TxSignal + 10^(-EsNOdB(i)/20)*noise;
%Receiver
RecDataP=reshape(Tdata,(N+Ncp),samples).'; % Serial to Parallel Conversion
% Removing Cyclic Prefix
RecDataP=RecDataP,Ncp+1N+Ncp));
% FFT
R_Freq=fft(RecDataP);
%BPSK Demodulation
R_Freq1= reshape(R_Freq,1,samples*N);
R_Freq1(R_Freq1>0) = +1;
R_Freq1(R_Freq1<0) = 0;
s_cap=R_Freq1;
RecSymbols=R_Freq1;
numErrors=sum(xor(RecSymbols,data)); % Count Number of Errors
SimulatedBER(i)=numErrors/(samples*N);
%%TheoreticalBER(i)=(1/2)*erfc(sqrt(10.^(EbNOdB(i)/10))); % AWGN Channel
end
EbNO= 10.^(EbNOdB/10); % EbNO in Linear Scale
TheoreticalBER = 0.5.*(1-sqrt(EbNO./(EbNO+1))); % For Rayleigh Fading
% Results
figure
semilogy(EbNOdB,SimulatedBER,'r-o');
hold on;
semilogy(EbNOdB,TheoreticalBER,'k*');
grid on; title('BER Vs SNR(db) for OFDM with BPSK Modulation Over AWGN Channel');
xlabel ('Eb/No (dB)');ylabel ('BER');legend ('simulated','theoretical');
title('BER for BPSK using OFDM in single Tap Rayleigh channel')
It gives the following result.
i have written code for OFDM using Single Tap Raylaigh Fading Channel. But the result seems incorrect.
Please help finding out the mistake.
%BPSK OFDM over Rayleigh Fading Channel
%08-DCET-73
clear all;
clc;
% OFDM Parameters
N=1024; % Total number of Subcarriers
ofdmBW=2.5e6; % OFDM Bandwitdh
deltaf=ofdmBW/256; %data on each subcarriers
Tfft=1/deltaf; % ifft period
Tgi=Tfft/4; %guard interval duration duration of cyclic prefix 1/4rth portion of ofdm symbols
Tsignal=Tgi+Tfft; %total duration of BPSK-OFDM symbols=guard time+ifft period
Ncp=N*Tgi/Tfft; %number of symbols allocated to cyclic prefix
nbitspersymbol=N; % For BPSK, the number of Bits/Symbol is the same as N
% Simulation Parameters
samples=10; %Number of the OFDM Symbols to transmit
EbNOdB= 0:20; % Bit to noise ratio
EsNOdB = EbNOdB + 10*log10(N/(Ncp+N)); % Symbol to Noise Ratio
SimulatedBER = zeros(1,length(EsNOdB)); %Place Holder for Simulated BER
TheoreticalBER = zeros(1,length(EsNOdB)); %Place Holder for Theoretical BER
% Monte Carlo Simulation
for i=1:length(EsNOdB),
%Transmitter
data=randint(1,N*samples); % Generating Random Data
A=reshape(data,samples,N); % Serial to Parallel
s=2*A-1; % BPSK Modulation (1=1 & 0=-1)
d_ifft=ifft(s); % Applying IFFT
ofdm_signal=[d_ifft,N-Ncp+1:N) d_ifft]; % Cyclic Prefix
[rows cols]=size(ofdm_signal);
TxSignal = reshape(ofdm_signal,1,rows*cols);
%Single Tap Rayleigh Fading Channel
ht = 1/sqrt(2)*(randn(1,rows*cols));
noise=1/sqrt(2)*(randn(1,rows*cols));
Tdata= sqrt((N+Ncp)/N).*ht.*TxSignal + 10^(-EsNOdB(i)/20)*noise;
%Receiver
RecDataP=reshape(Tdata,(N+Ncp),samples).'; % Serial to Parallel Conversion
% Removing Cyclic Prefix
RecDataP=RecDataP,Ncp+1N+Ncp));
% FFT
R_Freq=fft(RecDataP);
%BPSK Demodulation
R_Freq1= reshape(R_Freq,1,samples*N);
R_Freq1(R_Freq1>0) = +1;
R_Freq1(R_Freq1<0) = 0;
s_cap=R_Freq1;
RecSymbols=R_Freq1;
numErrors=sum(xor(RecSymbols,data)); % Count Number of Errors
SimulatedBER(i)=numErrors/(samples*N);
%%TheoreticalBER(i)=(1/2)*erfc(sqrt(10.^(EbNOdB(i)/10))); % AWGN Channel
end
EbNO= 10.^(EbNOdB/10); % EbNO in Linear Scale
TheoreticalBER = 0.5.*(1-sqrt(EbNO./(EbNO+1))); % For Rayleigh Fading
% Results
figure
semilogy(EbNOdB,SimulatedBER,'r-o');
hold on;
semilogy(EbNOdB,TheoreticalBER,'k*');
grid on; title('BER Vs SNR(db) for OFDM with BPSK Modulation Over AWGN Channel');
xlabel ('Eb/No (dB)');ylabel ('BER');legend ('simulated','theoretical');
title('BER for BPSK using OFDM in single Tap Rayleigh channel')
It gives the following result.