-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreceivers.py
383 lines (302 loc) · 10.1 KB
/
receivers.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
import numpy as np
import multiprocessing
from joblib import Parallel
from joblib import dump, load
from joblib import delayed
# Obtain the number of processors
num_cores = multiprocessing.cpu_count()
########################################
# Private functions
########################################
def block_kaczmarz(H, y_, mu, niter, order=None):
""""""
# Extract dimensions from channel matrix
M, K = H.shape
# Canonical order
canonical_order = np.arange(0, M, 1, dtype=np.int_)
# Initializations
A_ = np.eye(K, dtype=np.complex128)
W_ = np.zeros((M, K), dtype=np.complex128)
# Compute norms of the channel vectors w.r.t. antenna indexes
norms = np.linalg.norm(H, axis=1)**2
# Compute lambda vector for each antenna element
mu_vec = mu/norms
# Compute probability vector
p_ = norms/norms.sum()
# Randomization based on root indexes
root_indexes = np.random.choice(M, size=niter, replace=True, p=p_)
# Go through all iterations
for iter in range(niter):
# Check the order
if order is None:
morder = canonical_order
else:
morder = np.roll(canonical_order, shift=root_indexes[iter])
# Go through each antenna (processing) element
for m in morder:
# Compute update term
update_term = mu_vec[m] * A_ @ H[m]
# Update the receive combining vector
W_[m] += update_term
# Update A_ matrix
A_ -= np.outer(update_term, H[m].conj())
# Compute soft estimate
xhat_soft = W_.conj().T @ y_
return xhat_soft
########################################
# Public functions
########################################
def mf_receiver(H, y_):
""" Obtain soft-estimates for the matched filter (MF) receiver.
Parameters
----------
H : 3D ndarray of numpy.cdouble
Collection of channel matrices.
shape: (nchnlreal,M,K)
y_ : 2D ndarray of numpy.cdouble
Collection o received signals.
shape: (nchnlreal,M)
Returns
-------
xhat_soft : 2D ndarray of numpy.cdouble
Soft signal estimates.
shape: (nchnlreal,K)
"""
Vbar = H / (np.linalg.norm(H, axis=1)**2)[:, None, :]
xhat_soft = np.squeeze(np.matmul(Vbar.conj().transpose(0, 2, 1), y_[:, :, None]))
return xhat_soft
def zf_receiver(H, y_):
""" Obtain soft-estimates for the zero-forcing (ZF) receiver.
Parameters
----------
H : 3D ndarray of numpy.cdouble
Collection of channel matrices.
shape: (nchnlreal,M,K)
y_ : 2D ndarray of numpy.cdouble
Collection o received signals.
shape: (nchnlreal,M)
Returns
-------
xhat_soft : 2D ndarray of numpy.cdouble
Soft signal estimates.
shape: (nchnlreal,K)
"""
from numpy.dual import inv
# Compute Gramian matrix
G = np.matmul(H.conj().transpose(0, 2, 1), H)
# Compute MF soft-estimates
mf = H.conj().transpose(0, 2, 1)@y_[:, :, None]
# Compute inverses of the Gramian matrix
Ginv = inv(G)
# Compute ZF soft-estimates
xhat_soft = np.squeeze(Ginv @ mf)
return xhat_soft
def standard_distributed_kaczmarz_receiver(H, y_, SNR, mu=None, niter=1, D=None):
""" Obtain soft-estimates for the standard distributed Kaczmarz (SDK) receiver.
Parameters
----------
H : 3D ndarray of numpy.cdouble
Collection of channel matrices.
shape: (nchnlreal,M,K)
y_ : 2D ndarray of numpy.cdouble
Collection o received signals.
shape: (nchnlreal,M)
SNR : float
Signal-to-noise ratio.
mu : str
Relaxation parameter.
None - mu = 1
'previous' - previous
'proposed' - proposed
Returns
-------
xhat_soft : 2D ndarray of numpy.cdouble
Soft signal estimates.
shape: (nchnlreal,K)
"""
# Extract dimensions from channel matrix
nchnlreal, M, K = H.shape
# Check mu input
if mu is None:
mu_cons = 1.0
elif mu is 'previous':
mu_cons = 0.5*(K/M)*np.log(4*M*SNR)
# Prepare to store the soft estimates
xhat_soft = np.zeros((nchnlreal, K), dtype=np.complex128)
# Go through all channel realizations
for n in range(nchnlreal):
# Initialization
x_ = np.zeros((2, K), dtype=np.complex128)
# Compute channel norms for each node
mu_norm = np.reciprocal(np.linalg.norm(H[n], axis=1)**2)
user_indexes = np.ones(K, dtype=np.complex128)
# Go through all iterations
for iter in range(niter):
# Go through each node
for m in range(M):
if mu is 'proposed':
num = K*SNR
den = (iter+1)*(m+1)
mu_cons = np.min([np.sqrt(num/den), 1])
# New is old
x_[0] = x_[1].copy()
# Compute the residual
residual = y_[n, m] - np.inner(H[n, m], x_[0])
# Update the soft estimates
x_[1] = x_[0] + mu_cons * mu_norm[m] * H[n, m].conj() * (y_[n, m] - np.inner(H[n, m], x_[0]))
# Compute soft estimate
xhat_soft[n] = x_[1]
return xhat_soft
def bayesian_distributed_kaczmarz_receiver(H, y_, SNR, mu=None, niter=1):
""" Obtain soft-estimates for the Bayesian distributed Kaczmarz (BDK) receiver.
Parameters
----------
H : 3D ndarray of numpy.cdouble
Collection of channel matrices.
shape: (nchnlreal,M,K)
y_ : 2D ndarray of numpy.cdouble
Collection o received signals.
shape: (nchnlreal,M)
SNR : float
Signal-to-noise ratio.
mu : str
Relaxation parameter.
None - mu = 1
'proposed' - proposed
Returns
-------
xhat_soft : 2D ndarray of numpy.cdouble
Soft signal estimates.
shape: (nchnlreal,K)
"""
# Extract dimensions from channel matrix
nchnlreal, M, K = H.shape
# Check mu input
if mu is None:
mu_cons = 1.0
elif mu is 'previous':
mu_cons = 0.5*(K/M)*np.log(4*M*SNR)
# Compute inverse of the SNR
xi = 1/SNR
# Store soft estimate
xhat_soft = np.zeros((nchnlreal, K), dtype=np.complex128)
# Go through each channel realization
for n in range(nchnlreal):
# Initializations
x_ = np.zeros((2, K), dtype=np.complex128)
n_ = np.zeros((2, M), dtype=np.complex128)
# Compute lambda vector for each antenna element
mu_norm = np.reciprocal(np.linalg.norm(H[n], axis=1)**2 + xi)
# Go through all iterations
for iter in range(niter):
# Go through each antenna (processing) element
for m in range(M):
if mu is 'proposed':
mu_cons = np.sqrt((K*SNR+M)/((niter+1)*(m+1)))
# New is old
x_[0] = x_[1].copy()
n_[0] = n_[1].copy()
# Compute the residual
residual = y_[n, m] - np.inner(H[n, m], x_[0]) - np.sqrt(xi)*n_[0, m]
# Update soft estimate
x_[1] = x_[0] + mu_cons * mu_norm[m] * H[n, m].conj() * residual
# Update noise estimate
n_[1, m] = n_[0, m] + mu_cons * mu_norm[m] * np.sqrt(xi) * residual
# Get final soft estimates
xhat_soft[n] = x_[1]
return xhat_soft
# def distributed_kaczmarz_receiver(H, y_, SNR, mu=None, niter=1):
# """ """
#
# # Extract dimensions from channel matrix
# nchnlreal, M, K = H.shape
#
# # Check if we have to use the optimum value
# if mu is None:
# mu = 0.5*(K/M)*np.log(4*M*SNR)
#
# with Parallel(n_jobs=num_cores) as parl:
# xhat_soft_raw = parl(delayed(block_kaczmarz)(H[n], y_[n], mu, niter) for n in range(nchnlreal))
#
# # Store soft estimate
# xhat_soft = np.array(xhat_soft_raw)
#
# return xhat_soft
# def randomized_kaczmarz_receiver(H, y_, SNR, mu=None, niter=1):
# """ """
#
# # Extract dimensions from channel matrix
# nchnlreal, M, K = H.shape
#
# # Check if we have to use the optimum value
# if mu is None:
# mu = 0.5*(K/M)*np.log(4*M*SNR)
#
# with Parallel(n_jobs=num_cores) as parl:
# xhat_soft_raw = parl(delayed(block_kaczmarz)(H[n], y_[n], mu, niter, order=1) for n in range(nchnlreal))
#
# # Store soft estimate
# xhat_soft = np.array(xhat_soft_raw)
#
# return xhat_soft
# def rzf_receiver(SNR, H, G, y_):
# """ Obtain regularized zero-forcing (RZF) soft signal estimates. Raw signal
# estimates are outputted for comparison with methods that emulate the RZF
# scheme. Soft normalization matrix Dinv is also outputted.
#
# Parameters
# ----------
# SNR : float
# Signal-to-noise-ratio in power units.
#
# H : 3D ndarray of numpy.cdouble
# Collection of channel matrices.
# shape: (nchnlreal,M,K)
#
# G : 3D ndarray of numpy.cdouble
# Collection of channel Gramian matrices.
# shape: (nchnlreal,K,K)
#
# y_ : 2D ndarray of numpy.cdouble
# Collection o received signals.
# shape: (nchnlreal,M)
#
# Returns
# -------
# xhat_soft : 1D ndarray of numpy.cdouble
# Soft signal estimates.
# shape: (nchnlreal,K)
#
# xhat : 1D ndarray of numpy.cdouble
# Raw signal estimates.
# shape: (nchnlreal,K)
#
# Dinv : 2D ndarray of numpy.cdouble
# Soft power normalization.
# shape: (nchnlreal,K)
# """
# from numpy.dual import inv
#
# nchnlreal, M, K = H.shape
#
# # Constants
# xi = 1/SNR
# eyeK = np.eye(K)
#
# # Store inverted covariance of the received signal
# Ryy_inv = inv(G + (xi*eyeK)[None, :, :])
#
# # Compute receive combining matrices
# V = np.matmul(H, Ryy_inv)
#
# # Store norm of RZF receive combining
# D = np.diagonal(np.matmul(Ryy_inv, G), axis1=1, axis2=2)
# Dinv = np.reciprocal(D)
#
# # Get RZF signal estimates
# xhat = np.squeeze(np.matmul(V.conj().transpose(0, 2, 1), y_[:, :, None]))
#
# # Get soft RZF signal estimates
# xhat_soft = Dinv*xhat
#
# return xhat_soft, xhat, Dinv