From 8696ebf0d58e0e2b9b362497e6c1b778de4a20b6 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 18 Aug 2017 17:33:37 +0200 Subject: DPDCE: Change subsample correlation to use complex correlation --- dpd/src/subsample_align.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'dpd/src') diff --git a/dpd/src/subsample_align.py b/dpd/src/subsample_align.py index c30af7c..eda1dce 100755 --- a/dpd/src/subsample_align.py +++ b/dpd/src/subsample_align.py @@ -2,6 +2,7 @@ import numpy as np from scipy import signal, optimize import sys import matplotlib.pyplot as plt +import datetime def gen_omega(length): if (length % 2) == 1: @@ -51,20 +52,28 @@ def subsample_align(sig, ref_sig): corr_sig = np.fft.ifft(rotate_vec * fft_sig) - # TODO why do we only look at the real part? Because it's faster than - # a complex cross-correlation? Clarify! - return -np.sum(np.real(corr_sig) * np.real(ref_sig.real)) + return -np.abs(np.sum(corr_sig * ref_sig)) optim_result = optimize.minimize_scalar(correlate_for_delay, bounds=(-1,1), method='bounded', options={'disp': True}) if optim_result.success: - #print("x:") - #print(optim_result.x) - best_tau = optim_result.x #print("Found subsample delay = {}".format(best_tau)) + if 0: + corr = np.vectorize(correlate_for_delay) + ixs = np.linspace(-1, 1, 100) + taus = corr(ixs) + + tau_path = ('/tmp/tau_' + + datetime.datetime.now().isoformat() + + '.pdf') + plt.plot(ixs, taus) + plt.title("Subsample correlation, minimum is best: {}".format(best_tau)) + plt.savefig(tau_path) + plt.clf() + # Prepare rotate_vec = fft_sig with rotated phase rotate_vec = np.exp(1j * best_tau * omega) rotate_vec[halflen] = np.cos(np.pi * best_tau) -- cgit v1.2.3