From e39141df6907e25d7ec466f8b5f38b9b738c64ae Mon Sep 17 00:00:00 2001 From: Jason <83615043+JJassonn69@users.noreply.github.com> Date: Thu, 9 Apr 2026 02:42:50 +0300 Subject: [PATCH] fix: align replay DC notch with dual sub-frame architecture The replay _replay_dc_notch() was treating all 32 Doppler bins as a single frame, only zeroing bins at the global edges ({0,1,31} for width=2). The RTL uses dual 16-point sub-frames where each sub-frame has its own DC, so the notch must use bin_within_sf = dbin & 0xF. This fixes test_replay_packets_parseable which was seeing 5 detections instead of the expected 4, due to a spurious hit at (range=2, doppler=15) surviving CFAR. --- 9_Firmware/9_3_GUI/radar_protocol.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/9_Firmware/9_3_GUI/radar_protocol.py b/9_Firmware/9_3_GUI/radar_protocol.py index 85a5867..52e4543 100644 --- a/9_Firmware/9_3_GUI/radar_protocol.py +++ b/9_Firmware/9_3_GUI/radar_protocol.py @@ -459,14 +459,20 @@ def _replay_mti(decim_i: np.ndarray, decim_q: np.ndarray, def _replay_dc_notch(doppler_i: np.ndarray, doppler_q: np.ndarray, width: int) -> Tuple[np.ndarray, np.ndarray]: - """Bit-accurate DC notch filter (matches radar_system_top.v inline).""" + """Bit-accurate DC notch filter (matches radar_system_top.v inline). + + Dual sub-frame notch: doppler_bin[4:0] = {sub_frame, bin[3:0]}. + Each 16-bin sub-frame has its own DC at bin 0, so we zero bins + where ``bin_within_sf < width`` or ``bin_within_sf > (15 - width + 1)``. + """ out_i = doppler_i.copy() out_q = doppler_q.copy() if width == 0: return out_i, out_q n_doppler = doppler_i.shape[1] for dbin in range(n_doppler): - if dbin < width or dbin > (n_doppler - 1 - width + 1): + bin_within_sf = dbin & 0xF + if bin_within_sf < width or bin_within_sf > (15 - width + 1): out_i[:, dbin] = 0 out_q[:, dbin] = 0 return out_i, out_q