summaryrefslogtreecommitdiffstats
path: root/python/dpd
diff options
context:
space:
mode:
Diffstat (limited to 'python/dpd')
-rw-r--r--python/dpd/GlobalConfig.py9
-rw-r--r--python/dpd/RX_Agc.py45
2 files changed, 32 insertions, 22 deletions
diff --git a/python/dpd/GlobalConfig.py b/python/dpd/GlobalConfig.py
index abd7442..873b6ac 100644
--- a/python/dpd/GlobalConfig.py
+++ b/python/dpd/GlobalConfig.py
@@ -10,9 +10,9 @@
import numpy as np
class GlobalConfig:
- def __init__(self, args, plot_location: str):
- self.sample_rate = args['samplerate']
- assert self.sample_rate == 8192000 # By now only constants for 8192000
+ def __init__(self, samplerate, plot_location: str):
+ self.sample_rate = samplerate
+ assert self.sample_rate == 8192000, "We only support constants for 8192000 sample rate: {}".format(self.sample_rate)
self.plot_location = plot_location
plot = len(plot_location) > 0
@@ -77,12 +77,13 @@ class GlobalConfig:
# Constants for RX_AGC
self.RAGC_min_rxgain = 25 # USRP B200 specific
+ self.RAGC_max_rxgain = 65 # USRP B200 specific
self.RAGC_rx_median_target = 0.05
# The MIT License (MIT)
#
# Copyright (c) 2017 Andreas Steger
-# Copyright (c) 2017 Matthias P. Braendli
+# Copyright (c) 2018 Matthias P. Braendli
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
diff --git a/python/dpd/RX_Agc.py b/python/dpd/RX_Agc.py
index 0cc18b8..2a2f548 100644
--- a/python/dpd/RX_Agc.py
+++ b/python/dpd/RX_Agc.py
@@ -13,6 +13,7 @@ import numpy as np
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
+from typing import Tuple
import dpd.Adapt as Adapt
import dpd.Measure as Measure
@@ -39,31 +40,39 @@ class Agc:
self.measure = measure
self.adapt = adapt
self.min_rxgain = c.RAGC_min_rxgain
+ self.max_rxgain = c.RAGC_max_rxgain
self.rxgain = self.min_rxgain
self.peak_to_median = 1./c.RAGC_rx_median_target
- def run(self):
+ def run(self) -> Tuple[bool, str]:
self.adapt.set_rxgain(self.rxgain)
- for i in range(2):
- # Measure
- txframe_aligned, tx_ts, rxframe_aligned, rx_ts, rx_median= \
- self.measure.get_samples()
-
- # Estimate Maximum
- rx_peak = self.peak_to_median * rx_median
- correction_factor = 20*np.log10(1/rx_peak)
- self.rxgain = self.rxgain + correction_factor
-
- assert self.min_rxgain <= self.rxgain, ("Desired RX Gain is {} which is smaller than the minimum of {}".format(
- self.rxgain, self.min_rxgain))
-
- logging.info("RX Median {:1.4f}, estimated peak {:1.4f}, correction factor {:1.4f}, new RX gain {:1.4f}".format(
- rx_median, rx_peak, correction_factor, self.rxgain
- ))
-
+ # Measure
+ txframe_aligned, tx_ts, rxframe_aligned, rx_ts, rx_median=self.measure.get_samples()
+
+ # Estimate Maximum
+ rx_peak = self.peak_to_median * rx_median
+ correction_factor = 20*np.log10(1/rx_peak)
+ self.rxgain = self.rxgain + correction_factor
+
+ measurements = "RX Median {:1.4f}, estimated peak {:1.4f}, correction factor {:1.4f}, new RX gain {:1.4f}".format(
+ rx_median, rx_peak, correction_factor, self.rxgain)
+ logging.info(measurements)
+
+ if self.rxgain < self.min_rxgain:
+ w = "Warning: calculated RX Gain={} is lower than minimum={}. RX feedback power is too high!".format(
+ self.rxgain, self.min_rxgain)
+ logging.warning(w)
+ return (False, "\n".join([measurements, w]))
+ elif self.rxgain > self.max_rxgain:
+ w = "Warning: calculated RX Gain={} is higher than maximum={}. RX feedback power should be increased.".format(
+ self.rxgain, self.max_rxgain)
+ logging.warning(w)
+ return (False, "\n".join([measurements, w]))
+ else:
self.adapt.set_rxgain(self.rxgain)
time.sleep(0.5)
+ return (True, measurements)
def plot_estimates(self):
"""Plots the estimate of for Max, Median, Mean for different