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 wrote a code and facing problems in it. it gives error in the line written in red color.
Plz help
??? Error using ==> xor
Operands must be real.
Error in ==> TestRun at 74
numErrors=sum(xor(RecSymbols,data)); % Count Number of Errors
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:10; % 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; % BPSK Modulation
d_ifft=ifft(s); % Apply IFFT
ofdm_signal=[d_ifft,N-Ncp+1:N) d_ifft]; % Adding Cyclic Prefix
[rows cols]=size(ofdm_signal);
%Parallel to serial conversion for transmission
ofdm_signal=reshape(ofdm_signal.',1,rows*cols);
%Zero mean unit variance AWGN channel
Tdata=awgn(ofdm_signal,i); % AWGN added
%Receiver
RecDataP=reshape(Tdata.',(N+Ncp),samples).'; % Serial to Parallel Conversion
% Removing Cyclic Prefix
RecDataP=RecDataP,Ncp+1N+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;
end
if 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 using ==> xor
Operands must be real.
Error in ==> TestRun at 74
numErrors=sum(xor(RecSymbols,data)); % Count Number of Errors
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:10; % 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; % BPSK Modulation
d_ifft=ifft(s); % Apply IFFT
ofdm_signal=[d_ifft,N-Ncp+1:N) d_ifft]; % Adding Cyclic Prefix
[rows cols]=size(ofdm_signal);
%Parallel to serial conversion for transmission
ofdm_signal=reshape(ofdm_signal.',1,rows*cols);
%Zero mean unit variance AWGN channel
Tdata=awgn(ofdm_signal,i); % AWGN added
%Receiver
RecDataP=reshape(Tdata.',(N+Ncp),samples).'; % Serial to Parallel Conversion
% Removing Cyclic Prefix
RecDataP=RecDataP,Ncp+1N+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;
end
if 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');