summaryrefslogtreecommitdiffstats
path: root/dpd/src/Model.py
diff options
context:
space:
mode:
authorandreas128 <Andreas>2017-08-21 20:05:26 +0200
committerandreas128 <Andreas>2017-08-21 20:05:26 +0200
commit0c0d145866043c16c3dc73615f35bbac12140b93 (patch)
treea2a04f35f95bd4983f070e8d399abb19a5ccdfaf /dpd/src/Model.py
parent944df89d7a6253b9077eec1655449e74b16f1418 (diff)
downloaddabmod-0c0d145866043c16c3dc73615f35bbac12140b93.tar.gz
dabmod-0c0d145866043c16c3dc73615f35bbac12140b93.tar.bz2
dabmod-0c0d145866043c16c3dc73615f35bbac12140b93.zip
Add single shot correction
Diffstat (limited to 'dpd/src/Model.py')
-rw-r--r--dpd/src/Model.py36
1 files changed, 34 insertions, 2 deletions
diff --git a/dpd/src/Model.py b/dpd/src/Model.py
index f66ba8f..014b5ef 100644
--- a/dpd/src/Model.py
+++ b/dpd/src/Model.py
@@ -6,6 +6,7 @@ import logging
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
+from sklearn.linear_model import Ridge
class Model:
"""Calculates new coefficients using the measurement and the old
@@ -15,6 +16,31 @@ class Model:
self.coefs = coefs
def get_next_coefs(self, txframe_aligned, rxframe_aligned):
+ rx_abs = np.abs(rxframe_aligned)
+ A = np.vstack([rx_abs,
+ rx_abs**3,
+ rx_abs**5,
+ rx_abs**7,
+ rx_abs**9,
+ ]).T
+ y = np.abs(txframe_aligned)
+
+ clf = Ridge(alpha=10)
+ clf.fit(A, y)
+ sol = clf.coef_
+
+ rx_range = np.linspace(0,1,50)
+ A_range = np.vstack([
+ rx_range,
+ rx_range**3,
+ rx_range**5,
+ rx_range**7,
+ rx_range**9,
+ ]).T
+ y_est = np.sum(A_range * sol, axis=1)
+
+ logging.debug("New coefficents {}".format(sol))
+
if logging.getLogger().getEffectiveLevel() == logging.DEBUG:
logging.debug("txframe: min %f, max %f, median %f" %
(np.min(np.abs(txframe_aligned)),
@@ -31,7 +57,7 @@ class Model:
dt = datetime.datetime.now().isoformat()
fig_path = "/tmp/" + dt + "_Model.pdf"
- fig, axs = plt.subplots(4, figsize=(6,2*6))
+ fig, axs = plt.subplots(5, figsize=(6,2*6))
ax = axs[0]
ax.plot(np.abs(txframe_aligned[:128]), label="TX Frame")
@@ -55,6 +81,11 @@ class Model:
np.abs(rxframe_aligned[:1024]),
s = 0.1
)
+ ax.plot(
+ y_est,
+ rx_range,
+ linewidth=0.25
+ )
ax.set_title("Amplifier Characteristic")
ax.set_xlabel("TX Amplitude")
ax.set_ylabel("RX Amplitude")
@@ -82,7 +113,8 @@ class Model:
mse = np.mean(np.abs(np.square(txframe_aligned[:1024] - rxframe_aligned[:1024])))
logging.debug("MSE: {}".format(mse))
- return self.coefs
+ sol = sol * 1.7/sol[0]
+ return sol
# The MIT License (MIT)
#