Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Why is the last simulation value is "0",i can't find where is wrong

1 回表示 (過去 30 日間)
yang-En Hsiao
yang-En Hsiao 2019 年 4 月 21 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I write an error probability of anti-podal,however,i found the last simulation value is zero,it means that there is no any error signal in the receiver at that time,but that is possible,and i can't find where do i wrong,can anyone help me?
Code
T_s=10^4;
SNR_dB=[-3 0 3 6 9];
SNR_Watt=10.^(SNR_dB./10);
anti_signal=rand(1,T_s)
%Create the anti-podal signal
for ii=1:length(SNR_dB)
for t=1:T_s
if anti_signal(t)>0.5
anti_signal(t)=1;
else
anti_signal(t)=-1;
end
end
%AWGN noise
noise=(1/sqrt(2)*[randn(1,T_s)+1i*randn(1,T_s)]);
%receive_signal
%10.^(-SNR_dB(ii)/20)*noise is the noise in "x" SNR,like -3dB,0dB,3dB,6dB and 9dB
receive_signal=anti_signal+10.^(-SNR_dB(ii)/20)*noise;
for q=1:T_s
if receive_signal(q)>0
receive_signal(q)=1;
else
receive_signal(q)=-1;
end
end
simulation(ii)=(T_s-sum(anti_signal==receive_signal))/T_s%(Total number-the number which is right)-Total number
end
theoretical=1/2*erfc(sqrt(SNR_Watt));
semilogy(SNR_dB,simulation,SNR_dB,theoretical)
The simulation result is as below,as we can see,the last number is always "0",why?i think there is something wrong in the code,but if this 0 is correct,i can't find a reasonable reason to convince to me
smu.PNG
  1 件のコメント
Stephen23
Stephen23 2019 年 4 月 21 日
編集済み: Stephen23 2019 年 4 月 21 日
Note that you should preallocate that array before the loop:
....
N = numel(SNR_db);
simulation = nan(1,N); % !!! Preallocate !!!
for ii = 1:N
....
simulation(ii) = ...
end

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 4 月 21 日
Your noise is complex valued, so your received_signal is complex valued. However, your if statements treat it as if it were real valued.

Community Treasure Hunt

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

Start Hunting!

Translated by