-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdrop_rand.m
37 lines (31 loc) · 900 Bytes
/
drop_rand.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function [] = drop_rand()
global P;
global Users;
for u = 1:P.nums
a = rand()*2*pi; % 随机生成角度 a∈(0,2*pi)
if (a > pi/3 && a < 2*pi/3) || (a > 4*pi/3 && a < 5*pi/3)
angle = a - pi/3;
elseif (a > 2*pi/3 && a < pi) || (a > 5*pi/3 && a < 2*pi)
angle = a - 2*pi/3;
else
angle = a;
end
border = sqrt(3)*P.cell_radius / (2*sin(pi/3 + angle)); % 六边形边界
while 1
dist = rand()*abs(border); % 距离 m
if dist > 35 % 避免灯下黑
break
end
end
pathloss = 128.1 + 37.6 * log10(dist / 1000); % 路损 dB
h = deal(0); % Nr x Nt
for i = 1:P.Nt
h(i) = exp(1i*sin(a - 2*pi*(i-1)/P.Nt));
end
Users(u).ang = a;
Users(u).h = h.'; % Nt x Nr
Users(u).dist = dist;
Users(u).coor = dist*exp(1i*a); % 坐标
Users(u).pathloss = 10^(-0.1*pathloss); % dB2lin
end
end