Why do we need to write the noise as randn(2,1)./sqrt(2*SNR) instead of randn(1,1)/sqrt(2)?

14 views (last 30 days)
I saw this code, about the error probability of on/off signal ,on the internet
Ts=10^4;
SNR_dB=[-3 0 3 6 9];
Ne=zeros(1,length(SNR_dB));
for i=1:length(SNR_dB)
SNR=10^(SNR_dB(i)/10);
for t=1:Ts
s=((sign(rand()-0.5))+1)/2;%create the "on"signal or "off" signal ."on"signal=1,"off" signal=0
r=randn(2,1)./sqrt(2.*SNR);%it seems that it is noise
if (s+r)>0.5
s_hat=1;
else
s_hat=0;
end
if abs(s_hat-s)>0
Ne(i)=Ne(i)+1;
end
y=Ne./Ts;
end
end
Pe=zeros(1,5);
for i=1:5
SNR=10^(SNR_dB(i)/10);
Pe(i)=erfc(sqrt(SNR/2)/(2^0.5))/2;
end
semilogy(SNR_dB,y,'-r',SNR_dB,Pe,'-k')
I don't understand why can the noise be written as
r=randn(2,1)./sqrt(2.*SNR)
,why do we need to write as randn(2,1)./sqrt(2*SNR) instead of randn(1,1)/sqrt(2)?Is anyone know about this?

Answers (0)

Categories

Find more on Communications Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!