N=1000000 %Number of samples to generate
variance = 1% Variance of underlying Gaussian random variables
%---------------------------------------
%Independent Gaussian random variables with zero mean and unit variance
x = randn(1, N)
y = randn(1, N)
%Rayleigh fading envelope with the desired variance
r = sqrt(variance*(x.^2 + y.^2))
%Define bin steps and range for histogram plotting
step = 0.1range = 0:step:5
%Get histogram values and approximate it to get the pdf curve
h = hist(r, range)
approxPDF = h/(step*sum(h))%Simulated PDF from the x and y samples
%Theoritical PDF from the Rayleigh Fading equation
theoretical = (range/variance).*exp(-range.^2/(2*variance))
plot(range, approxPDF,'b*'耐吵, range, theoretical,'r')
title('方差1.0时瑞利悔亩巧概率密度函数仿真值和理论值')
legend('概率密度仿真碧键值','概率密度函数理论值')
xlabel('r')
ylabel('P(r)')
grid
%PDF of phase of the Rayleigh envelope
theta = atan(y./x)
figure(2)
hist(theta)%Plot histogram of the phase part
%Approximate the histogram of the phase part to a nice PDF curve
[counts,range] = hist(theta,100)
step=range(2)-range(1)
approxPDF = counts/(step*sum(counts))%Simulated PDF from the x and y samples
bar(range, approxPDF,'b')
hold on
plotHandle=plot(range, approxPDF,'r')
set(plotHandle,'LineWidth',3.5)
axis([-2 2 0 max(approxPDF)+0.2])
hold off
title('瑞利概率密度函数相位分布仿真 ')
xlabel('\theta ')
ylabel('P(\theta)')
grid
“P1取值范围0~0.1,服从正态分布?”正态分布应该有两个参数(均值和方差)决定,范围很谈枣难说,理论上什么值都可能,只是概率比较小。瑞利分布缺大也存伏侍竖在类似问题。
正态分布用randn或normrnd;
瑞利分布用函数raylrnd;
均匀分布用函数rand或unifrnd。
直接把密度分布腔歼的函颂基数套进去填参数
s=sigma^2
选点野圆谨
x=0:0.01:5
f= x/s.*exp(-x.^2/s)
plot(x,f)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)