What should I do if I am getting different output every time I run my code in MATLAB code to obtain Bit error rate of BPSK modulation for the given data-[1 0 0 0 0 1 1 1]

3 ビュー (過去 30 日間)
%BER of BPSK for given data=[1 0 0 0 0 1 1 1]
clc;
clear all;
close all;
%input data
N=8;
m=[1 0 0 0 0 1 1 1];
x=zeros(1, N); %preallocating variable
for i=1:N
if m(i)==0
x(i)=-1;
else
x(i)=1;
end
end
ber_sim=[]; %empty array for bit error rate
ber_theory_erfc=[]; %empty array for theoretical bit error rate
ber_theory_Q=[]; %empty array for Q equation
ber_chernoff=[]; % BER approximation for upper bound(chernoff bound)
for EbN0dB=0:1:15 %SNR value in dB
EbN0=10^(EbN0dB/10); %convert to normal scale
sigma=sqrt(1/(2*EbN0));
r=x+sigma.*randn(1,N); %AWGN channel with random numbers
m_cap=(r>0); %detected bits, threshold=0
%BER calculation
noe=sum(m~=m_cap); %number of errors, sum if m is not equal to m_cap
ber_sim1=noe/N; %bit error rate calculation with simulation values
ber_sim=[ber_sim ber_sim1];
ber_th_er=0.5*erfc(sqrt(EbN0)); %theoretical bit error rate calculation
ber_theory_erfc=[ber_theory_erfc ber_th_er];
ber_th_q=qfunc(sqrt(2*EbN0)); %bit error rate in terms of Q function
ber_theory_Q=[ber_theory_Q ber_th_q];
ber_cher=0.5*exp(-EbN0); %highest possible bit error rate
ber_chernoff=[ber_chernoff ber_cher];
end
EbN0dB=0:1:15;
semilogy(EbN0dB,ber_sim,'r*-',EbN0dB,ber_theory_erfc,'ko-',EbN0dB,ber_theory_Q,'g+-',EbN0dB,ber_chernoff,' m>-');
xlabel('Eb/N0(dB)');
ylabel('BER');
legend('Simulation','Theory(erfc)','Theory(Q)','Chernoff');
grid on;

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 12 月 17 日
編集済み: KALYAN ACHARJYA 2020 年 12 月 17 日
Because of the following line (function randn)you are getting different results each time, may be random noise addition
r=x+sigma.*randn(1,N); %AWGN channel with random numbers
%............^
  2 件のコメント
Nikshith Shetty
Nikshith Shetty 2020 年 12 月 19 日
I asked one of my matlab professor and he said the same thing, that i didn't need to change the code and for our level this much is enough.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBPSK についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by