-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplot_fig04_nmd_prob.py
261 lines (178 loc) · 6.8 KB
/
plot_fig04_nmd_prob.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
########################################
# plot_fig04a_nmd.py
#
# Description. Script used to plot Fig. 4 of the paper.
#
# Author. @victorcroisfelt
#
# Date. December 27, 2021
#
# This code is part of the code package used to generate the numeric results
# of the paper:
#
# Croisfelt, V., Abrão, T., and Marinello, J. C., “User-Centric Perspective in
# Random Access Cell-Free Aided by Spatial Separability”, arXiv e-prints, 2021.
#
# Available on:
#
# https://arxiv.org/abs/2107.10294
#
########################################
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import time
import warnings
########################################
# Preamble
########################################
# Comment the line below to see possible warnings related to python version
# issues
warnings.filterwarnings("ignore")
np.random.seed(42)
axis_font = {'size':'12'}
plt.rcParams.update({'font.size': 12})
matplotlib.rc('xtick', labelsize=12)
matplotlib.rc('ytick', labelsize=12)
matplotlib.rc('text', usetex=True)
matplotlib.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"]
########################################
# System parameters
########################################
# Define number of APs
L = 64
# Define number of antennas per AP
N = 8
# UL transmit power
p = 100
# DL transmit power per AP
ql = 200/L
# Define noise power
sigma2 = 1
# Number of RA pilot signals
taup = 5
########################################
# Geometry
########################################
# Define square length
squareLength = 400
# Create square grid of APs
APperdim = int(np.sqrt(L))
APpositions = np.linspace(squareLength/APperdim, squareLength, APperdim) - squareLength/APperdim/2
APpositions = APpositions + 1j*APpositions[:, None]
APpositions = APpositions.reshape(L)
########################################
# SUCRe parameters
########################################
# Probability of access
pA = 0.001
########################################
# Simulation parameters
########################################
# Set the number of RA blocks
numRAblocks = 100
# Range of collision sizes
collisions = np.arange(1, 11)
# Range of maximum number of pilot-serving APs
Lmax_range = np.arange(1, L+1)
########################################
# Simulation
########################################
print("--------------------------------------------------")
print("Fig. 04: NMD and average probability")
print("--------------------------------------------------\n")
# Store total time
total_time = time.time()
# Store enumeration of L
enumerationL = np.arange(L)
# Prepare to save simulation results
nmd = np.zeros((collisions.size, Lmax_range.size, numRAblocks))
probability = np.zeros((collisions.size, Lmax_range.size, numRAblocks))
#####
# Generate noise realizations at APs
n_ = np.sqrt(sigma2/2)*(np.random.randn(numRAblocks, N, L) + 1j*np.random.randn(numRAblocks, N, L))
# Go through all collision sizes
for cs, collisionSize in enumerate(collisions):
# Storing time
timer_start = time.time()
# Print out current data point
print(f"\tcollision: {cs}/{collisions.size-1}")
# Generate normalized channel matrix for each AP equipped with N antennas
Gnorm_ = np.sqrt(1/2)*(np.random.randn(numRAblocks, N, collisionSize, L) + 1j*np.random.randn(numRAblocks, N, collisionSize, L))
# Go through all RA blocks
for rr in range(numRAblocks):
#####
# Generating UEs
#####
# Generate UEs locations
UElocations = squareLength*(np.random.rand(collisionSize) + 1j*np.random.rand(collisionSize))
# Compute UEs distances to each AP
UEdistance = abs(APpositions - UElocations[:, None])
# Compute average channel gains according to Eq. (1)
betas = 10**((94.0 - 30.5 - 36.7 * np.log10(np.sqrt(UEdistance**2 + 10**2)))/10)
# Randomize which pilot each UE chose
pilotSelections = np.random.randint(1, taup+1, size=collisionSize);
pilotSelections += -1
# Generate channel matrix for each AP equipped with N antennas
G_ = np.sqrt(betas[None, :, :]) * Gnorm_[rr, :, :, :]
# Compute received signal according to Eq. (4)
Yt_ = np.sqrt(p * taup) * np.sum(G_, axis=1) + n_[rr, :, :]
# Store l2-norms of Yt
Yt_norms = np.linalg.norm(Yt_, axis=0)
# Obtain pilot activity vector according to Eq. (8)
atilde_t = (1/N) * Yt_norms**2
atilde_t[atilde_t < sigma2] = 0.0
# Prepare to store sum over the sets of nearby APs
sum_checkCcal = np.zeros(collisionSize)
# Go through all colliding UEs
for k in range(collisionSize):
# Obtain natural set of nearby APs of UE k (Definition 1)
checkCcal = enumerationL[ql * betas[k, :] > sigma2]
if len(checkCcal) == 0:
checkCcal = np.array([np.argmax(ql * betas[k, :])])
# Calculate sum of betas over natural set of nearby APs of UE k
sum_checkCcal[k] = np.sum(betas[k, checkCcal])
# Go through all different values of Lmax
for ll, Lmax in enumerate(Lmax_range):
# Obtain set of pilot-serving APs (Definition 2)
Pcal = np.argsort(atilde_t)[-Lmax:]
Pcal = np.delete(Pcal, atilde_t[Pcal] == 0)
# Calculate sum of betas over set of pilot-serving APs
sum_Pcal = np.sum(betas[k, Pcal])
# Store results
nmd[cs, ll, rr] = np.mean(sum_checkCcal - sum_Pcal)/sum_Pcal
probability[cs, ll, rr] = np.mean(sum_Pcal > sum_checkCcal)
print('\t[collision] elapsed ' + str(np.round(time.time() - timer_start, 4)) + ' seconds.\n')
# Calculate averages
avg_nmd = np.mean(nmd, axis=-1)
avg_probability = np.mean(probability, axis=-1)
print("total simulation time was " + str(np.round(time.time() - total_time, 4)) + " seconds.\n")
print("wait for the plots...\n")
########################################
# Plot
########################################
# NMD
fig = plt.figure(figsize=(3.15,3))
ax = fig.gca(projection="3d")
X_, Y_ = np.meshgrid(Lmax_range, collisions)
ax.plot_surface(X_, Y_, np.sign(avg_nmd)*np.log10(1+np.abs(avg_nmd)))
ax.set_xlabel("$L^{\max}$")
ax.set_ylabel("$|\mathcal{S}_t|$")
ax.set_zlabel(r"transformed $\overline{\mathrm{NMD}}$")
ax.set_xticks([0, 16, 32, 48, 64])
ax.set_yticks([1, 2, 4, 6, 8, 10])
ax.view_init(elev=20, azim=-45)
plt.show()
# Probability
fig = plt.figure(figsize=(3.15,3))
ax = fig.gca(projection="3d")
X_, Y_ = np.meshgrid(Lmax_range, collisions)
ax.plot_surface(X_, Y_, avg_probability)
ax.set_xlabel("$L^{\max}$")
ax.set_ylabel("$|\mathcal{S}_t|$")
ax.set_zlabel(r"average probability")
ax.set_xticks([0, 16, 32, 48, 64])
ax.set_yticks([1, 2, 4, 6, 8, 10])
ax.view_init(elev=30, azim=-135)
plt.show()
print("------------------- all done :) ------------------")