Gaussian smoothing.

This commit is contained in:
ivngrmk
2025-11-17 18:03:41 +03:00
parent 174ab59004
commit 333ec5d196
6 changed files with 40 additions and 8 deletions

0
__init__.py Normal file
View File

0
vna_system/__init__.py Normal file
View File

View File

View File

@ -35,7 +35,7 @@ VNA_PID = 0x5740 # STM32 Virtual ComPort
# -----------------------------------------------------------------------------
# Simulator mode settings
# -----------------------------------------------------------------------------
USE_SIMULATOR = False # Set to True to use simulator instead of real device
USE_SIMULATOR = True # Set to True to use simulator instead of real device
SIMULATOR_SWEEP_FILE = BASE_DIR / "binary_input" / "sweep_example" / "example.json"
SIMULATOR_NOISE_LEVEL = 100 # Standard deviation of Gaussian noise to add to real and imaginary parts

View File

@ -1,11 +1,12 @@
{
"open_air": false,
"open_air": true,
"axis": "abs",
"cut": 0.244,
"max": 1.0,
"cut": 0.267,
"max": 1.5,
"gain": 1.0,
"start_freq": 600.0,
"stop_freq": 6080.0,
"start_freq": 470.0,
"stop_freq": 8800.0,
"clear_history": false,
"sigma": 4.28,
"data_limit": 500
}

View File

@ -6,6 +6,7 @@ from typing import Any
import numpy as np
from numpy.typing import NDArray
from scipy.ndimage import gaussian_filter1d
from vna_system.core.logging.logger import get_component_logger
from vna_system.core.processors.base_processor import BaseProcessor, UIParameter, ProcessedResult
@ -56,6 +57,7 @@ class BScanProcessor(BaseProcessor):
"start_freq": 100.0, # Start frequency (MHz)
"stop_freq": 8800.0, # Stop frequency (MHz)
"clear_history": False, # UI button; not persisted
"sigma" : 0.01,
}
def get_ui_parameters(self) -> list[UIParameter]:
@ -74,7 +76,7 @@ class BScanProcessor(BaseProcessor):
label="Ось",
type="select",
value=cfg["axis"],
options={"choices": ["real", "abs", "phase"]},
options={"choices": ["real", "imag", "abs", "phase"]},
),
# UIParameter(
# name="data_limitation",
@ -125,6 +127,13 @@ class BScanProcessor(BaseProcessor):
value=False,
options={"action": "Очистить накопленную историю графика"},
),
UIParameter(
name="sigma",
label="Степень сглаживания в abs режиме",
type="slider",
value=self._config.get("y_max", 10),
options={"min": 0.01, "max": 5.0, "step": 0.01, "dtype": "float"},
),
]
def update_config(self, updates: dict[str, Any]) -> None:
@ -557,6 +566,19 @@ class BScanProcessor(BaseProcessor):
freq_start = self._config["start_freq"] * 1e6
freq_stop = self._config["stop_freq"] * 1e6
# Determine sigma for smoothing
if vna_config:
# calc_type = vna_config.get("axis", "abs")
# sigma = float(vna_config.get("sigma", 0.01))
calc_type = self._config["axis"]
sigma = self._config["sigma"]
pass
else:
calc_type = self._config["axis"]
sigma = self._config["sigma"]
# Frequency vector over current data length
freq_axis = np.linspace(freq_start, freq_stop, complex_data.size, dtype=float)
@ -571,8 +593,15 @@ class BScanProcessor(BaseProcessor):
# Depth windowing and gain shaping
depth_out, time_out = self._apply_depth_processing(depth_m, time_response)
if calc_type == 'abs':
print('Filtering with sigma',sigma)
filtered_time_out = gaussian_filter1d(time_out, sigma=sigma)
else:
print("Not filtering")
filtered_time_out = time_out
return {
"time_data": time_out,
"time_data": filtered_time_out,
"distance": depth_out,
"freq_range": [freq_start, freq_stop],
"complex_time": complex_data,
@ -659,6 +688,8 @@ class BScanProcessor(BaseProcessor):
y_fin = np.abs(y)
elif axis == "real":
y_fin = np.real(y)
elif axis == "imag":
y_fin = np.imag(y)
elif axis == "phase":
y_fin = np.angle(y)
else: