-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtpe.py
236 lines (171 loc) · 5.89 KB
/
tpe.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
########################################
# tpe.py
#
# Description. Set of functions related to the implementation of TPE receiver.
#
# Author. @victorcroisfelt
#
# Date. May 21, 2021
#
# This code is part of the code package used to generate the results of the
# paper:
#
# V. C. Rodrigues, A. Amiri, T. Abrao, E. D. Carvalho and P. Popovski,
# "Accelerated Randomized Methods for Receiver Design in Extra-Large Scale
# MIMO Arrays," in IEEE Transactions on Vehicular Technology,
# doi: 10.1109/TVT.2021.3082520.
#
# Available on: https://ieeexplore.ieee.org/document/9437708
########################################
########################################
# Preamble
########################################
import numpy as np
import math
########################################
# Private functions
########################################
def nCk(n, k):
return math.factorial(n) // math.factorial(k) // math.factorial(n - k)
########################################
# Public functions
########################################
def tpe_detection_optz(SNR, H, G, y_, Dinv, Jrange):
""" Implementation of the optimal TPE receiver.
Parameters
----------
SNR : float
Signal-to-noise ratio.
H : 3D ndarray of numpy.cdouble
Collection of channel matrix.
shape: (nchnlreal,M,K)
G : 3D ndarray of numpy.cdouble
Collection of Gramian matrix.
shape: (nchnlreal,K,K)
y_ : 2D ndarray of numpy.cdouble
Collection of received signals.
shape: (nchnlreal,M)
Dinv : 3D ndarray of numpy.cdouble
Collection of re-scaling matrices.
shape: (nchnlreal,K,K)
Jrange : 1D ndarray of integers
Parameter J of TPE.
Returns
-------
xhat_soft : 2D ndarray of numpy.cdouble
Collection of soft estimates.
shape: (nchnlreal, K)
"""
# Extract dimensionns
nchnlreal, M, K = H.shape
# Compute inverse of the SNR
xi = 1/SNR
# Extract eigenvalues from the Gramian matrix
W_, _ = np.linalg.eig(G)
# Compute alpha_opt
alpha_opt = 2/(W_[:, 0] + W_[:, -1] + 2*xi)
# Compute MR estimates
yMR = np.squeeze(np.matmul(H.conj().transpose(0, 2, 1), y_[:, :, None]))
# Prepare to obtain the estimated symbols
xhat = alpha_opt[:, None] * yMR.copy()
# Go through all channel realizations
for real in range(nchnlreal):
# Go through each iteration
for j in range(Jrange):
#Store X matrix
X_ = np.eye(K) - alpha_opt[real] * (G[real] + xi*np.eye(K))
# Compute a new approximation
xhat[real] = alpha_opt[real] * yMR[real] + X_ @ xhat[real]
# Rescale the power
xhat_soft = Dinv*xhat
return xhat_soft
def tpe_detection(SNR, H, G, y_, Dinv, niter_range=None, maxiter=None):
""" Implementation of the canonical RPE.
Parameters
----------
SNR : float
Signal-to-noise ratio.
H : 3D ndarray of numpy.cdouble
Collection of channel matrix.
shape: (nchnlreal,M,K)
G : 3D ndarray of numpy.cdouble
Collection of Gramian matrix.
shape: (nchnlreal,K,K)
y_ : 2D ndarray of numpy.cdouble
Collection of received signals.
shape: (nchnlreal,M)
Dinv : 3D ndarray of numpy.cdouble
Collection of re-scaling matrices.
shape: (nchnlreal,K,K)
niter_range : 1D ndarray of integers
Number of iterations.
maxiter : 1D ndarray of integers
Maximum number of iterations.
Returns
-------
xhat_soft : 2D ndarray of numpy.cdouble
Collection of soft estimates.
shape: (nchnlreal, K)
"""
# Extract dimensionns
nchnlreal, M, K = H.shape
# Compute inverse of the SNR
xi = 1/SNR
# Check entries
if maxiter is None:
# Length of the range of the number of iterations
len_niter = len(niter_range)
# Extract maxiter
maxiter = niter_range[-1]
# Define an arbitrarily small number
epsilon = 1e-6
# Compute the row sum of the Gramian matrix
rowSums = np.abs(G).sum(axis=2)
# Estimate the max and min eigenvalues
lambdaHat_max = rowSums.max(axis=1)
lambdaHat_min = np.maximum((np.diagonal(G, axis1=1, axis2=2) - rowSums).min(axis=1), epsilon)
# Estimated alpha
alpha_est = 2/(lambdaHat_max + lambdaHat_min + 2*xi)
# Compute MR estimates
yMR = np.squeeze(np.matmul(H.conj().transpose(0, 2, 1), y_[:, :, None]))
# Prepare to save soft estimates
if niter_range is None:
xhat = np.empty((nchnlreal, K), dtype=np.cdouble)
else:
xhat = np.empty((len_niter, nchnlreal, K), dtype=np.cdouble)
# Go through all channel realizations
for real in range(nchnlreal):
# Start number of iterations counter
t = 0
# Initialize the estimated symbols
x_ = alpha_est[real, None] * yMR[real]
#Store X matrix
X_ = np.eye(K) - alpha_est[real] * (G[real] + xi*np.eye(K))
# Iterative process
while True:
# Compute a new approximation
x_ = alpha_est[real] * yMR[real] + X_ @ x_
# Update iteration counter
t += 1
if niter_range is None:
# Check maxiter
if t == maxiter:
# Save result
xhat[real] = x_.copy()
break
else:
# Check condition
if np.sum(t == niter_range) > 0:
# Get the index from niter_range
index = np.where(t == niter_range)[0][0]
# Save result
xhat[index, real] = x_.copy()
# Check maxiter
if t == maxiter:
break
if niter_range is None:
# Rescale the power
xhat_soft = Dinv*xhat
else:
xhat_soft = Dinv[None, :, :]*xhat
return xhat_soft