Fix logging to matlab/bin file

Add Python script to plot logged buffers. Modified write_file_matlab()
to add .bin extension if binary format is selected.
This commit is contained in:
Sakthivel Velumani
2025-04-11 09:46:50 -04:00
parent 1d479b2aa9
commit 4adadedeb9
7 changed files with 1666 additions and 46 deletions
+13
View File
@@ -19,3 +19,16 @@ Same goes for any software modifications of `nr_ulsim` - the cache is not aware
the data - remember to clear your cache manually if you are comparing different `nr_ulsim` versions.
The script also allows to skip usage of the cache with `--rerun` option.
## `dl_graph.py`
This generates plots from data saved from nr_dlsim. It takes data in two formats:
1. Plots frequency domain channel estimates, constellation diagram and LLRs from data read in binary format. The data is generated from `nr_dlsim -w`
2. Plots BER (other also possible) from CSV data generated by `nr_dlsim -Z`.
The plots are saved in three formats: `.png`, `.pdf` and `.svg`.
### Example graphs:
#### BER
![image](./ber_compare.svg)
File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 39 KiB

+68
View File
@@ -0,0 +1,68 @@
#!/usr/bin/env python
# coding: utf-8
import numpy as np
import matplotlib.pyplot as plt
import argparse
import pandas
def save_fig(fig:plt.figure, figName:str):
fig.savefig(figName + '.pdf')
fig.savefig(figName + '.png')
fig.savefig(figName + '.svg')
# Channel Frequency Response
def channel_est(dataPath):
binfile = dataPath + 'chestF0_ext_s1.m.bin'
data = np.fromfile(binfile,dtype=np.int16)
dataCmp = data[0::2] + 1j*data[1::2]
fig = plt.gcf()
plt.plot(np.abs(dataCmp))
save_fig(fig, 'channel_est')
plt.close(fig)
# Constellation
def constellation(dataPath):
binfile = dataPath + 'rxF_comp_s1.m.bin'
data = np.fromfile(binfile,dtype=np.int16)
dataCmp = data[0::2] + 1j*data[1::2]
fig = plt.gcf()
plt.scatter(np.real(dataCmp),np.imag(dataCmp))
save_fig(fig, 'constellation')
plt.close(fig)
# LLR
def llr(dataPath):
binfile = dataPath + 'rxF_llr.m.bin'
data = np.fromfile(binfile,dtype=np.int16)
fig = plt.gcf()
plt.plot(data,'*')
save_fig(fig, 'llr')
plt.close(fig)
# BER from data in CSV files generated by nr_dlsim
def ber(dataPath, csvFiles):
d0 = pandas.read_csv(dataPath + csvFiles[0] + '.csv')
ax = d0.plot(x='SNR',y='channel_ber_0',logy=True,label=csvFiles[0])
plt.ylabel('BER')
for i in range(1,len(csvFiles)):
d = pandas.read_csv(dataPath + csvFiles[i] + '.csv')
d.plot(ax=ax,x='SNR',y='channel_ber_0',logy=True,label=csvFiles[i],grid=True)
fig = ax.figure
save_fig(fig, 'ber_compare')
plt.close(fig)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="DL plot generator")
parser.add_argument('--data-path', help='Path to directory containing data', default='../../cmake_targets/ran_build/build/')
parser.add_argument('--csv-data', nargs='+' ,help='CSV file name without extension (generated from nr_dlsim with -Z option)')
parser.add_argument('--ber-compare', help='Compare BER from multiple CSV files', action='store_true')
args = parser.parse_args()
channel_est(args.data_path)
constellation(args.data_path)
llr(args.data_path)
if args.ber_compare:
ber(args.data_path, args.csv_data)