From 383fe3ceeaf1dabea2a1584ce6d3a660eb520cf5 Mon Sep 17 00:00:00 2001 From: Brendan Haines Date: Sat, 12 Apr 2025 23:04:59 -0600 Subject: [PATCH] slight power cal improvement --- charon_vna/vna.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/charon_vna/vna.py b/charon_vna/vna.py index b3bc2f6..d2d68f0 100644 --- a/charon_vna/vna.py +++ b/charon_vna/vna.py @@ -189,22 +189,20 @@ class Charon: ) def set_output_power(self, power: float): - # FIXME: this is a hack because I don't want to go through re-calibration - if power == 5: - tx_gain = -1 - elif power == 0: - tx_gain = -7 - elif power == -5: - tx_gain = -12 - elif power == -10: - tx_gain = -17 - elif power == -15: - tx_gain = -22 - else: - raise NotImplementedError() - # # TODO: correct over frequency - # tx_gain_idx = np.abs(pout.sel(tx_channel=0) - power).argmin(dim="tx_gain") - # tx_gain = pout.coords["tx_gain"][tx_gain_idx] + pout = xr.DataArray( + [-15, -10, -5, 0, 5], + dims=["tx_gain"], + coords=dict( + # TODO: correct over frequency + frequency=1e9, # FIXME: I'm not sure at what frequency I generated this table + tx_channel=0, + tx_gain=[-22, -17, -12, -7, -1], + ), + ) + + tx_gain_idx = np.abs(pout - power).argmin(dim="tx_gain") + tx_gain = pout.coords["tx_gain"][tx_gain_idx] + self.sdr.tx_hardwaregain_chan0 = float(tx_gain) def set_output(self, frequency: float, power: float):