可以具体解释一下这个matlab的m文件的每一步是干什么的吗?整体应该是二进制通信系统的Monte Carlo仿真。
这个文件中echoon和echooff语句,是做什么用的,为什么要echoon和echooff呢?还有log(10)/10是什么意思?以下是需要解释的matlab的m文件...
这个文件中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); 展开
以下是需要解释的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); 展开
展开全部
为什么要echo on和echo off呢?还有log(10)/10是什么意思?
echo on是把命令转成脚本文件。
echo off是关闭转换
log(10)/10应该是求以10为底的对数吧,不过好像没写对
我也是菜鸟,共勉
echo on是把命令转成脚本文件。
echo off是关闭转换
log(10)/10应该是求以10为底的对数吧,不过好像没写对
我也是菜鸟,共勉
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
程序跑不完啊。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询