I am using the code available on Brian for computing auto- or cross-correlograms (see below). But I obtained sometimes (and usually, in the most interesting cases), the artifacts shown on the attached figure (note that there are 58,000 spikes in the train).
I already posted a related question, but I didn't manage to solve this problem. Note: the problem is not "bin size < signal discretization size" (bin size = 1 ms; signal discretization size = 0.05 ms, since sampling frequency = 20kHz).
That would be great if someone can help me with this issue. It should be a numerical error, but I cannot figure out which one.
def CCG(T1,T2,width,bin,T):
'''
Returns a cross-correlogram with lag in [-width,width] and given bin size.
T is the total duration (optional) and should be greater than the duration of T1 and T2.
The result is in Hz (rate of coincidences in each bin).
N.B.: units are discarded.
'''
# Remove units
Fs = 20000. #-sampling frequency in (Hz)
dt = 1/Fs*10**3 #-elementary time step in (ms)
width = int64(width/dt)
bin = int64(bin/dt)
T1 = array(T1)
T2 = array(T2)
i = 0
j = 0
n = int64(ceil(width/bin)) # Histogram length
l = []
for t in T1:
while i < len(T2) and T2[i] < t-width: # other possibility use searchsorted
i += 1
while j < len(T2) and T2[j] < t+width:
j += 1
l.extend(T2[i:j]-t)
H,_ = histogram(l,bins=arange(2*n+1)*bin*dt-n*bin*dt)
# Divide by time to get rate
if T is None:
T=max(T1[-1],T2[-1])-min(T1[0],T2[0])
# Windowing function (triangle)
#W=zeros(2*n)
#W[:n]=T-bin*arange(n-1,-1,-1)
#W[n:]=T-bin*arange(n)
return H/T*10**6