|
23 | 23 | import matplotlib.pyplot as plt |
24 | 24 | from commpy.utilities import bitarray2dec, dec2bitarray |
25 | 25 | from numpy import arange, array, zeros, pi, cos, sin, sqrt, log2, argmin, \ |
26 | | - hstack, repeat, tile, dot, sum, shape, concatenate, exp, \ |
| 26 | + hstack, repeat, tile, dot, shape, concatenate, exp, \ |
27 | 27 | log, vectorize, empty, eye, kron |
28 | 28 | from numpy.fft import fft, ifft |
29 | | -from numpy.linalg import qr |
| 29 | +from numpy.linalg import qr, norm |
30 | 30 |
|
31 | 31 | __all__ = ['PSKModem', 'QAMModem', 'ofdm_tx', 'ofdm_rx', 'mimo_ml', 'kbest', 'bit_lvl_repr'] |
32 | 32 |
|
@@ -118,7 +118,7 @@ def plotCons(self): |
118 | 118 | for e in listBin: |
119 | 119 | for i in range(beta): |
120 | 120 | Bin.append(ord(e[i]) - 48) |
121 | | - if (ord(e[i]) - 48 == 0): |
| 121 | + if ord(e[i]) - 48 == 0: |
122 | 122 | mot.append(-1) |
123 | 123 | else: |
124 | 124 | mot.append(1) |
@@ -236,10 +236,12 @@ def mimo_ml(y, h, constellation): |
236 | 236 | Constellation used to modulate the symbols |
237 | 237 |
|
238 | 238 | """ |
| 239 | + _, n = h.shape |
239 | 240 | m = len(constellation) |
240 | | - x_ideal = array([tile(constellation, m), repeat(constellation, m)]) |
241 | | - y_vector = tile(y, m * m) |
242 | | - min_idx = argmin(sum(abs(y_vector - dot(h, x_ideal)), axis=0)) |
| 241 | + x_ideal = empty((n, pow(m, n)), complex) |
| 242 | + for i in range(0, n): |
| 243 | + x_ideal[i] = repeat(tile(constellation, pow(m, i)), pow(m, n - i - 1)) |
| 244 | + min_idx = argmin(norm(y[:, None] - dot(h, x_ideal), axis=0)) |
243 | 245 | x_r = x_ideal[:, min_idx] |
244 | 246 |
|
245 | 247 | return x_r |
@@ -340,10 +342,10 @@ def bit_lvl_repr(H, w): |
340 | 342 | Channel matrix adapted to the bit-level representation. |
341 | 343 | """ |
342 | 344 | beta = len(w) |
343 | | - if beta%2 == 0: |
| 345 | + if beta % 2 == 0: |
344 | 346 | m, n = H.shape |
345 | | - In = eye(n,n) |
346 | | - kr = kron(In,w) |
347 | | - return dot(H,kr) |
| 347 | + In = eye(n , n) |
| 348 | + kr = kron(In , w) |
| 349 | + return dot(H , kr) |
348 | 350 | else: |
349 | 351 | raise ValueError('Beta must be even.') |
0 commit comments