This commit is contained in:
2026-07-13 17:58:40 +01:00
parent 5050574e4a
commit 2cf7543bbe
2 changed files with 19 additions and 13 deletions
+13 -1
View File
@@ -10,6 +10,13 @@ import numpy as np
from rfg_adc_plotter.constants import FFT_LEN, SWEEP_FREQ_MAX_GHZ, SWEEP_FREQ_MIN_GHZ
from rfg_adc_plotter.processing.fft import compute_distance_axis, compute_fft_mag_row, fft_mag_to_db
# The device sweep length jitters by a few percent (e.g. 896..920). Only treat a
# shrink as real when the new width drops below this fraction of the current width;
# genuine format changes (e.g. 2048 -> 256, or halving) fall well below it. This
# stops the ring from reallocating every frame — which churned the buffer and made
# the B-scan flicker.
RING_WIDTH_SHRINK_FRACTION = 0.8
class RingBuffer:
"""Store raw sweeps, FFT rows, and matching time markers."""
@@ -103,7 +110,12 @@ class RingBuffer:
self.ring_fft_input = np.full((self.max_sweeps, self.width), np.nan + 0j, dtype=np.complex64)
self.head = 0
changed = True
elif target_width != self.width:
elif target_width > self.width or target_width < int(self.width * RING_WIDTH_SHRINK_FRACTION):
# Resize when the sweep grows, or shrinks by a meaningful fraction (a real
# format change). Ignore small shrinks: the device sweep length jitters by
# a few percent (e.g. 896 vs 920). Resizing on every such shrink churned
# the ring every frame and made the B-scan flicker. A shorter sweep just
# fills fewer columns (the rest stays NaN); the width converges to the max.
new_ring = np.full((self.max_sweeps, target_width), np.nan, dtype=np.float32)
new_fft_input = np.full((self.max_sweeps, target_width), np.nan + 0j, dtype=np.complex64)
take = min(self.width, target_width)