Commit bebd2bb9 authored by Rahman's avatar Rahman

added log2csi_hdf5 and anaylyze mode to plot_hdf5 for plotting capcacity and other stats

parent a6854776
......@@ -352,157 +352,3 @@ def demult(csi, data, method='zf'):
sig_intf[frame, :, sc] = np.dot(data[frame, :, sc], np.transpose(
np.conj(userCSI[frame, :, :, sc]), (1, 0)))
return sig_intf
# ********************* Example Code *********************
if __name__ == '__main__':
starttime = time.time()
show_plots = True
# samples to zoom in around frame (to look at local behavior), 0 to disable
zoom = 0
pl = 0
static = h5py.File('logs/ArgosCSI-76x2-2017-02-07-18-25-47.hdf5', 'r')
env = h5py.File('logs/ArgosCSI-76x2-2017-02-07-18-25-47.hdf5', 'r')
mobile = h5py.File('logs/ArgosCSI-76x2-2017-02-07-18-25-47.hdf5', 'r')
frame = 10 # frame to compute beamweights from
conjdata = []
zfdata = []
for h5log in [static, env, mobile]:
# read parameters for this measurement data
samps_per_user = h5log.attrs['samples_per_user']
num_users = h5log.attrs['num_mob_ant']
timestep = h5log.attrs['frame_length']/20e6
noise_meas_en = h5log.attrs.get('measured_noise', 1)
# compute CSI for each user and get a nice numpy array
# Returns csi with Frame, User, LTS (there are 2), BS ant, Subcarrier #also, iq samples nicely chunked out, same dims, but subcarrier is sample.
csi, iq = samps2csi(
h5log['Pilot_Samples'], num_users+noise_meas_en, samps_per_user)
# zoom in too look at behavior around peak (and reduce processing time)
if zoom > 0:
csi = csi[frame-zoom:frame+zoom, :, :, :, :]
# recenter the plots (otherwise it errors)
frame = zoom
noise = csi[:, -1, :, :, :] # noise is last set of data.
# don't include noise, average over both LTSs
userCSI = np.mean(csi[:, :num_users, :, :, :], 2)
# example lts find:
user = 0
# so, this is pretty ugly, but we want all the samples (not just those chunked from samps2csi), so we not only convert ints to the complex floats, but also have to figure out where to chunk the user from.
lts_iq = h5log['Pilot_Samples'][frame, 0, user*samps_per_user:(
user+1)*samps_per_user, 0]*1.+h5log['Pilot_Samples'][frame, 0, user*samps_per_user:(user+1)*samps_per_user, 1]*1j
lts_iq /= 2**15
# Andrew wrote this, but I don't really like the way he did the convolve method... works well enough for high SNRs.
offset = lts.findLTS(lts_iq)+32
print("LTS offset for user %d, frame %d: %d" %
(user, frame, offset))
# compute beamweights based on the specified frame.
conjbws = np.transpose(
np.conj(userCSI[frame, :, :, :]), (1, 0, 2))
zfbws = np.empty(
(userCSI.shape[2], userCSI.shape[1], userCSI.shape[3]), dtype='complex64')
for sc in range(userCSI.shape[3]):
zfbws[:, :, sc] = np.linalg.pinv(
userCSI[frame, :, :, sc])
downlink = True
# calculate capacity based on these weights
# these return total capacity, per-user capacity, per-user/per-subcarrier capacity, SINR, single-user capacity(no inter-user interference), and SNR
# conjcap_total,conjcap_u,conjcap_sc,conjSINR,conjcap_su_sc,conjcap_su_u,conjSNR
conj = calCapacity(userCSI, noise, conjbws, downlink=downlink)
# zfcap_total,zfcap_u,zfcap_sc,zfSINR,zfcap_su_sc,zfcap_su_u,zfSNR
zf = calCapacity(userCSI, noise, zfbws, downlink=downlink)
# plot stuff
if show_plots:
# Multiuser Conjugate
plt.figure(1000*pl, figsize=(50, 10))
plt.plot(
np.arange(0, csi.shape[0]*timestep, timestep)[:csi.shape[0]], conj[1])
# plt.ylim([0,2])
plt.xlabel('Time (s)')
plt.ylabel('Per User Capacity Conj (bps/Hz)')
plt.show()
# Multiuser Zeroforcing
plt.figure(1000*pl+1, figsize=(50, 10))
plt.plot(
np.arange(0, csi.shape[0]*timestep, timestep)[:csi.shape[0]], zf[1])
# plt.ylim([0,2])
plt.xlabel('Time (s)')
plt.ylabel('Per User Capacity ZF (bps/Hz)')
plt.show()
# Single user (but show all users)
plt.figure(1000*pl+2, figsize=(50, 10))
plt.plot(
np.arange(0, csi.shape[0]*timestep, timestep)[:csi.shape[0]], conj[-2])
# plt.ylim([0,2])
plt.xlabel('Time (s)')
plt.ylabel('SUBF Capacity Conj (bps/Hz)')
plt.show()
pl += 1
# save for exporting to matlab (prettier plots)
conjdata.append(conj)
zfdata.append(zf)
del csi, iq # free the memory
endtime = time.time()
print("Total time: %f" % (endtime-starttime))
'''
import scipy.io
data = dict(timestep=timestep)
data.update(dict(static_zf_cap_total=zfdata[0][0], static_zf_cap_u=zfdata[0][1],static_conj_cap_total=conjdata[0][0], static_conj_cap_u=conjdata[0][1], static_conj_cap_su_u=conjdata[0][-2]))
data.update(dict(env_zf_cap_total=zfdata[1][0], env_zf_cap_u=zfdata[1][1], env_conj_cap_total=conjdata[1][0], env_conj_cap_u=conjdata[1][1], env_conj_cap_su_u=conjdata[1][-2]))
data.update(dict(mobile_zf_cap_total=zfdata[2][0], mobile_zf_cap_u=zfdata[2][1],mobile_conj_cap_total=conjdata[2][0], mobile_conj_cap_u=conjdata[2][1], mobile_conj_cap_su_u=conjdata[2][-2]))
#data = dict(timestep=timestep, static_zf_cap_total=zfdata[0][0], static_zf_cap_u=zfdata[0][1],static_conj_cap_total=conjdata[0][0], static_conj_cap_u=conjdata[0][1], env_zf_cap_total=zfdata[1][0], env_zf_cap_u=zfdata[1][1],env_conj_cap_total=conjdata[1][0], env_conj_cap_u=conjdata[1][1], mobile_zf_cap_total=zfdata[2][0], mobile_zf_cap_u=zfdata[2][1],mobile_conj_cap_total=conjdata[2][0], mobile_conj_cap_u=conjdata[2][1], static_conj_cap_su_u=conjdata[0][-2], env_conj_cap_su_u=conjdata[1][-2], mobile_conj_cap_su_u=conjdata[2][-2])
scipy.io.savemat('logs/capacity-frame_%d.mat' % frame, data)
'''
'''
%example matlab script for loading the saved file
load capacity-frame_500
%timestep = 0.035
plot(0:timestep:timestep*(length(env_conj_cap_u)-1),env_conj_cap_u)
plot(0:timestep:timestep*(length(mobile_conj_cap_u)-1),mobile_conj_cap_u)
xlim([0,600])
ylim([0,5])
ylabel('Per User Capacity Conj (bps/Hz)')
xlabel('Time (s)')
figure(4)
plot(0:timestep:timestep*(length(mobile_conj_cap_u)-1),mobile_conj_cap_u(:,2))
xlim([0,120])
ylim([0,5])
xlabel('Time (s)')
ylabel('User Capacity Conjugate (bps/Hz)')
print -clipboard -dmeta %windows only
'''
#import os
#import glob
'''
#Example for simply converting raw IQ to CSI.
import glob
logdir = "logs/uhf_wb_traces_vito/"
filenames = glob.glob(logdir+"*.hdf5")
#filenames = ('ChannelTracesVitosLand/ArgosCSI-8x5-2015-12-19-00-00-29_good_uhf_mobile_2directionalpolarized_1staticmobile_2mobile',
# 'ChannelTracesVitosLand/ArgosCSI-8x4-2015-12-18-22-34-02_good_static_uhf_vito_alldirectional',
# 'ChannelTracesVitosLand/ArgosCSI-8x4-2015-12-18-22-53-16_good_uhf_envmobility_vito.hdf5',)
for filename in filenames:
print(filename)
log2csi_hdf5(filename)
'''
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment