diff options
author | andreas128 <Andreas> | 2017-08-19 19:19:46 +0200 |
---|---|---|
committer | andreas128 <Andreas> | 2017-08-19 19:19:46 +0200 |
commit | 70d4314056cf6ec2df93369ac50e223d9c43aef7 (patch) | |
tree | cd95b16dc6783e3c66e89d13fac48e347a874e18 | |
parent | a11b8c5b13654d69286c6661b4e5eee2d7b0cc59 (diff) | |
download | dabmod-70d4314056cf6ec2df93369ac50e223d9c43aef7.tar.gz dabmod-70d4314056cf6ec2df93369ac50e223d9c43aef7.tar.bz2 dabmod-70d4314056cf6ec2df93369ac50e223d9c43aef7.zip |
Cleanup plots
-rw-r--r-- | dpd/src/Dab_Util.py | 105 | ||||
-rw-r--r-- | dpd/src/Measure.py | 24 | ||||
-rw-r--r-- | dpd/src/Model.py | 11 | ||||
-rw-r--r-- | dpd/src/phase_align.py | 77 | ||||
-rwxr-xr-x | dpd/src/subsample_align.py | 5 |
5 files changed, 141 insertions, 81 deletions
diff --git a/dpd/src/Dab_Util.py b/dpd/src/Dab_Util.py index a4a271e..1f88ae4 100644 --- a/dpd/src/Dab_Util.py +++ b/dpd/src/Dab_Util.py @@ -34,9 +34,8 @@ class Dab_Util: c = np.abs(signal.correlate(sig_orig, sig_rec)) if logging.getLogger().getEffectiveLevel() == logging.DEBUG: - corr_path = ('/tmp/tx_rx_corr_' + - datetime.datetime.now().isoformat() + - '.pdf') + dt = datetime.datetime.now().isoformat() + corr_path = ("/tmp/" + dt + "_tx_rx_corr.pdf") plt.plot(c, label="corr") plt.legend() plt.savefig(corr_path) @@ -90,10 +89,26 @@ class Dab_Util: if logging.getLogger().getEffectiveLevel() == logging.DEBUG: dt = datetime.datetime.now().isoformat() - txframe_path = ('/tmp/tx_0_' + dt + '.iq') - sig1.tofile(txframe_path) - rxframe_path = ('/tmp/rx_0_' + dt + '.iq') - sig2.tofile(rxframe_path) + fig_path = "/tmp/" + dt + "_sync_raw.pdf" + + fig, axs = plt.subplots(2) + axs[0].plot(np.abs(sig1[:128]), label="TX Frame") + axs[0].plot(np.abs(sig2[:128]), label="RX Frame") + axs[0].set_title("Raw Data") + axs[0].set_ylabel("Amplitude") + axs[0].set_xlabel("Samples") + axs[0].legend(loc=4) + + axs[1].plot(np.real(sig1[:128]), label="TX Frame") + axs[1].plot(np.real(sig2[:128]), label="RX Frame") + axs[1].set_title("Raw Data") + axs[1].set_ylabel("Real Part") + axs[1].set_xlabel("Samples") + axs[1].legend(loc=4) + + fig.tight_layout() + fig.savefig(fig_path) + fig.clf() logging.debug("Sig1_orig: %d %s, Sig2_orig: %d %s" % (len(sig1), sig1.dtype, len(sig2), sig2.dtype)) off_meas = self.lag_upsampling(sig2, sig1, n_up=1) @@ -111,29 +126,75 @@ class Dab_Util: sig2 = sig2[:-1] if logging.getLogger().getEffectiveLevel() == logging.DEBUG: - txframe_path = ('/tmp/tx_1_' + dt + '.iq') - sig1.tofile(txframe_path) - rxframe_path = ('/tmp/rx_1_' + dt + '.iq') - sig2.tofile(rxframe_path) + dt = datetime.datetime.now().isoformat() + fig_path = "/tmp/" + dt + "_sync_sample_aligned.pdf" - sig2 = sa.subsample_align(sig2, sig1) + fig, axs = plt.subplots(2) + axs[0].plot(np.abs(sig1[:128]), label="TX Frame") + axs[0].plot(np.abs(sig2[:128]), label="RX Frame") + axs[0].set_title("Sample Aligned Data") + axs[0].set_ylabel("Amplitude") + axs[0].set_xlabel("Samples") + axs[0].legend(loc=4) - if logging.getLogger().getEffectiveLevel() == logging.DEBUG: - txframe_path = ('/tmp/tx_2_' + dt + '.iq') - sig1.tofile(txframe_path) - rxframe_path = ('/tmp/rx_2_' + dt + '.iq') - sig2.tofile(rxframe_path) + axs[1].plot(np.real(sig1[:128]), label="TX Frame") + axs[1].plot(np.real(sig2[:128]), label="RX Frame") + axs[1].set_ylabel("Real Part") + axs[1].set_xlabel("Samples") + axs[1].legend(loc=4) + + fig.tight_layout() + fig.savefig(fig_path) + fig.clf() - sig2 = pa.phase_align(sig2, sig1) sig2 = sa.subsample_align(sig2, sig1) + + if logging.getLogger().getEffectiveLevel() == logging.DEBUG: + dt = datetime.datetime.now().isoformat() + fig_path = "/tmp/" + dt + "_sync_subsample_aligned.pdf" + + fig, axs = plt.subplots(2) + axs[0].plot(np.abs(sig1[:128]), label="TX Frame") + axs[0].plot(np.abs(sig2[:128]), label="RX Frame") + axs[0].set_title("Subsample Aligned") + axs[0].set_ylabel("Amplitude") + axs[0].set_xlabel("Samples") + axs[0].legend(loc=4) + + axs[1].plot(np.real(sig1[:128]), label="TX Frame") + axs[1].plot(np.real(sig2[:128]), label="RX Frame") + axs[1].set_ylabel("Real Part") + axs[1].set_xlabel("Samples") + axs[1].legend(loc=4) + + fig.tight_layout() + fig.savefig(fig_path) + fig.clf() + sig2 = pa.phase_align(sig2, sig1) if logging.getLogger().getEffectiveLevel() == logging.DEBUG: - txframe_path = ('/tmp/tx_3_' + dt + '.iq') - sig1.tofile(txframe_path) - rxframe_path = ('/tmp/rx_3_' + dt + '.iq') - sig2.tofile(rxframe_path) + dt = datetime.datetime.now().isoformat() + fig_path = "/tmp/" + dt + "_sync_phase_aligned.pdf" + + fig, axs = plt.subplots(2) + axs[0].plot(np.abs(sig1[:128]), label="TX Frame") + axs[0].plot(np.abs(sig2[:128]), label="RX Frame") + axs[0].set_title("Phase Aligned") + axs[0].set_ylabel("Amplitude") + axs[0].set_xlabel("Samples") + axs[0].legend(loc=4) + + axs[1].plot(np.real(sig1[:128]), label="TX Frame") + axs[1].plot(np.real(sig2[:128]), label="RX Frame") + axs[1].set_ylabel("Real Part") + axs[1].set_xlabel("Samples") + axs[1].legend(loc=4) + + fig.tight_layout() + fig.savefig(fig_path) + fig.clf() logging.debug("Sig1_cut: %d %s, Sig2_cut: %d %s, off: %d" % (len(sig1), sig1.dtype, len(sig2), sig2.dtype, off)) return sig1, sig2 diff --git a/dpd/src/Measure.py b/dpd/src/Measure.py index e9493fa..ef9e290 100644 --- a/dpd/src/Measure.py +++ b/dpd/src/Measure.py @@ -84,31 +84,15 @@ class Measure: rxframe = rxframe / np.median(np.abs(rxframe)) * np.median(np.abs(txframe)) if logging.getLogger().getEffectiveLevel() == logging.DEBUG: - txframe_path = ('/tmp/txframe_fft_' + - datetime.datetime.now().isoformat() + - '.pdf') - plt.plot(np.abs(np.fft.fftshift(np.fft.fft(txframe[:self.samplerate])))) - plt.savefig(txframe_path) - plt.clf() - - rxframe_path = ('/tmp/rxframe_fft_' + - datetime.datetime.now().isoformat() + - '.pdf') - plt.plot(np.abs(np.fft.fftshift(np.fft.fft(rxframe[:self.samplerate])))) - plt.savefig(rxframe_path) - plt.clf() - - logging.debug("txframe: min %f, max %f, median %f, spectrum %s" % + logging.debug("txframe: min %f, max %f, median %f" % (np.min(np.abs(txframe)), np.max(np.abs(txframe)), - np.median(np.abs(txframe)), - txframe_path)) + np.median(np.abs(txframe)))) - logging.debug("rxframe: min %f, max %f, median %f, spectrum %s" % + logging.debug("rxframe: min %f, max %f, median %f" % (np.min(np.abs(rxframe)), np.max(np.abs(rxframe)), - np.median(np.abs(rxframe)), - rxframe_path)) + np.median(np.abs(rxframe)))) logging.debug("Disconnecting") s.close() diff --git a/dpd/src/Model.py b/dpd/src/Model.py index 07ac5a4..f923799 100644 --- a/dpd/src/Model.py +++ b/dpd/src/Model.py @@ -28,9 +28,8 @@ class Model: np.median(np.abs(rxframe_aligned)) )) - tx_rx_frame_path = ('/tmp/tx_rx_sync_' + - datetime.datetime.now().isoformat() + - '.pdf') + dt = datetime.datetime.now().isoformat() + tx_rx_frame_path = ("/tmp/" + dt + "_tx_rx_sync.pdf") plt.plot(np.abs(rxframe_aligned[:128]), label="rxframe") plt.plot(np.abs(txframe_aligned[:128]), label="txframe") plt.xlabel("Samples") @@ -40,12 +39,6 @@ class Model: plt.clf() logging.debug("Tx, Rx synchronized %s" % tx_rx_frame_path) - dt = datetime.datetime.now().isoformat() - txframe_path = ('/tmp/tx_3_' + dt + '.iq') - txframe_aligned.tofile(txframe_path) - rxframe_path = ('/tmp/rx_3_' + dt + '.iq') - rxframe_aligned.tofile(rxframe_path) - mse = np.mean(np.abs(np.square(txframe_aligned - rxframe_aligned))) logging.debug("MSE: {}".format(mse)) diff --git a/dpd/src/phase_align.py b/dpd/src/phase_align.py index 9e78483..bea0b82 100644 --- a/dpd/src/phase_align.py +++ b/dpd/src/phase_align.py @@ -14,35 +14,58 @@ def phase_align(sig, ref_sig): angle_diff = (np.angle(sig) - np.angle(ref_sig)) % (2. * np.pi) - dt = datetime.datetime.now().isoformat() - fig_path = "/tmp/phase_align_" + dt + ".pdf" - plt.subplot(311) - plt.hist(angle_diff, bins=60, label="Angle Diff") - plt.xlabel("Angle") - plt.ylabel("Count") - plt.legend(loc=4) - - plt.subplot(312) - plt.plot(np.angle(ref_sig[:128]), label="ref_sig") - plt.plot(np.angle(sig[:128]), label="sig") - plt.xlabel("Angle") - plt.ylabel("Sample") - plt.legend(loc=4) - - angle = np.median(angle_diff) - logging.debug("Compensating phase by {} rad, {} degree.".format( - angle, angle*180./np.pi + real_diffs = np.cos(angle_diff) + imag_diffs = np.sin(angle_diff) + + if logging.getLogger().getEffectiveLevel() == logging.DEBUG: + dt = datetime.datetime.now().isoformat() + fig_path = "/tmp/" + dt + "_phase_align.pdf" + + plt.subplot(511) + plt.hist(angle_diff, bins=60, label="Angle Diff") + plt.xlabel("Angle") + plt.ylabel("Count") + plt.legend(loc=4) + + plt.subplot(512) + plt.hist(real_diffs, bins=60, label="Real Diff") + plt.xlabel("Real Part") + plt.ylabel("Count") + plt.legend(loc=4) + + plt.subplot(513) + plt.hist(imag_diffs, bins=60, label="Imaginary Diff") + plt.xlabel("Imaginary Part") + plt.ylabel("Count") + plt.legend(loc=4) + + plt.subplot(514) + plt.plot(np.angle(ref_sig[:128]), label="ref_sig") + plt.plot(np.angle(sig[:128]), label="sig") + plt.xlabel("Angle") + plt.ylabel("Sample") + plt.legend(loc=4) + + real_diff = np.median(real_diffs) + imag_diff = np.median(imag_diffs) + + angle = np.angle(real_diff + 1j * imag_diff) + + logging.debug( + "Compensating phase by {} rad, {} degree. real median {}, imag median {}".format( + angle, angle*180./np.pi, real_diff, imag_diff )) sig = sig * np.exp(1j * -angle) - plt.subplot(313) - plt.plot(np.angle(ref_sig[:128]), label="ref_sig") - plt.plot(np.angle(sig[:128]), label="sig") - plt.xlabel("Angle") - plt.ylabel("Sample") - plt.legend(loc=4) - plt.tight_layout() - plt.savefig(fig_path) - plt.clf() + if logging.getLogger().getEffectiveLevel() == logging.DEBUG: + plt.subplot(515) + plt.plot(np.angle(ref_sig[:128]), label="ref_sig") + plt.plot(np.angle(sig[:128]), label="sig") + plt.xlabel("Angle") + plt.ylabel("Sample") + plt.legend(loc=4) + plt.tight_layout() + plt.savefig(fig_path) + plt.clf() return sig diff --git a/dpd/src/subsample_align.py b/dpd/src/subsample_align.py index 992aa03..0dc78c1 100755 --- a/dpd/src/subsample_align.py +++ b/dpd/src/subsample_align.py @@ -66,9 +66,8 @@ def subsample_align(sig, ref_sig): ixs = np.linspace(-1, 1, 100) taus = corr(ixs) - tau_path = ('/tmp/tau_' + - datetime.datetime.now().isoformat() + - '.pdf') + dt = datetime.datetime.now().isoformat() + tau_path = ("/tmp/" + dt + "_tau.pdf") plt.plot(ixs, taus) plt.title("Subsample correlation, minimum is best: {}".format(best_tau)) plt.savefig(tau_path) |