中易网

可以具体解释一下这个matlab的m文件的每一步是干什么的吗?整体应该是二进制通信系统的Monte Carlo仿真。

答案:2  悬赏:50  
解决时间 2021-03-14 09:38
这个文件中echo on 和echo off语句,是做什么用的,为什么要echo on和echo off呢?还有log(10)/10是什么意思?
以下是需要解释的matlab的m文件:
% MATLAB script for Illustrative Problem 5.4.
echo on
SNRindB1=0:1:12;
SNRindB2=0:0.1:12;
for i=1:length(SNRindB1),
% simulated error rate
smld_err_prb(i)=smldPe54(SNRindB1(i));
echo off ;
end;
echo on ;
for i=1:length(SNRindB2),
SNR=exp(SNRindB2(i)*log(10)/10);
% theoretical error rate
theo_err_prb(i)=Qfunct(sqrt(SNR));
echo off ;
end;
echo on;
% Plotting commands follow.
semilogy(SNRindB1,smld_err_prb,'*');
hold
semilogy(SNRindB2,theo_err_prb);

以上matlab文件需要调用的函数在以下的两个matlab的m文件中:
第一个是:
function [p]=smldPe54(snr_in_dB)
% [p]=smldPe54(snr_in_dB)
% SMLDPE54 finds the probability of error for the given
% snr_in_dB, signal-to-noise ratio in dB.
E=1;
SNR=exp(snr_in_dB*log(10)/10); % signal-to-noise ratio
sgma=E/sqrt(2*SNR); % sigma, standard deviation of noise
N=10000;
% generation of the binary data source
for i=1:N,
temp=rand; % a uniform random variable over (0,1)
if (temp<0.5),
dsource(i)=0; % With probability 1/2, source output is 0.
else
dsource(i)=1; % With probability 1/2, source output is 1.
end
end;
% detection, and probability of error calculation
numoferr=0;
for i=1:N,
% matched filter outputs
if (dsource(i)==0),
r0=E+gngauss(sgma);
r1=gngauss(sgma); % if the source output is "0"
else
r0=gngauss(sgma);
r1=E+gngauss(sgma); % if the source output is "1"
end;
% Detector follows.
if (r0>r1),
decis=0; % Decision is "0".
else
decis=1; % Decision is "1".
end;
if (decis~=dsource(i)), % If it is an error, increase the error counter.
numoferr=numoferr+1;
end;
end;
p=numoferr/N; % probability of error estimate

第二个是:
function [gsrv1,gsrv2]=gngauss(m,sgma)
% [gsrv1,gsrv2]=gngauss(m,sgma)
% [gsrv1,gsrv2]=gngauss(sgma)
% [gsrv1,gsrv2]=gngauss
% GNGAUSS generates two independent Gaussian random variables with mean
% m and standard deviation sgma. If one of the input arguments is missing
% it takes the mean as 0, and the standard deviation as the given parameter.
% If neither mean nor the variance is given, it generates two standard
% Gaussian random variables.
if nargin == 0,
m=0; sgma=1;
elseif nargin == 1,
sgma=m; m=0;
end;
u=rand; % a uniform random variable in (0,1)
z=sgma*(sqrt(2*log(1/(1-u)))); % a Rayleigh distributed random variable
u=rand; % another uniform random variable in (0,1)
gsrv1=m+z*cos(2*pi*u);
gsrv2=m+z*sin(2*pi*u);
最佳答案
第二个函数用m+sigma*randn代替即可
全部回答
echo on之后会将m文件运行的代码在command window打印出来 echo off会取消回显 snr=exp(snrindb2(i)*log(10)/10);化简之后可得snr=10^(snrindb2(i)/10)也就是把对应的snrindb2中表示的db转化成线性的功率信噪比. 对应的10db对应功率的10倍;20db对应功率的100倍.
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
行乞的意思和造句
输入任意一个整数 判断它能否被5或8整除
高送转有什么用,分红才是真正好
说谎歌词吉佑社是什么意思??
为什么我身上总一股发酵的气味
车漆快修设备是电脑调漆的好,还是数码的好,是
酒店里挂着星期8是什么意思?
D N 1400m m 的热力管道焊接一米多少钱?16个
戈壁大漠的意思是什么
酷派5891通讯录怎么不见了
《恋你》的歌词万芳的
卧室门对着走廊,可以把鞋柜放走廊吗
经常感到前额无端头涨是怎么回事?
空调外机支架焊接的好还是螺丝的好?
教师职称评定,需要《山东教育》《中国教育报
推荐资讯
三百平米商铺消防应该安装,烟感和喷淋吗
有人有元祖的打折卡吗?
说一个人长得有点猥琐是什么意思
现在剑灵灵剑好还是刺客好玩
文化中路/G2(路口)在哪里啊,我有事要去这个
淘宝店书籍经营特种经营权限如何办理
我爱我家(香樟路店)在哪里啊,我有事要去这个
汽油泵压力不足 是燃油问题吗
手脚多汗该挂什么科室
autoCAD2010中 拖动图正常是按下鼠标滚轮拖动
一喝红酒胃里面热热的怎么回事
新人求助:4月初适合去西藏旅游吗,4月末回家
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?