Skip to content

Commit

Permalink
improve plot int test_Decimator_Correlator_PeakDetector_FFT.py
Browse files Browse the repository at this point in the history
  • Loading branch information
catkira committed Aug 15, 2023
1 parent 8c32fd7 commit d697a8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion hdl/Decimator_Correlator_PeakDetector_FFT.sv
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Decimator_Correlator_PeakDetector_FFT
localparam SFN_WIDTH = $clog2(SFN_MAX),
localparam SUBFRAME_NUMBER_WIDTH = $clog2(SUBFRAMES_PER_FRAME - 1),
localparam SYMBOL_NUMBER_WIDTH = $clog2(SYM_PER_SF - 1),
localparam BLK_EXP_LEN = 8,
localparam OUT_USER_WIDTH = SFN_WIDTH + SUBFRAME_NUMBER_WIDTH + SYMBOL_NUMBER_WIDTH + BLK_EXP_LEN + 1
)
(
Expand Down Expand Up @@ -131,7 +132,6 @@ frame_sync_i
.SSB_start_o(fs_out_SSB_start)
);

localparam BLK_EXP_LEN = 8;
localparam FFT_DEMOD_OUT_USER_WIDTH = SFN_WIDTH + SUBFRAME_NUMBER_WIDTH + SYMBOL_NUMBER_WIDTH + BLK_EXP_LEN;
wire [FFT_OUT_DW - 1 : 0] fft_demod_out_tdata;
wire [FFT_DEMOD_OUT_USER_WIDTH - 1 : 0] fft_demod_out_tuser;
Expand Down
28 changes: 19 additions & 9 deletions tests/test_Decimator_Correlator_PeakDetector_FFT.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ async def simple_test(dut):
elif os.environ['TEST_FILE'] == '1876954_7680KSPS_srsRAN_Project_gnb_short_2':
expected_N_id_1 = 0
expected_N_id_2 = 1
sym_offset = 2
expected_rx_syms = 25 * 12 * 14 * 2 # 2 subframes
f_c = 1876954000
delta_f = 0
Expand Down Expand Up @@ -199,8 +200,10 @@ async def simple_test(dut):
received_SSS.append(sym)

if dut.m_axis_out_tvalid.value.integer == 1:
sym = _twos_comp(dut.m_axis_out_tdata.value.integer & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2) \
+ 1j * _twos_comp((dut.m_axis_out_tdata.value.integer>>(FFT_OUT_DW//2)) & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2)
blk_exp_len = 8
blk_exp = (dut.m_axis_out_tuser.value.integer >> 1) & (2 ** blk_exp_len - 1)
sym = (_twos_comp(dut.m_axis_out_tdata.value.integer & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2) \
+ 1j * _twos_comp((dut.m_axis_out_tdata.value.integer>>(FFT_OUT_DW//2)) & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2)) / (2 ** blk_exp)
rx_syms.append(sym)


Expand Down Expand Up @@ -266,14 +269,21 @@ async def simple_test(dut):
rx_syms = np.array(rx_syms)
print(f'received {len(rx_syms)} ressource elements')
if ('PLOTS' in os.environ and os.environ['PLOTS'] == '1') and (os.environ['TEST_FILE'] == '1876954_7680KSPS_srsRAN_Project_gnb_short_2'):
_, axs = plt.subplots(1, 3, figsize=(15, 5))
SC_PER_SYM = 25 * 12 # assume NFFT = 9
sym = rx_syms[SC_PER_SYM*0 : SC_PER_SYM*1]
axs[0].plot(np.real(sym), np.imag(sym), '.')
sym = rx_syms[SC_PER_SYM*1 : SC_PER_SYM*17]
axs[1].plot(np.real(sym), np.imag(sym), '.')
sym = rx_syms[SC_PER_SYM*17 : SC_PER_SYM*28]
axs[2].plot(np.real(sym), np.imag(sym), '.')
assert len(rx_syms) % SC_PER_SYM == 0
rx_syms = np.append(np.zeros(SC_PER_SYM * sym_offset), rx_syms)
rx_syms = np.reshape(rx_syms, (SC_PER_SYM, len(rx_syms) // SC_PER_SYM), order='F')
fig, axs = plt.subplots(2, 14, figsize=(35, 7))
for slot in range(2):
for sym_idx in range(14):
sym = rx_syms[:, slot*14 + sym_idx]
phase_comp(sym, f_c, NFFT, sym_idx)
axs[slot, sym_idx].plot(np.real(sym), np.imag(sym), '.')
axs[slot, sym_idx].set_xlim(-25, 25)
axs[slot, sym_idx].set_ylim(-25, 25)
axs[slot, sym_idx].set_xticks([])
axs[slot, sym_idx].set_yticks([])
fig.tight_layout()
plt.show()

# peak_pos = np.argmax(received[:np.round(fs * 0.02).astype(int)]) # max peak within first 20 ms
Expand Down

0 comments on commit d697a8f

Please sign in to comment.