From 1b6c5dd58658bbc1b423b50baa15ca3fae6a1065 Mon Sep 17 00:00:00 2001 From: andreas128 Date: Tue, 5 Sep 2017 10:02:59 +0200 Subject: Change max to meadian in TX_Agc --- dpd/src/Adapt.py | 2 +- dpd/src/TX_Agc.py | 43 +++++++++++++++++++++---------------------- 2 files changed, 22 insertions(+), 23 deletions(-) (limited to 'dpd/src') diff --git a/dpd/src/Adapt.py b/dpd/src/Adapt.py index 78eaa9e..5e05112 100644 --- a/dpd/src/Adapt.py +++ b/dpd/src/Adapt.py @@ -90,7 +90,7 @@ class Adapt: def get_txgain(self): """Get the txgain value in dB for the ODR-DabMod.""" # TODO handle failure - return int(self.send_receive("get uhd txgain")[0]) + return float(self.send_receive("get uhd txgain")[0]) def set_rxgain(self, gain): """Set a new rxgain for the ODR-DabMod. diff --git a/dpd/src/TX_Agc.py b/dpd/src/TX_Agc.py index 832c4d4..6f4cee8 100644 --- a/dpd/src/TX_Agc.py +++ b/dpd/src/TX_Agc.py @@ -19,52 +19,51 @@ matplotlib.use('agg') import matplotlib.pyplot as plt import src.Adapt as Adapt -import src.Measure as Measure - #TODO fix for float tx_gain class TX_Agc: def __init__(self, adapt, - max_txgain=70, - tx_max_target=0.85, - tx_max_threshold_max=0.95, - tx_max_threshold_min=0.65): + max_txgain=80, + tx_median_target=0.1, + tx_median_threshold_max=0.15, + tx_median_threshold_min=0.05): """ In order to avoid digital clipping, this class increases the TX gain and reduces the digital gain. Digital clipping happens when the digital analog converter receives values greater than it's maximal output. This class solves that problem by adapting the TX gain in a way that the peaks of the TX signal are in a - specified range. The TX gain is adapted accordingly. + specified range. The TX gain is adapted accordingly. The TX peaks + are approximated by estimating it based on the signal median. :param adapt: Instance of Adapt Class to update txgain and coefficients :param max_txgain: limit for TX gain - :param tx_max_threshold_max: if the maximum of TX is larger + :param tx_median_threshold_max: if the median of TX is larger than this value, then the digital gain is reduced - :param tx_max_threshold_min: if the maximum of TX is smaller + :param tx_median_threshold_min: if the median of TX is smaller than this value, then the digital gain is increased - :param tx_max_target: The digital gain is reduced in a way that - the maximal TX value is expected to be lower than this value. + :param tx_median_target: The digital gain is reduced in a way that + the median TX value is expected to be lower than this value. """ assert isinstance(adapt, Adapt.Adapt) self.adapt = adapt self.max_txgain = max_txgain self.txgain = self.max_txgain - assert tx_max_threshold_max > tx_max_target,\ - "The tolerated tx_max has to be larger then the goal tx_max" - self.tx_max_threshold_tolerate_max = tx_max_threshold_max - self.tx_max_threshold_tolerate_min = tx_max_threshold_min - self.tx_max_target = tx_max_target + assert tx_median_threshold_max > tx_median_target,\ + "The tolerated tx_median has to be larger then the goal tx_median" + self.tx_median_threshold_tolerate_max = tx_median_threshold_max + self.tx_median_threshold_tolerate_min = tx_median_threshold_min + self.tx_median_target = tx_median_target def adapt_if_necessary(self, tx): - tx_max = np.max(np.abs(tx)) - if tx_max > self.tx_max_threshold_tolerate_max or\ - tx_max < self.tx_max_threshold_tolerate_min: + tx_median = np.median(np.abs(tx)) + if tx_median > self.tx_median_threshold_tolerate_max or\ + tx_median < self.tx_median_threshold_tolerate_min: delta_db = \ - np.floor(20 * np.log10(self.tx_max_target / tx_max)).astype(int) + np.floor(20 * np.log10(self.tx_median_target / tx_median)).astype(int) new_txgain = self.adapt.get_txgain() - delta_db assert new_txgain < self.max_txgain,\ "TX_Agc failed. New TX gain of {} is too large.".format( @@ -79,10 +78,10 @@ class TX_Agc: logging.info( "digital_gain = {}, txgain_new = {}, " \ - "delta_db = {}, tx_max {}, " \ + "delta_db = {}, tx_median {}, " \ "digital_gain_factor = {}". format(digital_gain, txgain, delta_db, - tx_max, digital_gain_factor)) + tx_median, digital_gain_factor)) time.sleep(1) return True -- cgit v1.2.3