import neo
import numpy as np
import quantities as pq
import matplotlib.pyplot as plt
from elephant.signal_processing import cross_correlation_function
dt = 0.02
N = 2018
f = 0.5
t = np.arange(N)*dt
x = np.zeros((N,2))
x[:,0] = 0.2 * np.sin(2.*np.pi*f*t)
x[:,1] = 5.3 * np.cos(2.*np.pi*f*t)

# Generate neo.AnalogSignals from x and find cross-correlation

signal = neo.AnalogSignal(x, units='mV', t_start=0.*pq.ms,
         sampling_rate=1/dt*pq.Hz, dtype=float)
rho = cross_correlation_function(signal, [0,1], n_lags=150)
env = cross_correlation_function(signal, [0,1], n_lags=150,
    hilbert_envelope=True)

plt.plot(rho.times, rho)
plt.plot(env.times, env) # should be equal to one
plt.show()