Post by waheed on Sept 23, 2011 13:31:40 GMT -5
Hi , i wrote a code and facing problems in it. it gives error in the line written in red color.
Plz help
Error is:
??? Undefined function or method 'EsN0dB' for input arguments of
type 'double'.
Error in ==> TestRun at 48
Tdata= sqrt((N+Ncp)/N)*ofdm_signal + 10^(-EsN0dB(i)/20)*noise;
Here is the code:
clear all;
clc;
% OFDM Parameters
N=256;
ofdmBW=2.5e6;
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=100; %Number of the OFDM Symbols to transmit
EbNOdB= -10:2:8; % Bit to noise ratio
EsNOdB= EbNOdB + 10*log10(N/N) + 10*log10(N/(Ncp+N)); % Symbol to Noise Ratio
SimulatedBER = zeros(1,length(EsNOdB));
TheoreticalBER = zeros(1,length(EsNOdB));
% Monte Carlo Simulation
for i=1:length(EsNOdB),
%Transmitter
data=randint(1,N*samples);
A=reshape(data,samples,N);
s=2*A-1;
d_ifft=N/sqrt(N)*ifft(s);
ofdm_signal=[d_ifft(:,N-Ncp+1:N) d_ifft];
[rows cols]=size(ofdm_signal);
%Parallel to serial conversion for transmission
ofdm_signal=reshape(ofdm_signal.',1,rows*cols);
%-----------------------------------------------
%Channel Modeling
%-----------------------------------------------
%Zero mean unit variance AWGN channel
noise=1/sqrt(2)*(randn(1,rows*cols)+1i*randn(1,rows*cols));
Tdata= sqrt((N+Ncp)/N)*ofdm_signal + 10^(-EsN0dB(i)/20)*noise;
%Receiver
RecDataP=reshape(Tdata.',(N+Ncp),samples).'; % Serial to Parallel Conversion
% Removing Cyclic Prefix
RecDataP=RecDataP(:,Ncp+1:(N+Ncp));
% FFT
R_fft=fft(RecDataP);
%BPSK Demodulation
for m=1:samples
for n=1:N
if R_fft(m,n)==1
R_fft(m,n)=1;
else R_fft(m,n)==-1
R_fft(m,n)=0;
end
end
end
RecSymbols=reshape(R_fft,1,N*samples);
numErrors=sum(xor(RecSymbols,data)); % Count Number of Errors
simulatedBER(i)=numErrors/(100);
theoreticalBER(i)=(1/2)*erfc(sqrt(10.^(EbNOdB(i)/10)))
end
% Results
plot(EbNOdB,log10(simulatedBER),'r-o');
hold on;
plot(EbNOdB,log10(theoreticalBER),'k*');
grid on; tiltle('BER Vs SNR(db) for OFDM with BPSK Modulation Over AWGN Channel');
xlabel ('Eb/No (dB)');ylabel ('BER');legend ('simulated','theoretical');
Plz help
Error is:
??? Undefined function or method 'EsN0dB' for input arguments of
type 'double'.
Error in ==> TestRun at 48
Tdata= sqrt((N+Ncp)/N)*ofdm_signal + 10^(-EsN0dB(i)/20)*noise;
Here is the code:
clear all;
clc;
% OFDM Parameters
N=256;
ofdmBW=2.5e6;
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=100; %Number of the OFDM Symbols to transmit
EbNOdB= -10:2:8; % Bit to noise ratio
EsNOdB= EbNOdB + 10*log10(N/N) + 10*log10(N/(Ncp+N)); % Symbol to Noise Ratio
SimulatedBER = zeros(1,length(EsNOdB));
TheoreticalBER = zeros(1,length(EsNOdB));
% Monte Carlo Simulation
for i=1:length(EsNOdB),
%Transmitter
data=randint(1,N*samples);
A=reshape(data,samples,N);
s=2*A-1;
d_ifft=N/sqrt(N)*ifft(s);
ofdm_signal=[d_ifft(:,N-Ncp+1:N) d_ifft];
[rows cols]=size(ofdm_signal);
%Parallel to serial conversion for transmission
ofdm_signal=reshape(ofdm_signal.',1,rows*cols);
%-----------------------------------------------
%Channel Modeling
%-----------------------------------------------
%Zero mean unit variance AWGN channel
noise=1/sqrt(2)*(randn(1,rows*cols)+1i*randn(1,rows*cols));
Tdata= sqrt((N+Ncp)/N)*ofdm_signal + 10^(-EsN0dB(i)/20)*noise;
%Receiver
RecDataP=reshape(Tdata.',(N+Ncp),samples).'; % Serial to Parallel Conversion
% Removing Cyclic Prefix
RecDataP=RecDataP(:,Ncp+1:(N+Ncp));
% FFT
R_fft=fft(RecDataP);
%BPSK Demodulation
for m=1:samples
for n=1:N
if R_fft(m,n)==1
R_fft(m,n)=1;
else R_fft(m,n)==-1
R_fft(m,n)=0;
end
end
end
RecSymbols=reshape(R_fft,1,N*samples);
numErrors=sum(xor(RecSymbols,data)); % Count Number of Errors
simulatedBER(i)=numErrors/(100);
theoreticalBER(i)=(1/2)*erfc(sqrt(10.^(EbNOdB(i)/10)))
end
% Results
plot(EbNOdB,log10(simulatedBER),'r-o');
hold on;
plot(EbNOdB,log10(theoreticalBER),'k*');
grid on; tiltle('BER Vs SNR(db) for OFDM with BPSK Modulation Over AWGN Channel');
xlabel ('Eb/No (dB)');ylabel ('BER');legend ('simulated','theoretical');