mmserv

Minimum Mean Square Error detection on RISC-V Vector Extention
git clone https://git.ea.contact/mmserv
Log | Files | Refs | README

mmse.py (1240B)


      1 #!/usr/bin/python
      2 
      3 """ Python implementation of the MMSE receiver with Cholesky decomposition """
      4 
      5 from util import read_defines, load_xHRy
      6 
      7 import numpy as np
      8 from os import path, makedirs
      9 
     10 # Read the data from the files
     11 NUM_RX_ANT, NUM_TX_ANT, NUM_SC = read_defines()
     12 x, H, R, y = load_xHRy(NUM_RX_ANT, NUM_TX_ANT, NUM_SC)
     13 x_mmse = np.empty((NUM_TX_ANT, NUM_SC), np.complex64)
     14 
     15 for sc in range(NUM_SC):
     16     HH = H[..., sc].conj().T
     17     L = np.linalg.cholesky(HH @ H[..., sc] + R[..., sc])
     18     HHy = np.einsum("ij,j->i", HH, y[:, sc])
     19 
     20     z = np.empty((NUM_TX_ANT,), dtype=np.complex64)
     21     for i in range(NUM_TX_ANT):
     22         z[i] = (HHy[i] - np.sum([L[i, j]*z[j] for j in range(i)])) / L[i, i]
     23 
     24     LH = L.conj().T
     25     for i in range(NUM_TX_ANT-1, -1, -1):
     26         x_mmse[i, sc] = (z[i] - np.sum([LH[i, j]*x_mmse[j, sc] for j in range(i+1, NUM_TX_ANT)], 0)) / LH[i, i]
     27 
     28 # Output the data
     29 out_dir = path.join(path.dirname(__file__), "..", "out")
     30 if not path.exists(out_dir):
     31     makedirs(out_dir)
     32 with open(path.join(out_dir, "x_mmse_python_re.bin"), "wb") as f:
     33     f.write(x_mmse.real.astype(np.float32).tobytes())
     34 with open(path.join(out_dir, "x_mmse_python_im.bin"), "wb") as f:
     35     f.write(x_mmse.imag.astype(np.float32).tobytes())