import numpy as np


def zero_crossing(eod, time):
	threshold = 0
	shift_eod = np.roll(eod, 1)
	eod_times = time[(eod >= threshold) & (shift_eod < threshold)]
	sampling_rate = 40000.0
	eod_idx = eod_times*sampling_rate
	return eod_idx


def vector_strength(spike_times, eod_durations):
	n = len(spike_times)
	phase_times = np.zeros(len(spike_times))
	for i, idx in enumerate(spike_times):
		phase_times[i] = (spike_times[i] / eod_durations[i]) * 2 * np.pi
	vs = np.sqrt((1/n*sum(np.cos(phase_times)))**2 + (1/n*sum(np.sin(phase_times)))**2)
	return vs


def gaussian(x, mu, sig):
	y = np.exp(-np.power(x - mu, 2.) / (2 * np.power(sig, 2.)))
	return y

