cm_sm52.m

来自「详细介绍了cdma通信系统功率控制的算法」· M 代码 · 共 49 行

M
49
字号
function [p]=cm_sm52(snr_in_dB)% [p]=cm_sm52(snr_in_dB)%		CM_SM52  Returns the probability of error for the given%   		value of snr_in_dB, signal to noise ratio in dB.N=10000;Eb=1;d=1;				  snr=10^(snr_in_dB/10);	 	  	% signal to noise ratio per bitsgma=sqrt(Eb/(2*snr));	  	  	% noise variancephi=0;% generation of the data source followsfor i=1:N,	  temp=rand;			  	% a uniform random variable between 0 and 1  if (temp<0.5),    dsource(i)=0;  else    dsource(i)=1;  end;end;% detection and the probability of error calculationnumoferr=0;for i=1:N,  % demodulator output  if (dsource(i)==0),    r0c=sqrt(Eb)*cos(phi)+gngauss(sgma);    r0s=sqrt(Eb)*sin(phi)+gngauss(sgma);    r1c=gngauss(sgma);    r1s=gngauss(sgma);  else    r0c=gngauss(sgma);    r0s=gngauss(sgma);    r1c=sqrt(Eb)*cos(phi)+gngauss(sgma);    r1s=sqrt(Eb)*sin(phi)+gngauss(sgma);  end;  % square law detector outputs  r0=r0c^2+r0s^2;  r1=r1c^2+r1s^2;  % decision is made next  if (r0>r1),    decis=0;  else    decis=1;  end;  % Let's increment the error counter, if the decision is not correct  if (decis~=dsource(i)),    numoferr=numoferr+1;  end;end;p=numoferr/(N);		  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?