aboutsummaryrefslogtreecommitdiffstats
path: root/dpd/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'dpd/main.py')
-rwxr-xr-xdpd/main.py69
1 files changed, 47 insertions, 22 deletions
diff --git a/dpd/main.py b/dpd/main.py
index 208a4ff..084ccd5 100755
--- a/dpd/main.py
+++ b/dpd/main.py
@@ -13,7 +13,7 @@ predistortion module of ODR-DabMod."""
import datetime
import os
import time
-
+import sys
import matplotlib
matplotlib.use('GTKAgg')
@@ -43,7 +43,6 @@ import traceback
import src.Measure as Measure
import src.Model as Model
import src.ExtractStatistic as ExtractStatistic
-import src.Model_Poly
import src.Adapt as Adapt
import src.Agc as Agc
import src.TX_Agc as TX_Agc
@@ -84,8 +83,8 @@ parser.add_argument('--samps', default='81920', type=int,
parser.add_argument('-i', '--iterations', default=1, type=int,
help='Number of iterations to run',
required=False)
-parser.add_argument('-l', '--load-poly',
- help='Load existing polynomial',
+parser.add_argument('-L', '--lut',
+ help='Use lookup table instead of polynomial predistorter',
action="store_true")
cli_args = parser.parse_args()
@@ -107,13 +106,13 @@ c = src.const.const(samplerate)
meas = Measure.Measure(samplerate, port, num_req)
extStat = ExtractStatistic.ExtractStatistic(c, plot=True)
adapt = Adapt.Adapt(port_rc, coef_path)
+dpddata = adapt.get_predistorter()
-coefs_am, coefs_pm = adapt.get_coefs()
-model_poly = src.Model_Poly.Model_Poly(c, coefs_am, coefs_pm, plot=True)
-if not cli_args.load_poly:
- coefs_am, coefs_pm = model_poly.get_default_coefs()
-
-adapt.set_coefs(model_poly.coefs_am, model_poly.coefs_pm)
+if cli_args.lut:
+ model = Model.Lut(c, plot=True)
+else:
+ model = Model.Poly(c, plot=True)
+adapt.set_predistorter(model.get_dpd_data())
adapt.set_digital_gain(digital_gain)
adapt.set_txgain(txgain)
adapt.set_rxgain(rxgain)
@@ -121,13 +120,28 @@ adapt.set_rxgain(rxgain)
tx_gain = adapt.get_txgain()
rx_gain = adapt.get_rxgain()
digital_gain = adapt.get_digital_gain()
-dpd_coefs_am, dpd_coefs_pm = adapt.get_coefs()
-logging.info(
- "TX gain {}, RX gain {}, dpd_coefs_am {},"
- " dpd_coefs_pm {}, digital_gain {}".format(
- tx_gain, rx_gain, dpd_coefs_am, dpd_coefs_pm, digital_gain
+
+dpddata = adapt.get_predistorter()
+if dpddata[0] == "poly":
+ coefs_am = dpddata[1]
+ coefs_pm = dpddata[2]
+ logging.info(
+ "TX gain {}, RX gain {}, dpd_coefs_am {},"
+ " dpd_coefs_pm {}, digital_gain {}".format(
+ tx_gain, rx_gain, coefs_am, coefs_pm, digital_gain
+ )
)
-)
+elif dpddata[0] == "lut":
+ scalefactor = dpddata[1]
+ lut = dpddata[2]
+ logging.info(
+ "TX gain {}, RX gain {}, LUT scalefactor {},"
+ " LUT {}, digital_gain {}".format(
+ tx_gain, rx_gain, scalefactor, lut, digital_gain
+ )
+ )
+else:
+ logging.error("Unknown dpd data format {}".format(dpddata[0]))
tx_agc = TX_Agc.TX_Agc(adapt)
@@ -154,14 +168,14 @@ while i < num_iter:
# Model
elif state == "model":
- coefs_am, coefs_pm = model_poly.get_next_coefs(tx, rx, phase_diff)
+ dpddata = model_poly.get_dpd_data(tx, rx, phase_diff)
del extStat
extStat = ExtractStatistic.ExtractStatistic(c, plot=True)
state = "adapt"
# Adapt
elif state == "adapt":
- adapt.set_coefs(coefs_am, coefs_pm)
+ adapt.set_predistorter(dpddata)
state = "report"
i += 1
@@ -172,9 +186,19 @@ while i < num_iter:
tx_mer = MER.calc_mer(txframe_aligned[off:off+c.T_U], debug=True)
rx_mer = MER.calc_mer(rxframe_aligned[off:off+c.T_U], debug=True)
mse = np.mean(np.abs((txframe_aligned - rxframe_aligned)**2))
- logging.info("It {}: TX_MER {}, RX_MER {}," \
- " MSE {}, coefs_am {}, coefs_pm {}".
- format(i, tx_mer, rx_mer, mse, coefs_am, coefs_pm))
+
+ if dpddata[0] == "poly":
+ coefs_am = dpddata[1]
+ coefs_pm = dpddata[2]
+ logging.info("It {}: TX_MER {}, RX_MER {}," \
+ " MSE {}, coefs_am {}, coefs_pm {}".
+ format(i, tx_mer, rx_mer, mse, coefs_am, coefs_pm))
+ if dpddata[0] == "lut":
+ scalefactor = dpddata[1]
+ lut = dpddata[2]
+ logging.info("It {}: TX_MER {}, RX_MER {}," \
+ " MSE {}, LUT scalefactor {}, LUT {}".
+ format(i, tx_mer, rx_mer, mse, scalefactor, lut))
state = "measure"
except:
logging.warning("Iteration {}: Report failed.".format(i))
@@ -187,7 +211,8 @@ while i < num_iter:
# The MIT License (MIT)
#
-# Copyright (c) 2017 Andreas Steger, Matthias P. Braendli
+# Copyright (c) 2017 Andreas Steger
+# Copyright (c) 2017 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