Compare commits
2 Commits
normaliser
...
7d714530bc
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d714530bc | |||
| 415084e66b |
@ -85,6 +85,116 @@ def _parse_spec_clip(spec: Optional[str]) -> Optional[Tuple[float, float]]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _normalize_sweep_simple(raw: np.ndarray, calib: np.ndarray) -> np.ndarray:
|
||||||
|
"""Простая нормировка: поэлементное деление raw/calib."""
|
||||||
|
w = min(raw.size, calib.size)
|
||||||
|
if w <= 0:
|
||||||
|
return raw
|
||||||
|
out = np.full_like(raw, np.nan, dtype=np.float32)
|
||||||
|
with np.errstate(divide="ignore", invalid="ignore"):
|
||||||
|
out[:w] = raw[:w] / calib[:w]
|
||||||
|
out = np.nan_to_num(out, nan=np.nan, posinf=np.nan, neginf=np.nan)
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def _build_calib_envelopes(calib: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
|
||||||
|
"""Оценить нижнюю/верхнюю огибающие калибровочной кривой."""
|
||||||
|
n = int(calib.size)
|
||||||
|
if n <= 0:
|
||||||
|
empty = np.zeros((0,), dtype=np.float32)
|
||||||
|
return empty, empty
|
||||||
|
|
||||||
|
y = np.asarray(calib, dtype=np.float32)
|
||||||
|
finite = np.isfinite(y)
|
||||||
|
if not np.any(finite):
|
||||||
|
zeros = np.zeros_like(y, dtype=np.float32)
|
||||||
|
return zeros, zeros
|
||||||
|
|
||||||
|
if not np.all(finite):
|
||||||
|
x = np.arange(n, dtype=np.float32)
|
||||||
|
y = y.copy()
|
||||||
|
y[~finite] = np.interp(x[~finite], x[finite], y[finite]).astype(np.float32)
|
||||||
|
|
||||||
|
if n < 3:
|
||||||
|
return y.copy(), y.copy()
|
||||||
|
|
||||||
|
dy = np.diff(y)
|
||||||
|
s = np.sign(dy).astype(np.int8, copy=False)
|
||||||
|
|
||||||
|
if np.any(s == 0):
|
||||||
|
for i in range(1, s.size):
|
||||||
|
if s[i] == 0:
|
||||||
|
s[i] = s[i - 1]
|
||||||
|
for i in range(s.size - 2, -1, -1):
|
||||||
|
if s[i] == 0:
|
||||||
|
s[i] = s[i + 1]
|
||||||
|
s[s == 0] = 1
|
||||||
|
|
||||||
|
max_idx = np.where((s[:-1] > 0) & (s[1:] < 0))[0] + 1
|
||||||
|
min_idx = np.where((s[:-1] < 0) & (s[1:] > 0))[0] + 1
|
||||||
|
|
||||||
|
x = np.arange(n, dtype=np.float32)
|
||||||
|
|
||||||
|
def _interp_nodes(nodes: np.ndarray) -> np.ndarray:
|
||||||
|
if nodes.size == 0:
|
||||||
|
idx = np.array([0, n - 1], dtype=np.int64)
|
||||||
|
else:
|
||||||
|
idx = np.unique(np.concatenate(([0], nodes, [n - 1]))).astype(np.int64)
|
||||||
|
return np.interp(x, idx.astype(np.float32), y[idx]).astype(np.float32)
|
||||||
|
|
||||||
|
upper = _interp_nodes(max_idx)
|
||||||
|
lower = _interp_nodes(min_idx)
|
||||||
|
|
||||||
|
swap = lower > upper
|
||||||
|
if np.any(swap):
|
||||||
|
tmp = upper[swap].copy()
|
||||||
|
upper[swap] = lower[swap]
|
||||||
|
lower[swap] = tmp
|
||||||
|
|
||||||
|
return lower, upper
|
||||||
|
|
||||||
|
|
||||||
|
def _normalize_sweep_projector(raw: np.ndarray, calib: np.ndarray) -> np.ndarray:
|
||||||
|
"""Нормировка через проекцию между огибающими калибровки в диапазон [-1, +1]."""
|
||||||
|
w = min(raw.size, calib.size)
|
||||||
|
if w <= 0:
|
||||||
|
return raw
|
||||||
|
|
||||||
|
out = np.full_like(raw, np.nan, dtype=np.float32)
|
||||||
|
raw_seg = np.asarray(raw[:w], dtype=np.float32)
|
||||||
|
lower, upper = _build_calib_envelopes(np.asarray(calib[:w], dtype=np.float32))
|
||||||
|
span = upper - lower
|
||||||
|
|
||||||
|
finite_span = span[np.isfinite(span) & (span > 0)]
|
||||||
|
if finite_span.size > 0:
|
||||||
|
eps = max(float(np.median(finite_span)) * 1e-6, 1e-9)
|
||||||
|
else:
|
||||||
|
eps = 1e-9
|
||||||
|
|
||||||
|
valid = (
|
||||||
|
np.isfinite(raw_seg)
|
||||||
|
& np.isfinite(lower)
|
||||||
|
& np.isfinite(upper)
|
||||||
|
& (span > eps)
|
||||||
|
)
|
||||||
|
if np.any(valid):
|
||||||
|
proj = np.empty_like(raw_seg, dtype=np.float32)
|
||||||
|
proj[valid] = ((2.0 * (raw_seg[valid] - lower[valid]) / span[valid]) - 1.0) * 1000.0
|
||||||
|
proj[valid] = np.clip(proj[valid], -1000.0, 1000.0)
|
||||||
|
proj[~valid] = np.nan
|
||||||
|
out[:w] = proj
|
||||||
|
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def _normalize_by_calib(raw: np.ndarray, calib: np.ndarray, norm_type: str) -> np.ndarray:
|
||||||
|
"""Нормировка свипа по выбранному алгоритму."""
|
||||||
|
nt = str(norm_type).strip().lower()
|
||||||
|
if nt == "simple":
|
||||||
|
return _normalize_sweep_simple(raw, calib)
|
||||||
|
return _normalize_sweep_projector(raw, calib)
|
||||||
|
|
||||||
|
|
||||||
def try_open_pyserial(path: str, baud: int, timeout: float):
|
def try_open_pyserial(path: str, baud: int, timeout: float):
|
||||||
try:
|
try:
|
||||||
import serial # type: ignore
|
import serial # type: ignore
|
||||||
@ -532,6 +642,12 @@ def main():
|
|||||||
default="auto",
|
default="auto",
|
||||||
help="Графический бэкенд: pyqtgraph (pg) — быстрее; matplotlib (mpl) — совместимый. По умолчанию auto",
|
help="Графический бэкенд: pyqtgraph (pg) — быстрее; matplotlib (mpl) — совместимый. По умолчанию auto",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--norm-type",
|
||||||
|
choices=["projector", "simple"],
|
||||||
|
default="projector",
|
||||||
|
help="Тип нормировки: projector (по огибающим в [-1,+1]) или simple (raw/calib)",
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@ -592,6 +708,7 @@ def main():
|
|||||||
ymax_slider = None
|
ymax_slider = None
|
||||||
contrast_slider = None
|
contrast_slider = None
|
||||||
calib_enabled = False
|
calib_enabled = False
|
||||||
|
norm_type = str(getattr(args, "norm_type", "projector")).strip().lower()
|
||||||
cb = None
|
cb = None
|
||||||
|
|
||||||
# Статусная строка (внизу окна)
|
# Статусная строка (внизу окна)
|
||||||
@ -610,7 +727,7 @@ def main():
|
|||||||
line_calib_obj, = ax_line.plot([], [], lw=1, color="tab:red")
|
line_calib_obj, = ax_line.plot([], [], lw=1, color="tab:red")
|
||||||
line_norm_obj, = ax_line.plot([], [], lw=1, color="tab:green")
|
line_norm_obj, = ax_line.plot([], [], lw=1, color="tab:green")
|
||||||
ax_line.set_title("Сырые данные", pad=1)
|
ax_line.set_title("Сырые данные", pad=1)
|
||||||
ax_line.set_xlabel("F")
|
ax_line.set_xlabel("ГГц")
|
||||||
ax_line.set_ylabel("")
|
ax_line.set_ylabel("")
|
||||||
channel_text = ax_line.text(
|
channel_text = ax_line.text(
|
||||||
0.98,
|
0.98,
|
||||||
@ -626,8 +743,8 @@ def main():
|
|||||||
# Линейный график спектра текущего свипа
|
# Линейный график спектра текущего свипа
|
||||||
fft_line_obj, = ax_fft.plot([], [], lw=1)
|
fft_line_obj, = ax_fft.plot([], [], lw=1)
|
||||||
ax_fft.set_title("FFT", pad=1)
|
ax_fft.set_title("FFT", pad=1)
|
||||||
ax_fft.set_xlabel("X")
|
ax_fft.set_xlabel("Время")
|
||||||
ax_fft.set_ylabel("Амплитуда, дБ")
|
ax_fft.set_ylabel("дБ")
|
||||||
|
|
||||||
# Диапазон по Y для последнего свипа: авто по умолчанию (поддерживает отрицательные значения)
|
# Диапазон по Y для последнего свипа: авто по умолчанию (поддерживает отрицательные значения)
|
||||||
fixed_ylim: Optional[Tuple[float, float]] = None
|
fixed_ylim: Optional[Tuple[float, float]] = None
|
||||||
@ -651,7 +768,7 @@ def main():
|
|||||||
)
|
)
|
||||||
ax_img.set_title("Сырые данные", pad=12)
|
ax_img.set_title("Сырые данные", pad=12)
|
||||||
ax_img.set_xlabel("")
|
ax_img.set_xlabel("")
|
||||||
ax_img.set_ylabel("частота")
|
ax_img.set_ylabel("ГГц")
|
||||||
# Не показываем численные значения по времени на водопаде сырых данных
|
# Не показываем численные значения по времени на водопаде сырых данных
|
||||||
try:
|
try:
|
||||||
ax_img.tick_params(axis="x", labelbottom=False)
|
ax_img.tick_params(axis="x", labelbottom=False)
|
||||||
@ -674,15 +791,9 @@ def main():
|
|||||||
ax_spec.tick_params(axis="x", labelbottom=False)
|
ax_spec.tick_params(axis="x", labelbottom=False)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _normalize_sweep(raw: np.ndarray, calib: np.ndarray) -> np.ndarray:
|
def _normalize_sweep(raw: np.ndarray, calib: np.ndarray) -> np.ndarray:
|
||||||
w = min(raw.size, calib.size)
|
return _normalize_by_calib(raw, calib, norm_type=norm_type)
|
||||||
if w <= 0:
|
|
||||||
return raw
|
|
||||||
out = np.full_like(raw, np.nan, dtype=np.float32)
|
|
||||||
with np.errstate(divide="ignore", invalid="ignore"):
|
|
||||||
out[:w] = raw[:w] / calib[:w]
|
|
||||||
out = np.nan_to_num(out, nan=np.nan, posinf=np.nan, neginf=np.nan)
|
|
||||||
return out
|
|
||||||
|
|
||||||
def _set_calib_enabled():
|
def _set_calib_enabled():
|
||||||
nonlocal calib_enabled, current_sweep_norm
|
nonlocal calib_enabled, current_sweep_norm
|
||||||
@ -734,15 +845,15 @@ def main():
|
|||||||
if ring is not None:
|
if ring is not None:
|
||||||
return
|
return
|
||||||
width = WF_WIDTH
|
width = WF_WIDTH
|
||||||
x_shared = np.arange(width, dtype=np.int32)
|
x_shared = np.linspace(3.3, 14.3, width, dtype=np.float32)
|
||||||
ring = np.full((max_sweeps, width), np.nan, dtype=np.float32)
|
ring = np.full((max_sweeps, width), np.nan, dtype=np.float32)
|
||||||
ring_time = np.full((max_sweeps,), np.nan, dtype=np.float64)
|
ring_time = np.full((max_sweeps,), np.nan, dtype=np.float64)
|
||||||
head = 0
|
head = 0
|
||||||
# Обновляем изображение под новые размеры: время по X (горизонталь), X по Y
|
# Обновляем изображение под новые размеры: время по X (горизонталь), X по Y
|
||||||
img_obj.set_data(np.zeros((width, max_sweeps), dtype=np.float32))
|
img_obj.set_data(np.zeros((width, max_sweeps), dtype=np.float32))
|
||||||
img_obj.set_extent((0, max_sweeps - 1, 0, width - 1 if width > 0 else 1))
|
img_obj.set_extent((0, max_sweeps - 1, 3.3, 14.3))
|
||||||
ax_img.set_xlim(0, max_sweeps - 1)
|
ax_img.set_xlim(0, max_sweeps - 1)
|
||||||
ax_img.set_ylim(0, max(1, width - 1))
|
ax_img.set_ylim(3.3, 14.3)
|
||||||
# FFT буферы: время по X, бин по Y
|
# FFT буферы: время по X, бин по Y
|
||||||
ring_fft = np.full((max_sweeps, fft_bins), np.nan, dtype=np.float32)
|
ring_fft = np.full((max_sweeps, fft_bins), np.nan, dtype=np.float32)
|
||||||
img_fft_obj.set_data(np.zeros((fft_bins, max_sweeps), dtype=np.float32))
|
img_fft_obj.set_data(np.zeros((fft_bins, max_sweeps), dtype=np.float32))
|
||||||
@ -814,7 +925,7 @@ def main():
|
|||||||
# Окно Хэннинга
|
# Окно Хэннинга
|
||||||
win = np.hanning(take_fft).astype(np.float32)
|
win = np.hanning(take_fft).astype(np.float32)
|
||||||
fft_in[:take_fft] = seg * win
|
fft_in[:take_fft] = seg * win
|
||||||
spec = np.fft.rfft(fft_in)
|
spec = np.fft.ifft(fft_in)
|
||||||
mag = np.abs(spec).astype(np.float32)
|
mag = np.abs(spec).astype(np.float32)
|
||||||
fft_row = 20.0 * np.log10(mag + 1e-9)
|
fft_row = 20.0 * np.log10(mag + 1e-9)
|
||||||
if fft_row.shape[0] != bins:
|
if fft_row.shape[0] != bins:
|
||||||
@ -917,8 +1028,8 @@ def main():
|
|||||||
line_norm_obj.set_data(xs[: current_sweep_norm.size], current_sweep_norm)
|
line_norm_obj.set_data(xs[: current_sweep_norm.size], current_sweep_norm)
|
||||||
else:
|
else:
|
||||||
line_norm_obj.set_data([], [])
|
line_norm_obj.set_data([], [])
|
||||||
# Лимиты по X постоянные под текущую ширину
|
# Лимиты по X: 3.3 ГГц .. 14.3 ГГц
|
||||||
ax_line.set_xlim(0, max(1, current_sweep_raw.size - 1))
|
ax_line.set_xlim(3.3, 14.3)
|
||||||
# Адаптивные Y-лимиты (если не задан --ylim)
|
# Адаптивные Y-лимиты (если не задан --ylim)
|
||||||
if fixed_ylim is None:
|
if fixed_ylim is None:
|
||||||
y0 = float(np.nanmin(current_sweep_raw))
|
y0 = float(np.nanmin(current_sweep_raw))
|
||||||
@ -942,7 +1053,7 @@ def main():
|
|||||||
seg = np.nan_to_num(sweep_for_fft[:take_fft], nan=0.0).astype(np.float32, copy=False)
|
seg = np.nan_to_num(sweep_for_fft[:take_fft], nan=0.0).astype(np.float32, copy=False)
|
||||||
win = np.hanning(take_fft).astype(np.float32)
|
win = np.hanning(take_fft).astype(np.float32)
|
||||||
fft_in[:take_fft] = seg * win
|
fft_in[:take_fft] = seg * win
|
||||||
spec = np.fft.rfft(fft_in)
|
spec = np.fft.ifft(fft_in)
|
||||||
mag = np.abs(spec).astype(np.float32)
|
mag = np.abs(spec).astype(np.float32)
|
||||||
fft_vals = 20.0 * np.log10(mag + 1e-9)
|
fft_vals = 20.0 * np.log10(mag + 1e-9)
|
||||||
xs_fft = freq_shared
|
xs_fft = freq_shared
|
||||||
@ -951,7 +1062,7 @@ def main():
|
|||||||
fft_line_obj.set_data(xs_fft[: fft_vals.size], fft_vals)
|
fft_line_obj.set_data(xs_fft[: fft_vals.size], fft_vals)
|
||||||
# Авто-диапазон по Y для спектра
|
# Авто-диапазон по Y для спектра
|
||||||
if np.isfinite(np.nanmin(fft_vals)) and np.isfinite(np.nanmax(fft_vals)):
|
if np.isfinite(np.nanmin(fft_vals)) and np.isfinite(np.nanmax(fft_vals)):
|
||||||
ax_fft.set_xlim(0, max(1, xs_fft.size - 1))
|
ax_fft.set_xlim(0, max(1, xs_fft.size - 1) * 1.5)
|
||||||
ax_fft.set_ylim(float(np.nanmin(fft_vals)), float(np.nanmax(fft_vals)))
|
ax_fft.set_ylim(float(np.nanmin(fft_vals)), float(np.nanmax(fft_vals)))
|
||||||
|
|
||||||
# Обновление водопада
|
# Обновление водопада
|
||||||
@ -1077,7 +1188,7 @@ def run_pyqtgraph(args):
|
|||||||
curve = p_line.plot(pen=pg.mkPen((80, 120, 255), width=1))
|
curve = p_line.plot(pen=pg.mkPen((80, 120, 255), width=1))
|
||||||
curve_calib = p_line.plot(pen=pg.mkPen((220, 60, 60), width=1))
|
curve_calib = p_line.plot(pen=pg.mkPen((220, 60, 60), width=1))
|
||||||
curve_norm = p_line.plot(pen=pg.mkPen((60, 180, 90), width=1))
|
curve_norm = p_line.plot(pen=pg.mkPen((60, 180, 90), width=1))
|
||||||
p_line.setLabel("bottom", "X")
|
p_line.setLabel("bottom", "ГГц")
|
||||||
p_line.setLabel("left", "Y")
|
p_line.setLabel("left", "Y")
|
||||||
ch_text = pg.TextItem("", anchor=(1, 1))
|
ch_text = pg.TextItem("", anchor=(1, 1))
|
||||||
ch_text.setZValue(10)
|
ch_text.setZValue(10)
|
||||||
@ -1092,7 +1203,7 @@ def run_pyqtgraph(args):
|
|||||||
p_img.getAxis("bottom").setStyle(showValues=False)
|
p_img.getAxis("bottom").setStyle(showValues=False)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
p_img.setLabel("left", "X (0 снизу)")
|
p_img.setLabel("left", "ГГц")
|
||||||
img = pg.ImageItem()
|
img = pg.ImageItem()
|
||||||
p_img.addItem(img)
|
p_img.addItem(img)
|
||||||
|
|
||||||
@ -1100,8 +1211,8 @@ def run_pyqtgraph(args):
|
|||||||
p_fft = win.addPlot(row=1, col=0, title="FFT")
|
p_fft = win.addPlot(row=1, col=0, title="FFT")
|
||||||
p_fft.showGrid(x=True, y=True, alpha=0.3)
|
p_fft.showGrid(x=True, y=True, alpha=0.3)
|
||||||
curve_fft = p_fft.plot(pen=pg.mkPen((255, 120, 80), width=1))
|
curve_fft = p_fft.plot(pen=pg.mkPen((255, 120, 80), width=1))
|
||||||
p_fft.setLabel("bottom", "Бин")
|
p_fft.setLabel("bottom", "Время")
|
||||||
p_fft.setLabel("left", "Амплитуда, дБ")
|
p_fft.setLabel("left", "дБ")
|
||||||
|
|
||||||
# Водопад спектров (справа-снизу)
|
# Водопад спектров (справа-снизу)
|
||||||
p_spec = win.addPlot(row=1, col=1, title="B-scan (дБ)")
|
p_spec = win.addPlot(row=1, col=1, title="B-scan (дБ)")
|
||||||
@ -1146,6 +1257,7 @@ def run_pyqtgraph(args):
|
|||||||
spec_clip = _parse_spec_clip(getattr(args, "spec_clip", None))
|
spec_clip = _parse_spec_clip(getattr(args, "spec_clip", None))
|
||||||
spec_mean_sec = float(getattr(args, "spec_mean_sec", 0.0))
|
spec_mean_sec = float(getattr(args, "spec_mean_sec", 0.0))
|
||||||
calib_enabled = False
|
calib_enabled = False
|
||||||
|
norm_type = str(getattr(args, "norm_type", "projector")).strip().lower()
|
||||||
# Диапазон по Y: авто по умолчанию (поддерживает отрицательные значения)
|
# Диапазон по Y: авто по умолчанию (поддерживает отрицательные значения)
|
||||||
fixed_ylim: Optional[Tuple[float, float]] = None
|
fixed_ylim: Optional[Tuple[float, float]] = None
|
||||||
if args.ylim:
|
if args.ylim:
|
||||||
@ -1158,14 +1270,7 @@ def run_pyqtgraph(args):
|
|||||||
p_line.setYRange(fixed_ylim[0], fixed_ylim[1], padding=0)
|
p_line.setYRange(fixed_ylim[0], fixed_ylim[1], padding=0)
|
||||||
|
|
||||||
def _normalize_sweep(raw: np.ndarray, calib: np.ndarray) -> np.ndarray:
|
def _normalize_sweep(raw: np.ndarray, calib: np.ndarray) -> np.ndarray:
|
||||||
w = min(raw.size, calib.size)
|
return _normalize_by_calib(raw, calib, norm_type=norm_type)
|
||||||
if w <= 0:
|
|
||||||
return raw
|
|
||||||
out = np.full_like(raw, np.nan, dtype=np.float32)
|
|
||||||
with np.errstate(divide="ignore", invalid="ignore"):
|
|
||||||
out[:w] = raw[:w] / calib[:w]
|
|
||||||
out = np.nan_to_num(out, nan=np.nan, posinf=np.nan, neginf=np.nan)
|
|
||||||
return out
|
|
||||||
|
|
||||||
def _set_calib_enabled():
|
def _set_calib_enabled():
|
||||||
nonlocal calib_enabled, current_sweep_norm
|
nonlocal calib_enabled, current_sweep_norm
|
||||||
@ -1188,14 +1293,15 @@ def run_pyqtgraph(args):
|
|||||||
if ring is not None:
|
if ring is not None:
|
||||||
return
|
return
|
||||||
width = WF_WIDTH
|
width = WF_WIDTH
|
||||||
x_shared = np.arange(width, dtype=np.int32)
|
x_shared = np.linspace(3.3, 14.3, width, dtype=np.float32)
|
||||||
ring = np.full((max_sweeps, width), np.nan, dtype=np.float32)
|
ring = np.full((max_sweeps, width), np.nan, dtype=np.float32)
|
||||||
ring_time = np.full((max_sweeps,), np.nan, dtype=np.float64)
|
ring_time = np.full((max_sweeps,), np.nan, dtype=np.float64)
|
||||||
head = 0
|
head = 0
|
||||||
# Водопад: время по оси X, X по оси Y
|
# Водопад: время по оси X, X по оси Y (ось Y: 3.3..14.3 ГГц)
|
||||||
img.setImage(ring.T, autoLevels=False)
|
img.setImage(ring.T, autoLevels=False)
|
||||||
p_img.setRange(xRange=(0, max_sweeps - 1), yRange=(0, max(1, width - 1)), padding=0)
|
img.setRect(0, 3.3, max_sweeps, 14.3 - 3.3)
|
||||||
p_line.setXRange(0, max(1, width - 1), padding=0)
|
p_img.setRange(xRange=(0, max_sweeps - 1), yRange=(3.3, 14.3), padding=0)
|
||||||
|
p_line.setXRange(3.3, 14.3, padding=0)
|
||||||
# FFT: время по оси X, бин по оси Y
|
# FFT: время по оси X, бин по оси Y
|
||||||
ring_fft = np.full((max_sweeps, fft_bins), np.nan, dtype=np.float32)
|
ring_fft = np.full((max_sweeps, fft_bins), np.nan, dtype=np.float32)
|
||||||
img_fft.setImage(ring_fft.T, autoLevels=False)
|
img_fft.setImage(ring_fft.T, autoLevels=False)
|
||||||
@ -1255,7 +1361,7 @@ def run_pyqtgraph(args):
|
|||||||
seg = np.nan_to_num(s[:take_fft], nan=0.0).astype(np.float32, copy=False)
|
seg = np.nan_to_num(s[:take_fft], nan=0.0).astype(np.float32, copy=False)
|
||||||
win = np.hanning(take_fft).astype(np.float32)
|
win = np.hanning(take_fft).astype(np.float32)
|
||||||
fft_in[:take_fft] = seg * win
|
fft_in[:take_fft] = seg * win
|
||||||
spec = np.fft.rfft(fft_in)
|
spec = np.fft.ifft(fft_in)
|
||||||
mag = np.abs(spec).astype(np.float32)
|
mag = np.abs(spec).astype(np.float32)
|
||||||
fft_row = 20.0 * np.log10(mag + 1e-9)
|
fft_row = 20.0 * np.log10(mag + 1e-9)
|
||||||
if fft_row.shape[0] != bins:
|
if fft_row.shape[0] != bins:
|
||||||
@ -1341,13 +1447,14 @@ def run_pyqtgraph(args):
|
|||||||
seg = np.nan_to_num(sweep_for_fft[:take_fft], nan=0.0).astype(np.float32, copy=False)
|
seg = np.nan_to_num(sweep_for_fft[:take_fft], nan=0.0).astype(np.float32, copy=False)
|
||||||
win = np.hanning(take_fft).astype(np.float32)
|
win = np.hanning(take_fft).astype(np.float32)
|
||||||
fft_in[:take_fft] = seg * win
|
fft_in[:take_fft] = seg * win
|
||||||
spec = np.fft.rfft(fft_in)
|
spec = np.fft.ifft(fft_in)
|
||||||
mag = np.abs(spec).astype(np.float32)
|
mag = np.abs(spec).astype(np.float32)
|
||||||
fft_vals = 20.0 * np.log10(mag + 1e-9)
|
fft_vals = 20.0 * np.log10(mag + 1e-9)
|
||||||
xs_fft = freq_shared
|
xs_fft = freq_shared
|
||||||
if fft_vals.size > xs_fft.size:
|
if fft_vals.size > xs_fft.size:
|
||||||
fft_vals = fft_vals[: xs_fft.size]
|
fft_vals = fft_vals[: xs_fft.size]
|
||||||
curve_fft.setData(xs_fft[: fft_vals.size], fft_vals)
|
curve_fft.setData(xs_fft[: fft_vals.size], fft_vals)
|
||||||
|
p_fft.setXRange(0, max(1, xs_fft.size - 1) * 1.5, padding=0)
|
||||||
p_fft.setYRange(float(np.nanmin(fft_vals)), float(np.nanmax(fft_vals)), padding=0)
|
p_fft.setYRange(float(np.nanmin(fft_vals)), float(np.nanmax(fft_vals)), padding=0)
|
||||||
|
|
||||||
if changed and ring is not None:
|
if changed and ring is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user