aboutsummaryrefslogtreecommitdiffstats
path: root/dpd
diff options
context:
space:
mode:
Diffstat (limited to 'dpd')
-rwxr-xr-xdpd/main.py33
-rw-r--r--dpd/src/Model_Poly.py104
2 files changed, 117 insertions, 20 deletions
diff --git a/dpd/main.py b/dpd/main.py
index e17cd5a..528f59c 100755
--- a/dpd/main.py
+++ b/dpd/main.py
@@ -42,9 +42,8 @@ import numpy as np
import traceback
import src.Measure as Measure
import src.Model as Model
-import src.Model_AM as Model_AM
-import src.Model_PM as Model_PM
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
@@ -91,15 +90,15 @@ parser.add_argument('-l', '--load-poly',
cli_args = parser.parse_args()
-port = int(cli_args.port)
-port_rc = int(cli_args.rc_port)
+port = cli_args.port
+port_rc = cli_args.rc_port
coef_path = cli_args.coefs
digital_gain = cli_args.digital_gain
txgain = cli_args.txgain
rxgain = cli_args.rxgain
-num_req = int(cli_args.samps)
-samplerate = int(cli_args.samplerate)
-num_iter = int(cli_args.iterations)
+num_req = cli_args.samps
+samplerate = cli_args.samplerate
+num_iter = cli_args.iterations
SA = src.Symbol_align.Symbol_align(samplerate)
MER = src.MER.MER(samplerate)
@@ -109,19 +108,15 @@ meas = Measure.Measure(samplerate, port, num_req)
extStat = ExtractStatistic.ExtractStatistic(c, plot=True)
adapt = Adapt.Adapt(port_rc, coef_path)
-if cli_args.load_poly:
- coefs_am, coefs_pm = adapt.get_coefs()
- model = Model.Model(c, SA, MER, coefs_am, coefs_pm, plot=True)
-else:
- coefs_am, coefs_pm = [[1.0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
- model = Model.Model(c, SA, MER, coefs_am, coefs_pm, plot=True)
-model_am = Model_AM.Model_AM(c, plot=True)
-model_pm = Model_PM.Model_PM(c, plot=True)
-adapt.set_coefs(model.coefs_am, model.coefs_pm)
+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)
adapt.set_digital_gain(digital_gain)
adapt.set_txgain(txgain)
adapt.set_rxgain(rxgain)
-print(coefs_am)
tx_gain = adapt.get_txgain()
rx_gain = adapt.get_rxgain()
@@ -159,15 +154,13 @@ while i < num_iter:
# Model
elif state == "model":
- coefs_am = model_am.get_next_coefs(tx, rx, coefs_am)
- coefs_pm = model_pm.get_next_coefs(tx, phase_diff, coefs_pm)
+ coefs_am, coefs_pm = model_poly.get_next_coefs(tx, rx, phase_diff)
del extStat
extStat = ExtractStatistic.ExtractStatistic(c, plot=True)
state = "adapt"
# Adapt
elif state == "adapt":
- print(coefs_am)
adapt.set_coefs(coefs_am, coefs_pm)
state = "measure"
i += 1
diff --git a/dpd/src/Model_Poly.py b/dpd/src/Model_Poly.py
index e69de29..1faff24 100644
--- a/dpd/src/Model_Poly.py
+++ b/dpd/src/Model_Poly.py
@@ -0,0 +1,104 @@
+# -*- coding: utf-8 -*-
+#
+# DPD Calculation Engine, model implementation using polynomial
+#
+# http://www.opendigitalradio.org
+# Licence: The MIT License, see notice at the end of this file
+
+import datetime
+import os
+import logging
+
+logging_path = os.path.dirname(logging.getLoggerClass().root.handlers[0].baseFilename)
+
+import numpy as np
+import matplotlib.pyplot as plt
+from sklearn import linear_model
+
+import src.Model_AM as Model_AM
+import src.Model_PM as Model_PM
+
+
+def assert_np_float32(x):
+ assert isinstance(x, np.ndarray)
+ assert x.dtype == np.float32
+ assert x.flags.contiguous
+
+def _check_input_get_next_coefs(tx_abs, rx_abs, phase_diff):
+ assert_np_float32(tx_abs)
+ assert_np_float32(rx_abs)
+ assert_np_float32(phase_diff)
+
+ assert tx_abs.shape == rx_abs.shape, \
+ "tx_abs.shape {}, rx_abs.shape {}".format(
+ tx_abs.shape, rx_abs.shape)
+ assert tx_abs.shape == phase_diff.shape, \
+ "tx_abs.shape {}, phase_diff.shape {}".format(
+ tx_abs.shape, phase_diff.shape)
+
+
+class Model_Poly:
+ """Calculates new coefficients using the measurement and the previous
+ coefficients"""
+
+ def __init__(self,
+ c,
+ coefs_am,
+ coefs_pm,
+ learning_rate_am=1.0,
+ learning_rate_pm=1.0,
+ plot=False):
+ assert_np_float32(coefs_am)
+ assert_np_float32(coefs_pm)
+
+ self.c = c
+
+ self.learning_rate_am = learning_rate_am
+ self.learning_rate_pm = learning_rate_pm
+
+ self.coefs_am = coefs_am
+ self.coefs_pm = coefs_pm
+
+ self.model_am = Model_AM.Model_AM(c, plot=True)
+ self.model_pm = Model_PM.Model_PM(c, plot=True)
+
+ self.plot = plot
+
+ def get_default_coefs(self):
+ self.coefs_am[:] = 0
+ self.coefs_am[0] = 1
+ self.coefs_pm[:] = 0
+ return self.coefs_am, self.coefs_pm
+
+ def get_next_coefs(self, tx_abs, rx_abs, phase_diff):
+ _check_input_get_next_coefs(tx_abs, rx_abs, phase_diff)
+
+ coefs_am_new = self.model_am.get_next_coefs(tx_abs, rx_abs, self.coefs_am)
+ coefs_pm_new = self.model_pm.get_next_coefs(tx_abs, phase_diff, self.coefs_pm)
+
+ self.coefs_am = self.coefs_am + (coefs_am_new - self.coefs_am) * self.learning_rate_am
+ self.coefs_pm = self.coefs_pm + (coefs_pm_new - self.coefs_pm) * self.learning_rate_pm
+
+ return self.coefs_am, self.coefs_pm
+
+# The MIT License (MIT)
+#
+# Copyright (c) 2017 Andreas Steger
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.