【问题标题】:Pls convert this R code of bit error probability into matlab [closed]请将此位错误概率的R代码转换为matlab [关闭]
【发布时间】:2020-03-24 19:36:22
【问题描述】:

solution of the bit error probability problem

prob=function(E,m)        #--- prob is the estimated error probabity for given values of signal to 
                          #---noise ratio E and sample size m
{
   stopifnot(E>=0 & m>0)  #--- this says that the function won't accept negative values of E and 
                          #---m shoulde be at least 1
   n=rnorm(m)             #--- this says that n is a random sample of size m from N(0,1) 
                          #---distribution
   m=mean(n< -sqrt(E))    #--- this says that m is the proportion of values in n which are less  
                          #---than the negative root of E
   return(m)              #--- this gives us the value of m, which is the estimated error          
                          #---probability
}


E=seq(0,2,by=0.001)
sam=1000
y=sapply(E,prob,m=sam)
p=10*log10(E)

plot(p, log(y),
     main="Graph For The Error Probabilities",
     xlab=expression(10*log[10](E)),
     ylab="log(Error Probability)",
     type="l")

【问题讨论】:

    标签: r matlab signals probability-theory


    【解决方案1】:

    你可以试试下面的 MATLAB 代码

    clc;
    clear;
    close all;
    
    function y = prob(E,m)
      assert(E>=0 & m>0);
      n = randn(1,m);
      y = mean(n+sqrt(E)<0);
    end
    
    E = 0:0.001:2;
    sam = 1000;
    y = arrayfun(@(x) prob(x,sam),E);
    p = 10*log10(E);
    
    plot(p,log(y));
    title("Graph For The Error Probabilities");
    xlabel('10\log_{10}(E)');
    ylabel("log(Error Probability)");
    

    输出 (MATLAB) 输出 (R)

    【讨论】:

    • 非常感谢! :)
    • @HarshithCh 欢迎您。如果您认为我的回答有帮助,请随时点赞/接受,谢谢。
    猜你喜欢
    • 2011-07-28
    • 1970-01-01
    • 2018-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-21
    • 1970-01-01
    • 2017-10-06
    相关资源
    最近更新 更多