pdftest.m

来自「802.16的信道建模和仿真」· M 代码 · 共 40 行

M
40
字号
function pdftest(r,nbins,type,mu,sigma)
% default:fit the rayleigh distribution
%type=1:Rayleigh
%type=2:Normal
%type=3:Uniform

if nargin==2
    type=1;
    mu=0;
    sigma=1;
end

%calculate the histogram 
h=hist(r,nbins);
ma=max(r);
mi=min(r);
% Finds the range of this data
range=ma-mi;
% Finds the width of each bin.
binwidth = range/nbins; 
% the horizontal coordinate
x=mi:binwidth:ma-binwidth;
%plot pdf of r
Ns=length(r);
pdf=h/Ns/binwidth;
figure;
stem(x,pdf);
hold on;
grid on;
if (type==1)
    %fit the rayleigh distribution
    %p=raylpdf(x, sqrt(2)/2);
    p=raylpdf(x ,sigma);
elseif (type==2)
    %fit the normal distribution
    p=normpdf(x,mu,sigma);
else
    p=1/(2*pi)*ones(size(x));
end
plot(x,p,'r');

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?