cut the range feature
This commit is contained in:
@ -9,6 +9,21 @@ import numpy as np
|
||||
from rfg_adc_plotter.constants import C_M_S, FFT_LEN, SWEEP_FREQ_MAX_GHZ, SWEEP_FREQ_MIN_GHZ
|
||||
|
||||
|
||||
def _finite_freq_bounds(freqs: Optional[np.ndarray]) -> Optional[Tuple[float, float]]:
|
||||
"""Return finite frequency bounds for the current working segment."""
|
||||
if freqs is None:
|
||||
return None
|
||||
freq_arr = np.asarray(freqs, dtype=np.float64).reshape(-1)
|
||||
finite = freq_arr[np.isfinite(freq_arr)]
|
||||
if finite.size < 2:
|
||||
return None
|
||||
f_min = float(np.min(finite))
|
||||
f_max = float(np.max(finite))
|
||||
if not np.isfinite(f_min) or not np.isfinite(f_max) or f_max <= f_min:
|
||||
return None
|
||||
return f_min, f_max
|
||||
|
||||
|
||||
def prepare_fft_segment(
|
||||
sweep: np.ndarray,
|
||||
freqs: Optional[np.ndarray],
|
||||
@ -57,9 +72,16 @@ def build_symmetric_ifft_spectrum(
|
||||
if fft_len <= 0:
|
||||
return None
|
||||
|
||||
freq_axis = np.linspace(-SWEEP_FREQ_MAX_GHZ, SWEEP_FREQ_MAX_GHZ, int(fft_len), dtype=np.float64)
|
||||
neg_idx_all = np.flatnonzero(freq_axis <= (-SWEEP_FREQ_MIN_GHZ))
|
||||
pos_idx_all = np.flatnonzero(freq_axis >= SWEEP_FREQ_MIN_GHZ)
|
||||
bounds = _finite_freq_bounds(freqs)
|
||||
if bounds is None:
|
||||
f_min = float(SWEEP_FREQ_MIN_GHZ)
|
||||
f_max = float(SWEEP_FREQ_MAX_GHZ)
|
||||
else:
|
||||
f_min, f_max = bounds
|
||||
|
||||
freq_axis = np.linspace(-f_max, f_max, int(fft_len), dtype=np.float64)
|
||||
neg_idx_all = np.flatnonzero(freq_axis <= (-f_min))
|
||||
pos_idx_all = np.flatnonzero(freq_axis >= f_min)
|
||||
band_len = int(min(neg_idx_all.size, pos_idx_all.size))
|
||||
if band_len <= 1:
|
||||
return None
|
||||
@ -96,8 +118,15 @@ def build_positive_only_centered_ifft_spectrum(
|
||||
if fft_len <= 0:
|
||||
return None
|
||||
|
||||
freq_axis = np.linspace(-SWEEP_FREQ_MAX_GHZ, SWEEP_FREQ_MAX_GHZ, int(fft_len), dtype=np.float64)
|
||||
pos_idx = np.flatnonzero(freq_axis >= SWEEP_FREQ_MIN_GHZ)
|
||||
bounds = _finite_freq_bounds(freqs)
|
||||
if bounds is None:
|
||||
f_min = float(SWEEP_FREQ_MIN_GHZ)
|
||||
f_max = float(SWEEP_FREQ_MAX_GHZ)
|
||||
else:
|
||||
f_min, f_max = bounds
|
||||
|
||||
freq_axis = np.linspace(-f_max, f_max, int(fft_len), dtype=np.float64)
|
||||
pos_idx = np.flatnonzero(freq_axis >= f_min)
|
||||
band_len = int(pos_idx.size)
|
||||
if band_len <= 1:
|
||||
return None
|
||||
@ -216,7 +245,12 @@ def compute_distance_axis(
|
||||
return np.zeros((0,), dtype=np.float64)
|
||||
fft_mode = _normalize_fft_mode(mode, symmetric)
|
||||
if fft_mode in {"symmetric", "positive_only"}:
|
||||
df_ghz = (2.0 * float(SWEEP_FREQ_MAX_GHZ)) / max(1, FFT_LEN - 1)
|
||||
bounds = _finite_freq_bounds(freqs)
|
||||
if bounds is None:
|
||||
f_max = float(SWEEP_FREQ_MAX_GHZ)
|
||||
else:
|
||||
_, f_max = bounds
|
||||
df_ghz = (2.0 * f_max) / max(1, FFT_LEN - 1)
|
||||
else:
|
||||
if freqs is None:
|
||||
return np.arange(bins, dtype=np.float64)
|
||||
|
||||
Reference in New Issue
Block a user