-
Notifications
You must be signed in to change notification settings - Fork 14
/
util.py
136 lines (111 loc) · 4.49 KB
/
util.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from enum import Enum
import math
import environment
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np
class EnvType (Enum):
RURAL = 0
SUBURBAN = 1
URBAN = 2
MIN_RSRP = -120 # -140 #dB
def compute_rsrp(ue, bs, env):
if bs.bs_type == "sat":
return bs.sat_eirp - bs.path_loss - bs.atm_loss - bs.ut_G_T
elif bs.bs_type == "drone_relay":
return bs.compute_rsrp_drone(ue)
else:
#lte and nr case
path_loss = compute_path_loss_cost_hata(ue, bs, env)
subcarrier_power = 0
if (bs.bs_type == "lte"):
subcarrier_power = 10*math.log10(bs.antenna_power*1000 / ((bs.total_prb/10)*bs.number_subcarriers))
else:
subcarrier_power = 10*math.log10(bs.antenna_power*1000 / ((bs.total_prb/(10*2**bs.numerology))*bs.number_subcarriers))
return subcarrier_power + bs.antenna_gain - bs.feeder_loss - path_loss
def compute_path_loss_cost_hata(ue, bs, env, save = None):
#compute distance first
dist = math.sqrt((ue.current_position[0]-bs.position[0])**2 + (ue.current_position[1]-bs.position[1])**2 + (ue.h_m - bs.h_b)**2)
if dist == 0: #just to avoid log(0) in path loss computing
dist = 0.01
#compute C_0, C_f, b(h_b), a(h_m) and C_m with the magic numbers defined by the model
if bs.carrier_frequency <= 1500 and bs.carrier_frequency >= 150 :
C_0 = 69.55
C_f = 26.16
b = 13.82*math.log10(bs.h_b)
if env.env_type == EnvType.URBAN:
C_m = 0
elif env.env_type == EnvType.SUBURBAN:
C_m = -2*((math.log10(bs.carrier_frequency/28))**2) - 5.4
else:
C_m = -4.78*((math.log10(bs.carrier_frequency))**2) + 18.33*math.log10(bs.carrier_frequency) - 40.94
else:
C_0 = 46.3
C_f = 26.16
b = 13.82*math.log10(bs.h_b)
if env.env_type == EnvType.URBAN:
C_m = 3
elif env.env_type == EnvType.SUBURBAN:
C_m = 0
else:
raise Exception("COST-HATA model is not defined for frequencies in 1500-2000MHz with RURAL environments")
if env.env_type == EnvType.SUBURBAN or env.env_type == EnvType.RURAL:
a = (1.1*math.log10(bs.carrier_frequency) - 0.7)*ue.h_m - 1.56*math.log10(bs.carrier_frequency) + 0.8
else:
if bs.carrier_frequency >= 150 and bs.carrier_frequency <= 300:
a = 8.29*(math.log10(1.54*ue.h_m)**2) - 1.1
else:
a = 3.2*(math.log10(11.75*ue.h_m)**2) - 4.97
path_loss = C_0 + C_f * math.log10(bs.carrier_frequency) - b - a + (44.9-6.55*math.log10(bs.h_b))*math.log10(dist/1000) + C_m
if (save is not None):
save = path_loss
return path_loss
def find_bs_by_id(bs_id):
return environment.wireless_environment.bs_list[bs_id]
def find_ue_by_id(ue_id):
return environment.wireless_environment.ue_list[ue_id]
run = 0
def plot(ue, bs, env):
global ax
global fig
global run
if run == 0:
plt.ion()
fig, ax = plt.subplots()
run = 1
x_ue = []
y_ue = []
x_bs = []
y_bs = []
plt.cla()
#ax.set_xlim(0, env.x_limit)
#ax.set_ylim(0, env.y_limit)
colors = cm.rainbow(np.linspace(0, 1, len(bs)))
for j in bs:
x_bs.append(find_bs_by_id(j).position[0])
y_bs.append(find_bs_by_id(j).position[1])
for i in range(0, len(ue)):
x_ue.append(find_ue_by_id(ue[i]).current_position[0])
y_ue.append(find_ue_by_id(ue[i]).current_position[1])
for i in range(0, len(ue)):
for j in range(0, len(bs)):
if find_ue_by_id(ue[i]).current_bs == j:
ax.scatter(x_ue[i], y_ue[i], color = colors[j])
break
else:
ax.scatter(x_ue[i], y_ue[i], color = "tab:grey")
for i in range(0, len(ue)):
ax.annotate(str(ue[i]), (x_ue[i], y_ue[i]))
for j in range(0, len(bs)):
if find_bs_by_id(j).bs_type == "drone_relay":
ax.scatter(x_bs[j], y_bs[j], color = colors[j], label = "BS", marker = "^", s = 400, edgecolor = colors[find_bs_by_id(j).linked_bs], linewidth = 3)
elif find_bs_by_id(j).bs_type == "drone_bs":
ax.scatter(x_bs[j], y_bs[j], color = colors[j], label = "BS", marker = "^", s = 400)
else:
ax.scatter(x_bs[j], y_bs[j], color = colors[j], label = "BS", marker = "s", s = 400)
for j in range(0, len(bs)):
ax.annotate("BS"+str(j), (x_bs[j], y_bs[j]))
ax.grid(True)
ax.set_ylabel("[m]")
ax.set_xlabel("[m]")
fig.canvas.draw()