I have to calculate BER(bit error rate ) of OOK(on off keying signal)

22 次查看(过去 30 天)
Dear fellows,i have generated OOK(on off keying signal).Then i have taken FFT of OOK signal and then i have removed some part of frequecny from 50-150HZ.Then again i have taken IFFT so that i can see signal in time domain.This code is working perfectly now by collaboration of you guys.Now my next step is calculate BER(bit error rate).I have write code for it but it is not working well even when i simulate it ,it is giving errorsThere should be no errors when BODE=10,and when we increase it it gives errors.I am Pastin my both codes.
clc,close all,clear all
codn=100;
% fc=6e+3;
fs=360;
bode=10;
code=round(rand(1,codn));
code_len=round(1/bode/(1/fs))
for ii=1:codn
x((ii-1)*code_len+1:code_len*ii)=code(ii)
end
x2 = x-(1/2) % get rid of most of the dc peak
% set up time and frequency arrays
length(x)
u = length(x)
N = 2^nextpow2(u)
delt = 1/fs;
delf = fs/N;
delf1=fs/u
% shifted frequency array
figure(1)
tvec2=(1:length(x2))*delt;
plot(tvec2,x2(1,:)+0.5)
title('orignal baseband')
xlabel('time');
ylabel('amplitude')
ylim([-1 1.5]);
% n = 2^nextpow2(N);
y = fftshift(fft(x2)/N);
z=abs(y);
figure(2)
fvec2=(-length(x2)/2:length(x2)/2-1)*delf1;
plot(fvec2,z)
title('FFT')
xlabel('frequency')
ylabel('amplitude')
figure(3)
z=y;
z(abs(fvec2)>50 & abs(fvec2)<=150)=0
plot(fvec2,abs(z))
xlabel('frequency removed from 50 to 150 HZ');
ylabel('amplitude')
figure(4)
zf=fftshift(z)*N;
zifft=ifft(zf)+0.5;
plot(tvec2,abs(zifft))
ylim([-1 1.5])
title('recovered signal')
xlabel('time');
ylabel('amplitude')
The above code is ok.
Problem is in the code below.Please anyone can remove erros.i tried but not succcedded.I have set fs=360 and bode=10.At these parameters there should be no BER,but if i increase bode then there should be errors,because if you run above code and change bode>10 then in last figure(4) you can see there are bit which are distorted.
clc,close all,clear all
codn=100;
max_run=20;
Eb=1;
SNRdB=0:1:9; %Signal to Noise Ratio (in dB)
SNR=10.^(SNRdB/10);
fs=360;
bode=10;
code=round(rand(1,codn));
code_len=round(1/bode/(1/fs)) % no of samples/symbol
for iii=1:length(SNR)
avgError=0;
No=Eb/SNR(iii);
for ii=1:codn
x((ii-1)*code_len+1:code_len*ii)=code(ii);
Error=0;
data=randint(1,codn);
N=sqrt(No/2)*randn(1,codn);
Y=N;
% length(x)
u = length(x);
N = 2^nextpow2(u);
delt = 1/fs;
delf1=fs/u;
figure(1)
tvec2=(1:length(x))*delt;
plot(tvec2,x(1,:)+0.5)
title('orignal baseband')
xlabel('time');
ylabel('amplitude')
ylim([-1 1.5]);
y = fftshift(fft(x)/N);
z=abs(y);
figure(2)
fvec2=(-length(x)/2:length(x)/2-1)*delf1;
plot(fvec2,z)
title('FFT')
xlabel('frequency')
ylabel('amplitude')
figure(3)
z=y;
z(abs(fvec2)>120 & abs(fvec2)<=150)=0;
plot(fvec2,abs(z))
xlabel('frequency removed from 50 to 150 HZ');
ylabel('amplitude')
figure(4)
zf=fftshift(z)*N;
zifft=ifft(zf)+0.5;
for k=1:codn %Decision device taking hard decision and deciding error
if ((Y(k)>0 && data(k)==0)||(Y(k)<0 && data(k)==1))
Error=Error+1;
end
end
Error=Error/codn; %Calculate error/bit
avgError=avgError+Error; %Calculate error/bit for different runs
end
BER_sim(codn)=avgError/max_run;
end
BER_th=(1/2)*erfc(sqrt(SNR)); %Calculate analytical BER
plot(tvec2,abs(zifft))
ylim([-1 1.5])
title('recovered signal')
xlabel('time');
ylabel('amplitude')
figure; semilogy(SNRdB,BER_sim,'k*');
xlabel('Eb/N0,db');
ylabel('Bit Error Rate');
grid on
title('Bit error probability curve for OOK ');
legend('simulation','theory');

回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-11-17
编辑:KALYAN ACHARJYA 2019-11-17
I have checked the code, as suggested you the followings points:
First one: As the error pointed, use randi insteat on randint
data=randi(1,codn);
Second Case: Remove all those figure statements, which continoustly generates new figures, when the code interrate within for loop
Third one:
semilogy(SNRdB,BER_sim,'k*');
Here SNRdB having length 1x10, whereas BER_sim having 1x100, how can you plot the two vectors having different vector length? Please do changes accordingly to ensure that all plots parametesr must be having same length.
Beacuae the code is quite lengthy, hence it may take time to make it accurate & more efficient.
Hope it helps!

类别

Help CenterFile Exchange 中查找有关 Modulation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by