aboutsummaryrefslogtreecommitdiffstats
path: root/dpd/src/Model_Poly.py
diff options
context:
space:
mode:
Diffstat (limited to 'dpd/src/Model_Poly.py')
-rw-r--r--dpd/src/Model_Poly.py99
1 files changed, 99 insertions, 0 deletions
diff --git a/dpd/src/Model_Poly.py b/dpd/src/Model_Poly.py
new file mode 100644
index 0000000..f6c024c
--- /dev/null
+++ b/dpd/src/Model_Poly.py
@@ -0,0 +1,99 @@
+# -*- 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 Poly:
+ """Calculates new coefficients using the measurement and the previous
+ coefficients"""
+
+ def __init__(self,
+ c,
+ learning_rate_am=1.0,
+ learning_rate_pm=1.0,
+ plot=False):
+ self.c = c
+
+ self.learning_rate_am = learning_rate_am
+ self.learning_rate_pm = learning_rate_pm
+
+ self.reset_coefs()
+
+ self.model_am = Model_AM.Model_AM(c, plot=True)
+ self.model_pm = Model_PM.Model_PM(c, plot=True)
+
+ self.plot = plot
+
+ def reset_coefs(self):
+ self.coefs_am = np.zeros(5, dtype=np.float32)
+ self.coefs_am[0] = 1
+ self.coefs_pm = np.zeros(5, dtype=np.float32)
+ return self.coefs_am, self.coefs_pm
+
+ def train(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
+
+ def get_dpd_data(self):
+ return "poly", 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.