Define a Gaussian kernel. The width is specified by s
kernel = #2 Exp[-(t - #1)^2/(2 s^2)] &;
Define a function to compute the correlation in terms of the convolution
correlate[x_, y_, t, T_] := Convolve[x, y /. t -> -t, t, T]
Test this by correlating two kernels at different times
correlate[kernel[t1, 1], kernel[t2, 1], t, T]
(* (E^(-((T - t1 + t2)^2/(4 s^2))) Sqrt[π])/Sqrt[1/s^2] *)
As expected the location of the peak is given by t1-t2
.
Use a value of s=10
to spread the specified points and correlate.
correlation =
Block[{s = 10},
correlate[Total[kernel @@@ Spktrain1], Total[kernel @@@ Spktrain2],
t, T]]
(* 1.98775*10^-113 E^((-1.61981 - 0.0025 T) T) +
1.98531*10^-48 E^((-1.06167 - 0.0025 T) T) +
2.55025*10^-48 E^((-1.06049 - 0.0025 T) T) +
1.7299*10^-10 E^((-0.503515 - 0.0025 T) T) +
1.94791*10^-10 E^((-0.502335 - 0.0025 T) T) +
1.94791*10^-10 E^((-0.502335 - 0.0025 T) T) +
12.9801 E^((0.055815 - 0.0025 T) T) +
25.9602 E^((0.055815 - 0.0025 T) T) +
12.8435 E^((0.056755 - 0.0025 T) T) +
7.54594*10^-16 E^((0.613965 - 0.0025 T) T) +
7.54594*10^-16 E^((0.613965 - 0.0025 T) T) +
5.81383*10^-16 E^((0.616085 - 0.0025 T) T) +
3.82712*10^-59 E^((1.17211 - 0.0025 T) T) +
2.32725*10^-59 E^((1.17424 - 0.0025 T) T) +
8.12734*10^-130 E^((1.73239 - 0.0025 T) T) *)
Plot the results
Plot[correlation, {T, -500, 500}, PlotRange -> All]
The peak of the correlation gives the delay between the two sets of samples
FindMaximum[correlation, {T, 0}]
(* {70.897, {T -> 11.21}} *)