Compare commits

...

4 Commits

Author SHA1 Message Date
18a1b2faa3 better tx tone
All checks were successful
Publish Python 🐍 distribution 📦 to PyPI and TestPyPI / Build distribution 📦 (push) Successful in 40s
Publish Python 🐍 distribution 📦 to PyPI and TestPyPI / Publish Python 🐍 distribution 📦 to PyPI (push) Has been skipped
2025-01-15 23:01:10 -07:00
c034cdcb95 document firmware versions 2025-01-15 22:59:29 -07:00
0c152c337e make vna.py importable 2025-01-15 22:23:54 -07:00
22a33c2b84 some config stuff 2025-01-15 22:14:27 -07:00
3 changed files with 211 additions and 161 deletions

View File

@ -39,7 +39,9 @@ Without this, you'll be limited to S11 and uncalibrated S21 measurements (with r
There's nothing special about this particular board, if you want more than 4 ports you can make your own pretty easily. You just need 3 SPxT switches. Note that these switches will see tons of cycles so avoid mechanical switches.
- SMA cables
### Pluto Modification
### Pluto Configuration
Most of my testing is with Pluto firmware [v0.39](https://github.com/analogdevicesinc/plutosdr-fw/releases/tag/v0.39) though this may work with other firmware versions. Instructions for upgrading firmware are on the [Analog Devices wiki](https://wiki.analog.com/university/tools/pluto/users/firmware).
We need two receive channels on the SDR. If you have a Pluto+ that should already be configured and you can skip this step.

View File

@ -14,6 +14,8 @@ from numpy import typing as npt
from PySide6.QtGui import QAction, QKeySequence
from PySide6.QtWidgets import (
QApplication,
QFileDialog,
QInputDialog,
QMainWindow,
QMenu,
QProgressBar,
@ -21,18 +23,19 @@ from PySide6.QtWidgets import (
QWidget,
)
from skrf import plotting as rf_plt
from vna import Charon
from charon_vna.gui_helpers import FlowLayout
from charon_vna.util import db20, s2vswr
# from vna import Charon
# %%
DEFAULT_CONFIG = dict(
frequency=np.arange(1e9, 2e9, 11), # Hz
power=-5, # dB
)
CONFIG_SUFFIX = ".json"
class PlotWidget(QWidget):
traces: List[Tuple[int | str]]
@ -157,6 +160,7 @@ class MainWindow(QMainWindow):
super().__init__()
self.config_path = None
self._frequency = np.linspace(1e9, 2e9, 101) # TODO: read frequency from config
# self.device = Charon("ip:192.168.3.1", frequency=DEFAULT_CONFIG["frequency"])
@ -169,10 +173,10 @@ class MainWindow(QMainWindow):
menu_file = QMenu("&File")
menubar.addMenu(menu_file)
action_load_config = QAction("&Open Configuration", self)
menu_file.addAction(action_load_config)
action_load_config.triggered.connect(self.load_config)
action_load_config.setShortcut(QKeySequence("Ctrl+O"))
action_open_config = QAction("&Open Configuration", self)
menu_file.addAction(action_open_config)
action_open_config.triggered.connect(self.open_config)
action_open_config.setShortcut(QKeySequence("Ctrl+O"))
action_save_config = QAction("&Save Configuration", self)
menu_file.addAction(action_save_config)
action_save_config.triggered.connect(self.save_config)
@ -186,7 +190,7 @@ class MainWindow(QMainWindow):
menubar.addMenu(menu_stimulus)
action_set_frequency = QAction("&Frequency", self)
menu_stimulus.addAction(action_set_frequency)
# action_set_frequency.triggered.connect(self.set_frequency)
action_set_frequency.triggered.connect(self.set_frequency)
action_set_power = QAction("&Power", self)
menu_stimulus.addAction(action_set_power)
# action_set_power.triggered.connect(self.set_power)
@ -230,24 +234,51 @@ class MainWindow(QMainWindow):
def saveas_config(self) -> None:
print("Prompting for save path...")
# TODO: prompt for config path
self.config_path = Path(__file__).parent / "config.json"
dialog = QFileDialog(self)
dialog.setDefaultSuffix(CONFIG_SUFFIX)
dialog.setAcceptMode(QFileDialog.AcceptMode.AcceptSave)
if dialog.exec():
config_path = Path(dialog.selectedFiles()[0])
print(config_path)
if config_path.suffix != CONFIG_SUFFIX:
raise ValueError(
f"{config_path.name} is not a valid configuration file. Must have extension {CONFIG_SUFFIX}"
)
self.config_path = config_path
print(f"Config path is now {self.config_path.resolve()}")
self.save_config()
def open_config(self) -> None:
print("Prompting for load path...")
dialog = QFileDialog(self)
dialog.setNameFilter(f"*{CONFIG_SUFFIX}")
dialog.setAcceptMode(QFileDialog.AcceptMode.AcceptOpen)
if dialog.exec():
config_path = Path(dialog.selectedFiles()[0])
print(config_path)
if config_path.suffix != CONFIG_SUFFIX:
raise ValueError(
f"{config_path.name} is not a valid configuration file. Must have extension {CONFIG_SUFFIX}"
)
self.config_path = config_path
print(f"Config path is now {self.config_path.resolve()}")
self.load_config(self.config_path)
def save_config(self) -> None:
if self.config_path is None:
self.saveas_config()
else:
print(f"saving config to {self.config_path.resolve()}")
print(f"Saving config to {self.config_path.resolve()}")
# TODO: save config
def load_config(self) -> None:
print("loading config")
def load_config(self, path: Path) -> None:
print(f"Loading config from {path}...")
# TODO: load config
def generate_sim_data(self) -> None:
coords = {"frequency": np.linspace(1e9, 2e9, 101), "m": [1], "n": [1]}
coords = {"frequency": self._frequency, "m": [1], "n": [1]}
shape = tuple(len(v) for v in coords.values())
data = xr.DataArray(
((-1 + 2 * np.random.rand(*shape)) + 1j * (-1 + 2 * np.random.rand(*shape))) / np.sqrt(2),
@ -258,6 +289,20 @@ class MainWindow(QMainWindow):
for plot in self.plots:
plot.update_plot(data)
def set_frequency(self, *, frequency: npt.ArrayLike | None = None):
print(frequency)
if frequency is None:
start, ok = QInputDialog.getDouble(
self, "Start Frequency", "Start Frequency", minValue=30e6, maxValue=6e9, value=1e9
)
stop, ok = QInputDialog.getDouble(
self, "Stop Frequency", "Stop Frequency", minValue=30e6, maxValue=6e9, value=2e9
)
points, ok = QInputDialog.getInt(self, "Points", "Points", minValue=2, value=101)
frequency = np.linspace(start, stop, points)
# Currently does not support zero span
self._frequency = frequency
def main() -> None:
app = QApplication(sys.argv)

View File

@ -4,7 +4,8 @@ from pathlib import Path
from typing import Any, Dict, Tuple
import adi
import iio
# import iio
import numpy as np
import skrf as rf
import xarray as xr
@ -140,8 +141,9 @@ class Charon:
self.set_output_power(power)
self.sdr.tx_lo = int(frequency - self.FREQUENCY_OFFSET)
self.sdr.tx_cyclic_buffer = True
# self.sdr.tx(generate_tone(f=self.FREQUENCY_OFFSET, fs=self.sdr.sample_rate))
self.sdr.dds_single_tone(self.FREQUENCY_OFFSET, scale=0.9, channel=0)
# For some reason the pluto's DDS has truly horrendous phase noise to the point where it looks modulated
self.sdr.tx(generate_tone(f=self.FREQUENCY_OFFSET, fs=self.sdr.sample_rate))
# self.sdr.dds_single_tone(self.FREQUENCY_OFFSET, scale=0.9, channel=0)
def _rx(self, count: int = 1, fc: float | None = None) -> npt.ArrayLike:
if count < 1:
@ -228,6 +230,10 @@ class Charon:
return s
# %%
if __name__ == "__main__":
pass
# %%
sdr = Charon("ip:192.168.3.1", frequency=np.linspace(1e9, 1.1e9, 11))
@ -287,7 +293,6 @@ plt.gca().xaxis.set_major_formatter(EngFormatter())
plt.grid(True)
plt.show()
# %%
s = sdr.vna_capture(frequency=np.linspace(70e6, 200e6, 101))
@ -322,7 +327,6 @@ if reference_sparams is not None:
plt.show()
# %% SOL calibration
cal_frequency = np.linspace(70e6, 600e6, 101)
ideal_cal_frequency = rf.Frequency(np.min(cal_frequency), np.max(cal_frequency), len(cal_frequency))
@ -343,7 +347,6 @@ calibration = rf.calibration.OnePort(
[cal_ideal.short(), cal_ideal.open(), cal_ideal.load(0)],
)
# %%
s = sdr.vna_capture(frequency=cal_frequency)