|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
clc;clear;
p = exp(1);
N = 10000;
for n = 1:N
U(n) = n*p-fix(n*p);
end
E = sum(U)/N
E2 = sum(U.^2)/N;
V = E2-E^2
lanmuda = 0.5;
Z = 0:1:30;
E_theory = lanmuda.*exp(-lanmuda.*Z);
figure(1)
plot(Z,E_theory,'b-');
hold on;
E = (-1./lanmuda).*log(U);
m1 = max(Z);
m2 = min(Z);
NE = 100;
ms = (m1-m2)/NE;
VE = m2:ms:m1;
for i = 1:length(VE)-1
PE(i) = length(find(E<=VE(i+1) & E>VE(i)))/ms/N;
end
plot(VE(1:NE),PE,'ro')
clear;clc;
p = pi;
e = exp(1);
N = 100000;
for n = 1:N
U1(n) = n*p-fix(n*p);
U2(n) = n*e-fix(n*e);
end
sigma = 1;
X = sqrt(-2.*sigma.^2.*log(U1)).*cos(2.*pi.*U2);
Y = sqrt(-2.*sigma.^2.*log(U1)).*sin(2.*pi.*U2);
m1 = 5;
m2 = -5;
NG = 500;
ms = (m1-m2)/NG;
VG = m2:ms:m1;
for i = 1:length(VG)-1
PX(i) = length(find(X<=VG(i+1) & X>VG(i)))/ms/N;
PY(i) = length(find(Y<=VG(i+1) & Y>VG(i)))/ms/N;
end
G_theory = normpdf(VG,0,1);
figure(2)
plot(VG(1:NG),PX,'ro')
hold on
plot(VG(1:NG),G_theory(1:NG),'b-')
figure(3)
plot(VG(1:NG),PY,'ro')
hold on
plot(VG(1:NG),G_theory(1:NG),'b-')
R = sqrt(X.^2+Y.^2);
m1 = 5;
m2 = 0;
NR = 400;
ms = (m1-m2)/NR;
VR = m2:ms:m1;
for i = 1:length(VR)-1
PR(i) = length(find(R<=VR(i+1) & R>VR(i)))/ms/N;
end
figure(4)
plot(VR(1:NR),PR,'ro')
hold on
R_theory = raylpdf(VR,1);
plot(VR(1:NR),R_theory(1:NR),'b-')
Kdb = 7;
Mi = 1;
K = 10^(Kdb/10);
const = 1/(2*(K+1));
r = sqrt(const*((X+sqrt(2*K)).^2+ Y.^2));
rt = zeros(1,Mi*length(r));
ki = 1;
for i = 1:length(r)
rt(ki:i*Mi) = r(i);
ki = ki+Mi;
end
r = rt;
RdB = 20*log10(r);
Rt = [min(RdB):max(RdB)];
for m = 1:length(Rt)
fade = find(RdB<Rt(m));
Nm = length(fade);
AF(m) = Nm/N;
end
figure(5)
semilogy(Rt,AF,'k-o');
grid;
rt = [min(r):0.1:max(r)];
for m = 2:length(rt)
fr = find(r<rt(m)&r>=rt(m-1));
Nm = length(fr);
PDF(m) = Nm/N;
end
figure(6)
plot(rt,PDF,'k-o');
grid; |
|