首页 > 解决方案 > 请将此位错误概率的R代码转换为matlab

问题描述

误码概率问题的解

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")

标签: rmatlabsignalsprobability-theory

解决方案


你可以试试下面的 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)在此处输入图像描述 在此处输入图像描述


推荐阅读