From cc4a2fa49620306a16f131a54fbdc965a3d44056 Mon Sep 17 00:00:00 2001 From: andreas128 Date: Tue, 12 Sep 2017 17:46:25 +0200 Subject: Switch to linear regression; Cleanup --- dpd/src/Model.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'dpd/src/Model.py') diff --git a/dpd/src/Model.py b/dpd/src/Model.py index 827027a..1606441 100644 --- a/dpd/src/Model.py +++ b/dpd/src/Model.py @@ -15,6 +15,7 @@ import numpy as np import matplotlib.pyplot as plt from sklearn import linear_model + class Model: """Calculates new coefficients using the measurement and the old coefficients""" @@ -25,8 +26,8 @@ class Model: MER, coefs_am, coefs_pm, - learning_rate_am=1., - learning_rate_pm=1., + learning_rate_am=0.1, + learning_rate_pm=0.1, plot=False): self.c = c self.SA = SA @@ -122,11 +123,9 @@ class Model: err = np.abs(rx_dpd) - np.abs(tx_choice) mse = np.mean(np.abs((rx_dpd - tx_choice) ** 2)) self.mses_am.append(mse) - self.errs_am.append(np.mean(err**2)) + self.errs_am.append(np.mean(err ** 2)) - reg = linear_model.Ridge(alpha=0.00001) - reg.fit(rx_A, err) - a_delta = reg.coef_ + a_delta = np.linalg.lstsq(rx_A, err)[0] new_coefs_am = self.coefs_am - self.learning_rate_am * a_delta new_coefs_am = new_coefs_am * (self.coefs_am[0] / new_coefs_am[0]) return new_coefs_am @@ -139,15 +138,13 @@ class Model: (np.abs(rx_choice) * np.abs(tx_choice)) ) plt.hist(phase_diff_choice) - plt.savefig('/tmp/hist_' + str(np.random.randint(0,1000)) + '.svg') + plt.savefig('/tmp/hist_' + str(np.random.randint(0, 1000)) + '.svg') plt.clf() phase_diff_est, phase_A = self.dpd_phase(rx_choice) err_phase = phase_diff_est - phase_diff_choice self.errs_pm.append(np.mean(np.abs(err_phase ** 2))) - reg = linear_model.Ridge(alpha=0.00001) - reg.fit(phase_A, err_phase) - p_delta = reg.coef_ + p_delta = np.linalg.lstsq(phase_A, err_phase)[0] new_coefs_pm = self.coefs_pm - self.learning_rate_pm * p_delta return new_coefs_pm, phase_diff_choice @@ -164,6 +161,11 @@ class Model: np.median(np.abs(tx_dpd)) + np.median(np.abs(rx_received))) assert normalization_error < 0.01, "Non normalized signals" + if logging.getLogger().getEffectiveLevel() == logging.DEBUG: + dt = datetime.datetime.now().isoformat() + tx_dpd.tofile(logging_path + "/tx_dpd_" + dt + ".iq") + rx_received.tofile(logging_path + "/rx_received_" + dt + ".iq") + tx_choice, rx_choice = self.sample_uniformly(tx_dpd, rx_received) new_coefs_am = self._next_am_coefficent(tx_choice, rx_choice) new_coefs_pm, phase_diff_choice = self._next_pm_coefficent(tx_choice, rx_choice) @@ -303,7 +305,7 @@ class Model: np.rad2deg(phase_range_dpd_new), linewidth=0.25, label="next") - ax.set_ylim(-60, 60) + ax.set_ylim(-180, 180) ax.set_xlim(0, 1) ax.legend() ax.set_title("Amplifier Characteristic") -- cgit v1.2.3 From 895a420ea692f2c32aa206e1cfa2758bfa79b8cd Mon Sep 17 00:00:00 2001 From: andreas128 Date: Wed, 13 Sep 2017 14:33:20 +0200 Subject: Change comment --- dpd/src/Model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dpd/src/Model.py') diff --git a/dpd/src/Model.py b/dpd/src/Model.py index 1606441..a051927 100644 --- a/dpd/src/Model.py +++ b/dpd/src/Model.py @@ -17,7 +17,7 @@ from sklearn import linear_model class Model: - """Calculates new coefficients using the measurement and the old + """Calculates new coefficients using the measurement and the previous coefficients""" def __init__(self, -- cgit v1.2.3 From 426671f4af2a5d1d5d01225194eb66b2edb8c059 Mon Sep 17 00:00:00 2001 From: andreas128 Date: Wed, 13 Sep 2017 18:34:05 +0200 Subject: Fix non closed figures --- dpd/src/Agc.py | 2 +- dpd/src/Dab_Util.py | 10 +++++----- dpd/src/ExtractStatistic.py | 2 +- dpd/src/MER.py | 2 +- dpd/src/Model.py | 4 ++-- dpd/src/Model_AM.py | 2 +- dpd/src/phase_align.py | 2 +- dpd/src/subsample_align.py | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) (limited to 'dpd/src/Model.py') diff --git a/dpd/src/Agc.py b/dpd/src/Agc.py index 978b607..b83c91e 100644 --- a/dpd/src/Agc.py +++ b/dpd/src/Agc.py @@ -139,7 +139,7 @@ class Agc: fig.tight_layout() fig.savefig(fig_path) - fig.clf() + plt.close(fig) # The MIT License (MIT) diff --git a/dpd/src/Dab_Util.py b/dpd/src/Dab_Util.py index e3dbfe3..37be5db 100644 --- a/dpd/src/Dab_Util.py +++ b/dpd/src/Dab_Util.py @@ -49,7 +49,7 @@ class Dab_Util: plt.plot(c, label="corr") plt.legend() plt.savefig(corr_path) - plt.clf() + plt.close() return np.argmax(c) - off + 1 @@ -118,7 +118,7 @@ class Dab_Util: fig.tight_layout() fig.savefig(fig_path) - fig.clf() + plt.close(fig) off_meas = self.lag_upsampling(sig_rx, sig_tx, n_up=1) off = int(abs(off_meas)) @@ -161,7 +161,7 @@ class Dab_Util: fig.tight_layout() fig.savefig(fig_path) - fig.clf() + plt.close(fig) sig_rx = sa.subsample_align(sig_rx, sig_tx) @@ -185,7 +185,7 @@ class Dab_Util: fig.tight_layout() fig.savefig(fig_path) - fig.clf() + plt.close(fig) sig_rx = pa.phase_align(sig_rx, sig_tx) @@ -209,7 +209,7 @@ class Dab_Util: fig.tight_layout() fig.savefig(fig_path) - fig.clf() + plt.close(fig) logging.debug("Sig1_cut: %d %s, Sig2_cut: %d %s, off: %d" % (len(sig_tx), sig_tx.dtype, len(sig_rx), sig_rx.dtype, off)) return sig_tx, sig_rx diff --git a/dpd/src/ExtractStatistic.py b/dpd/src/ExtractStatistic.py index d2aeee4..6139e1d 100644 --- a/dpd/src/ExtractStatistic.py +++ b/dpd/src/ExtractStatistic.py @@ -118,7 +118,7 @@ class ExtractStatistic: fig.tight_layout() fig.savefig(fig_path) - fig.clf() + plt.close(fig) pickle.dump(self.rx_values_lists, open("/tmp/rx_values", "wb")) pickle.dump(self.tx_values, open("/tmp/tx_values", "wb")) diff --git a/dpd/src/MER.py b/dpd/src/MER.py index 00fcc23..4f2918e 100644 --- a/dpd/src/MER.py +++ b/dpd/src/MER.py @@ -106,7 +106,7 @@ class MER: plt.tight_layout() plt.savefig(fig_path) plt.show() - plt.clf() + plt.close() MER_res = 20 * np.log10(np.mean([10 ** (MER / 20) for MER in MERs])) return MER_res diff --git a/dpd/src/Model.py b/dpd/src/Model.py index a051927..fe9c56b 100644 --- a/dpd/src/Model.py +++ b/dpd/src/Model.py @@ -139,7 +139,7 @@ class Model: ) plt.hist(phase_diff_choice) plt.savefig('/tmp/hist_' + str(np.random.randint(0, 1000)) + '.svg') - plt.clf() + plt.close() phase_diff_est, phase_A = self.dpd_phase(rx_choice) err_phase = phase_diff_est - phase_diff_choice self.errs_pm.append(np.mean(np.abs(err_phase ** 2))) @@ -326,7 +326,7 @@ class Model: fig.tight_layout() fig.savefig(fig_path) - fig.clf() + plt.close(fig) self.coefs_am = new_coefs_am self.coefs_am_history.append(self.coefs_am) diff --git a/dpd/src/Model_AM.py b/dpd/src/Model_AM.py index 5281dde..bdf55c6 100644 --- a/dpd/src/Model_AM.py +++ b/dpd/src/Model_AM.py @@ -71,7 +71,7 @@ class Model_AM: fig.tight_layout() fig.savefig(fig_path) - fig.clf() + plt.close(fig) def poly(self, sig): return np.array([sig ** i for i in range(1, 6)]).T diff --git a/dpd/src/phase_align.py b/dpd/src/phase_align.py index 7f82392..7317d70 100644 --- a/dpd/src/phase_align.py +++ b/dpd/src/phase_align.py @@ -75,7 +75,7 @@ def phase_align(sig, ref_sig, plot=False): plt.legend(loc=4) plt.tight_layout() plt.savefig(fig_path) - plt.clf() + plt.close() return sig diff --git a/dpd/src/subsample_align.py b/dpd/src/subsample_align.py index 6d1cd2a..b0cbe88 100755 --- a/dpd/src/subsample_align.py +++ b/dpd/src/subsample_align.py @@ -78,7 +78,7 @@ def subsample_align(sig, ref_sig, plot=False): plt.plot(ixs, taus) plt.title("Subsample correlation, minimum is best: {}".format(best_tau)) plt.savefig(tau_path) - plt.clf() + plt.close() # Prepare rotate_vec = fft_sig with rotated phase rotate_vec = np.exp(1j * best_tau * omega) -- cgit v1.2.3