-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsim_figure7.py
203 lines (145 loc) · 6.34 KB
/
sim_figure7.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
import numpy as np
from tqdm import tqdm
from scipy.constants import speed_of_light
from scipy.stats.distributions import chi2
from src.channel import generate_channel_realizations, scenario, drop_ues
from src.ris import pow_ris_config_codebook, ris_rx_chest_with_choice
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
# Set random seed
np.random.seed(42)
##################################################
# BS Parameters
##################################################
# Number of BS antennas
M = 64
##################################################
# HRIS Parameters
##################################################
# Number of RIS elements
N = 32
##################################################
# UE Parameters
##################################################
# Number of UEs
K = 4
# Transmit power; 0 dBm
P_ue = 10 ** ((0 - 30) / 10)
##################################################
# System Parameters
##################################################
# Number of pilots
n_pilots = K
# Number of pilot subblocks
n_pilot_subblocks = 16
##################################################
# Scenario Parameters
##################################################
# Physical parameters
freq = 28 * 10 ** 9
wavelength = speed_of_light / freq
# NLoS variances
sigma2_dr = 0.1 * 9.08 * 1e-7
sigma2_rr = 0.1 * 1.11 * 1e-6
# Noise power
sigma2_n_bs = 10 ** ((-94 - 30) / 10)
sigma2_n_hris = 10 ** ((-91 - 30) / 10)
# Generate scenario
pos_bs, pos_bs_els, pos_ris, pos_ris_els, bs_ris_channels, ris_bs_steering, guard_distance_ris = scenario(wavelength, M, N)
##################################################
# Simulation Parameters
##################################################
# Define number of setups
n_setups = 100
# Define number of channel realizations
n_channels = 100
# Define number of noise realizations
n_noise = 100
# Number of pilot subbblocks for probe
n_pilot_subblocks_probe_range = np.arange(1, n_pilot_subblocks + 1)
n_probe = len(n_pilot_subblocks_probe_range)
# Range of HRIS reflection parameter
eta_range = np.array([0.9, 0.99, 0.999, 0.9999])
n_etas = len(eta_range)
# Define probability of false alarm
proba_false_alarm_range = np.array([0.01, 0.001])
n_probas = len(proba_false_alarm_range)
##################################################
# Simulation
##################################################
# Prepare to save simulation results
pd_proba_detection = np.zeros((n_probe, n_etas, n_probas))
dsp_proba_detection = np.zeros((n_probe, n_etas, n_probas))
# Drop the UEs over the area of interest
pos_ues = drop_ues(n_setups, pos_ris, dmax=1000, guard_distance_ris=900)
# Generate UE channels
bs_ue_channels, ris_ue_channels = generate_channel_realizations(wavelength, pos_bs, pos_bs_els, pos_ris, pos_ris_els, pos_ues, sigma2_dr, sigma2_rr, n_channels)
# Generate UE's choice
ue_choice = np.random.rand(n_setups)
# Get mask
mask = ue_choice > 0.5
# Convert into True and False
ue_choice[mask] = True
ue_choice[~mask] = False
#
# Generate signals
#
# Go through all possible values for C
for cc, n_pilot_subblocks_probe in tqdm(enumerate(n_pilot_subblocks_probe_range), total=n_pilot_subblocks):
# Generate power-RIS configuration codebook
pow_probe_configs = pow_ris_config_codebook(wavelength, n_pilot_subblocks_probe, pos_ris, pos_ris_els)
# Go through all values of eta
for ee in range(n_etas):
# Get current value of eta
eta = eta_range[ee]
# Go through noise realizations
for nn in range(n_noise):
# Compute received pilot signals
pow_ris_rx_chest = ris_rx_chest_with_choice(eta, P_ue, n_pilots, sigma2_n_hris, n_pilot_subblocks_probe, ris_ue_channels, mask, pow_probe_configs)
sig_ris_rx_chest = ris_rx_chest_with_choice(eta, P_ue, n_pilots, sigma2_n_hris, n_pilot_subblocks_probe, ris_ue_channels, mask)
#
# PD-based HRIS probe
#
# Compute measured power
pow_test = np.abs(pow_ris_rx_chest)**2
pow_test = pow_test.max(axis=0)
#
# DSP-based HRIS probe
#
# Compute test
sig_test = np.linalg.norm(sig_ris_rx_chest, axis=0)**2
sig_test *= 2 * n_pilot_subblocks_probe / n_pilots / sigma2_n_hris
# Go through all false alarm probabilities
for pp in range(n_probas):
# Get current value of eta
proba_false_alarm = proba_false_alarm_range[pp]
#
# PD-based HRIS probe
#
# Compute threshold
pow_threshold = - (2 * N * sigma2_n_hris) * np.log(proba_false_alarm)
# Perform test
pow_detected_ues = pow_test > pow_threshold
# Estimate probability of detection
pd_proba_detection_curr = (ue_choice == pow_detected_ues)
# Store results
pd_proba_detection[cc, ee, pp] += np.mean(pd_proba_detection_curr)
#
# DSP-based HRIS probe
#
# Get threshold value
sig_threshold = chi2.ppf((1 - proba_false_alarm), df=2*N)
# Perform test
sig_detected_ues = sig_test > sig_threshold
# Estimate probability of detection
dsp_proba_detection_curr = (ue_choice == sig_detected_ues)
# Store results
dsp_proba_detection[cc, ee, pp] += np.mean(dsp_proba_detection_curr)
np.savez('data/figure7.npz',
n_pilot_subblocks=n_pilot_subblocks,
n_pilot_subblocks_probe_range=n_pilot_subblocks_probe_range,
eta_range=eta_range,
proba_false_alarm_range=proba_false_alarm_range,
pd_proba_detection=pd_proba_detection,
dsp_proba_detection=dsp_proba_detection
)