forked from TianLin0509/BF-design-with-DL
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
43 lines (35 loc) · 1.25 KB
/
utils.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
from tensorflow.python.keras import *
import tensorflow as tf
import scipy.io as sio
# ---------------------
# Global Parameters
# ---------------------
Nt = 64 # the number of antennas
P = 1 # the normalized transmit power
# ---------------------
# Functions
# ---------------------
# transfer the phase to complex-valued analog beamformer
def trans_Vrf(temp):
v_real = tf.cos(temp)
v_imag = tf.sin(temp)
vrf = tf.cast(tf.complex(v_real, v_imag), tf.complex64)
return vrf
# For the simplification of implementation based on Keras, we use a lambda layer to compute the rate
# Thus, the output of the model is actually the loss.
def Rate_func(temp):
h, v, SNR_input = temp
hv = backend.batch_dot(
tf.cast(h, tf.complex64), tf.transpose(a=v, perm=[1, 0]))
rate = tf.math.log(tf.cast(1 + SNR_input / Nt * tf.pow(tf.abs(hv), 2), tf.float32)) / tf.math.log(2.0)
return -rate
# load the saved .mat files generated by Matlab.
def mat_load(path):
print('loading data...')
# load the perfect csi
h = sio.loadmat(path + '/pcsi.mat')['pcsi']
# load the estimated csi
h_est = sio.loadmat(path + '/ecsi.mat')['ecsi']
print('loading complete')
print('The shape of CSI is: ', h_est.shape)
return h, h_est