Gaussian smoothing.
This commit is contained in:
0
__init__.py
Normal file
0
__init__.py
Normal file
0
vna_system/__init__.py
Normal file
0
vna_system/__init__.py
Normal file
0
vna_system/core/__init__.py
Normal file
0
vna_system/core/__init__.py
Normal file
@ -35,7 +35,7 @@ VNA_PID = 0x5740 # STM32 Virtual ComPort
|
|||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Simulator mode settings
|
# 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_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
|
SIMULATOR_NOISE_LEVEL = 100 # Standard deviation of Gaussian noise to add to real and imaginary parts
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"open_air": false,
|
"open_air": true,
|
||||||
"axis": "abs",
|
"axis": "abs",
|
||||||
"cut": 0.244,
|
"cut": 0.267,
|
||||||
"max": 1.0,
|
"max": 1.5,
|
||||||
"gain": 1.0,
|
"gain": 1.0,
|
||||||
"start_freq": 600.0,
|
"start_freq": 470.0,
|
||||||
"stop_freq": 6080.0,
|
"stop_freq": 8800.0,
|
||||||
"clear_history": false,
|
"clear_history": false,
|
||||||
|
"sigma": 4.28,
|
||||||
"data_limit": 500
|
"data_limit": 500
|
||||||
}
|
}
|
||||||
@ -6,6 +6,7 @@ from typing import Any
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numpy.typing import NDArray
|
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.logging.logger import get_component_logger
|
||||||
from vna_system.core.processors.base_processor import BaseProcessor, UIParameter, ProcessedResult
|
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)
|
"start_freq": 100.0, # Start frequency (MHz)
|
||||||
"stop_freq": 8800.0, # Stop frequency (MHz)
|
"stop_freq": 8800.0, # Stop frequency (MHz)
|
||||||
"clear_history": False, # UI button; not persisted
|
"clear_history": False, # UI button; not persisted
|
||||||
|
"sigma" : 0.01,
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_ui_parameters(self) -> list[UIParameter]:
|
def get_ui_parameters(self) -> list[UIParameter]:
|
||||||
@ -74,7 +76,7 @@ class BScanProcessor(BaseProcessor):
|
|||||||
label="Ось",
|
label="Ось",
|
||||||
type="select",
|
type="select",
|
||||||
value=cfg["axis"],
|
value=cfg["axis"],
|
||||||
options={"choices": ["real", "abs", "phase"]},
|
options={"choices": ["real", "imag", "abs", "phase"]},
|
||||||
),
|
),
|
||||||
# UIParameter(
|
# UIParameter(
|
||||||
# name="data_limitation",
|
# name="data_limitation",
|
||||||
@ -125,6 +127,13 @@ class BScanProcessor(BaseProcessor):
|
|||||||
value=False,
|
value=False,
|
||||||
options={"action": "Очистить накопленную историю графика"},
|
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:
|
def update_config(self, updates: dict[str, Any]) -> None:
|
||||||
@ -557,6 +566,19 @@ class BScanProcessor(BaseProcessor):
|
|||||||
freq_start = self._config["start_freq"] * 1e6
|
freq_start = self._config["start_freq"] * 1e6
|
||||||
freq_stop = self._config["stop_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
|
# Frequency vector over current data length
|
||||||
freq_axis = np.linspace(freq_start, freq_stop, complex_data.size, dtype=float)
|
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 windowing and gain shaping
|
||||||
depth_out, time_out = self._apply_depth_processing(depth_m, time_response)
|
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 {
|
return {
|
||||||
"time_data": time_out,
|
"time_data": filtered_time_out,
|
||||||
"distance": depth_out,
|
"distance": depth_out,
|
||||||
"freq_range": [freq_start, freq_stop],
|
"freq_range": [freq_start, freq_stop],
|
||||||
"complex_time": complex_data,
|
"complex_time": complex_data,
|
||||||
@ -659,6 +688,8 @@ class BScanProcessor(BaseProcessor):
|
|||||||
y_fin = np.abs(y)
|
y_fin = np.abs(y)
|
||||||
elif axis == "real":
|
elif axis == "real":
|
||||||
y_fin = np.real(y)
|
y_fin = np.real(y)
|
||||||
|
elif axis == "imag":
|
||||||
|
y_fin = np.imag(y)
|
||||||
elif axis == "phase":
|
elif axis == "phase":
|
||||||
y_fin = np.angle(y)
|
y_fin = np.angle(y)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user