rho_b2=0:0.1:35
for i=1:length(rho_b1)
smlid_err_prb(i)=ssfh_Pe(rho_b1(i))
end
for i=1:length(rho_b2)
temp=10^(rho_b2(i)/10)
if(temp>2)
theo_err_rate(i)=1/(exp(1)*temp)
else
theo_err_rate(i)=(1/2)*exp(-temp/2)
end
end
semilogy(rho_b1,smlid_err_prb,'k*',rho_b2,theo_err_rate,'k-)
在程序中调用了ssfh_Pe子函数,程序如下:
function[p]=ssfh_Pe(tho_in_dB)
rho=10^(rho_in_dB/10)
Eb=rho
if(rho>2) alpa=2/rho
else alpa=1
end
agma=sqrt(1/(2*alpha))
N=10000
for i=1:N
temp=rand
if(temp<0.5)data(i)=1
else data(i)=0
end
end
for i=1:N
if(data(i)==0)
rlc(i)=sqrt(Eb)rls(i)=0r2c(i)=0r2s(i)=0
else
rlc(i)=0rls(i)=0r2c(i)=sqrt(Eb)r2s(i)=0
end
if(rand<alpha)
rlc(i)=rlc(i)+gngauss(sgma)
rls(i)=rls(i)+gngauss(sgma)
r2c(i)=r2c(i)+gngauss(sgma)
r2s(i)=r2s(i)+gngauss(sgma)
end
end
num_of_err=0
for i=1:N
r1=rlc(i)^2+rls(i)^2
r2=r2c(i)^2+r2s(i)^2
if(r1>r2)decis=0
else decis=1
end
if(decis~=data(i))
num_off_eff=num_of_err+1
end
end
p=num_of_err/N
其中高斯分布随机变量函数gngauss程序如下
function[gsrv1,gsrv2]=gngauss(n,sgma)
if nargin==0,
m=0sgma=1
elseif nargin==1,
sgma=mm=0
end
u=rand
z=sgma*(sqrt(2*log(1/(1-u))))
u=rand
gsrv1=m+z*cos(2*pi*u)
gsrv2=m+z*sin(2*pi*u)
1.WGN:产生高斯白噪声y=wgn(m,n,p)产生一个m行n列的高斯白噪声的矩阵,p以dBW为单位指定输出噪声的强度。y=wgn(m,n,p,imp)以欧姆(Ohm)为单位指定负载阻抗。y=wgn(m,n,p,imp,state)重置RANDN的状态。通过加入循环,判断可以实现。不然只能修改inputdlg源代码,
while 1
%对话框
prompt = {'Enter matrix size:','Enter colormap name:'}
dlg_title = 'Input for peaks function'
num_lines = 1
def = {'20','hsv'}
answer = inputdlg(prompt,dlg_title,num_lines,def)
%判断
reply = input('是否继续运行?若继续运行,请直接回车 Y/N [Y]: ', 's')
if isempty(reply)
reply = 'Y'%不输入,按或回车也是继续运行
end
if strcmp('N',reply)||strcmp('n',reply)
disp('您输入了N或n,运行结束')
break
end
end
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)