% matplotlib inline
% config InlineBackend.figure_format = 'retina'
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams as rcp
rcp['font.family'] = 'serif'
rcp['font.serif']='Times New Roman'
rcp['legend.fontsize'] = 15
rcp['font.size'] = 15.0
rcp['text.usetex']=True
rcp['agg.path.chunksize'] = 10000
h1_residual_data = np.loadtxt('fig1-residual-H.txt')
l1_residual_data = np.loadtxt('fig1-residual-L.txt')
h1_res_times = h1_residual_data[:,0]; h1_res_strain = h1_residual_data[:,1]
l1_res_times = l1_residual_data[:,0]; l1_res_strain = l1_residual_data[:,1]
fs = 1./(h1_res_times[1]-h1_res_times[0])
t = 0.39
w = 0.04
min_indxt = np.where(abs(h1_res_times-t) == abs(h1_res_times-t).min())[0][0]
max_indxt = np.where(abs(h1_res_times-(t+w)) == abs(h1_res_times-(t+w)).min())[0][0]
deltatau = 0.01
tauind_min = int(-deltatau*fs); tauind_max = int(+deltatau*fs)
tauind = np.arange(tauind_min,tauind_max)
tau = tauind/fs
corr = []
for i in tauind:
corr.append(np.corrcoef(h1_res_strain[min_indxt+abs(tauind_min)+i:max_indxt-abs(tauind_max)+i],l1_res_strain[min_indxt+abs(tauind_min):max_indxt-abs(tauind_max)])[0][1])
plt.figure()
plt.plot(tau * 1000.,corr,'k',label="t="+str(t)+", w="+str(w))
plt.xlim(-10,10)
plt.xlabel(r"$\tau$ [ms]")
plt.ylabel(r"$C(t,\tau,w)$")
plt.ylim(-.9,.7)
plt.legend(loc='best')