diff options
Diffstat (limited to 'dpd/src/phase_align.py')
-rw-r--r-- | dpd/src/phase_align.py | 77 |
1 files changed, 50 insertions, 27 deletions
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 |