diff options
author | andreas128 <Andreas> | 2017-09-05 10:02:59 +0200 |
---|---|---|
committer | andreas128 <Andreas> | 2017-09-05 10:18:05 +0200 |
commit | 1b6c5dd58658bbc1b423b50baa15ca3fae6a1065 (patch) | |
tree | 0b457a2bc92d295970a94640fa7fe63844c489a6 /dpd | |
parent | b9aab4c9ab542823ec751e32ea7462428d98419c (diff) | |
download | dabmod-1b6c5dd58658bbc1b423b50baa15ca3fae6a1065.tar.gz dabmod-1b6c5dd58658bbc1b423b50baa15ca3fae6a1065.tar.bz2 dabmod-1b6c5dd58658bbc1b423b50baa15ca3fae6a1065.zip |
Change max to meadian in TX_Agc
Diffstat (limited to 'dpd')
-rwxr-xr-x | dpd/main.py | 6 | ||||
-rw-r--r-- | dpd/src/Adapt.py | 2 | ||||
-rw-r--r-- | dpd/src/TX_Agc.py | 43 |
3 files changed, 25 insertions, 26 deletions
diff --git a/dpd/main.py b/dpd/main.py index 5e4f29f..ad42cb6 100755 --- a/dpd/main.py +++ b/dpd/main.py @@ -61,7 +61,7 @@ parser.add_argument('--samplerate', default='8192000', parser.add_argument('--coefs', default='poly.coef', help='File with DPD coefficients, which will be read by ODR-DabMod', required=False) -parser.add_argument('--txgain', default=65, +parser.add_argument('--txgain', default=60, help='TX Gain', required=False, type=int) @@ -69,7 +69,7 @@ parser.add_argument('--rxgain', default=30, help='TX Gain', required=False, type=int) -parser.add_argument('--digital_gain', default=1.0, +parser.add_argument('--digital_gain', default=0.2, help='Digital Gain', required=False, type=float) @@ -106,7 +106,7 @@ coefs_am, coefs_pm = adapt.get_coefs() if cli_args.load_poly: model = Model.Model(coefs_am, coefs_pm, plot=True) else: - model = Model.Model([1, 0, 0, 0, 0], [0, 0, 0, 0, 0], plot=True) + model = Model.Model([1.0, 0, 0, 0, 0], [0, 0, 0, 0, 0], plot=True) adapt.set_txgain(digital_gain) adapt.set_txgain(txgain) adapt.set_rxgain(rxgain) 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 |