1
## Copyright (C) 1996-2015 Piotr Held
3
## This file is part of Octave.
5
## Octave is free software; you can redistribute it and/or
6
## modify it under the terms of the GNU General Public
7
## License as published by the Free Software Foundation;
8
## either version 3 of the License, or (at your option) any
11
## Octave is distributed in the hope that it will be useful,
12
## but WITHOUT ANY WARRANTY; without even the implied
13
## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14
## PURPOSE. See the GNU General Public License for more
17
## You should have received a copy of the GNU General Public
18
## License along with Octave; see the file COPYING. If not,
19
## see <http://www.gnu.org/licenses/>.
22
## @deftypefn{Function File} {output =} spikeauto (@var{X}, @var{bin}, @var{bintot})
23
## @deftypefnx{Function File} {output =} spikeauto (@dots{}, '@var{inter}')
25
## Computes the binned autocorrelation function of a series of event times.
27
## The data is assumed to represent a sum of delta functions centered at the
28
## times given. The autocorrelation function is then a double sum of delta
29
## functions which must be binned to be representable. Therfore, you have to
30
## choose the duration of a single bin (with argument @var{bin}) and the maximum
31
## time lag (argument @var{bintot}) considered.
37
## This function always assumes that each time series is along the longer
38
## dimension of matrix @var{S}. It also assumes that every dimension
39
## (counting along the shorter dimension) of @var{S} is considered a
40
## component of the time series.
42
## The duration of a single bin.
44
## The maximum lag considered.
51
## Treat the input as inter-event intervals instead of the time at which the event
57
## The output is alligned with the input. If the input was a column vector the
58
## output will consist of two columns, the first holds information about which
59
## bin did the autocorellation fit into, and the second the number of
60
## autocorellations that fit into that bin.
62
## @strong{Algorithms}
64
## The algorithms for this functions have been taken from the TISEAN package.
67
## Author: Piotr Held <pjheld@gmail.com>.
68
## This function is based on spikeauto of TISEAN 3.0.1
69
## https://github.com/heggus/Tisean"
71
function output = spikeauto (X, bin, totbin, varargin)
73
# Initial input validation
74
if (nargin < 3 || nargin > 4)
78
# Check if X is real vector
79
if ((isvector (X) == false) || (isreal (X) == false))
80
error ('Octave:invalid-input-arg', "X must be a real vector");
83
# Check if X has at least 2 different elements
84
if (min (X) == max (X))
85
error ('Octave:invalid-input-arg',
86
"X must contain at least 2 differing elements");
92
if (strcmpi (varargin{1}, "inter"))
95
error ('Octave:invalid-input-arg', "additional parameter is not 'inter'");
99
# Correct X to always have more rows than columns
101
if (rows (X) < columns (X))
106
# If the input is interval change to times
114
nbin = floor (totbin / bin) + 1;
116
# The oct file is used for optimization (using a for loop in Octave is about 100
117
# times slower and not using the for loop uses a lot of memory,
118
# e.g. when lenght (X) == 2000 it uses 500 MB).
119
ihist = __spikeauto__ (X, bin, nbin);
122
idx = (idx - 0.5) .* bin;
124
output = [idx, ihist];
132
%% Test against TISEAN output
134
%! spikeauto_res = [0.25 403965;0.75 376230;1.25 331311;1.75 274509;2.25 209767;2.75 153597;3.25 104075;3.75 65683;4.25 39030;4.75 21812;5.25 10745;5.75 5090;6.25 2064;6.75 792;7.25 245;7.75 70;8.25 14;8.75 1;9.25 0;9.75 0;10.25 0];
136
%! x = zeros (2000,1);
138
%! x(i) = 0.7*x(i-1) + (-6 + sum (rand ([size(1), 12]), 3));
140
%! res = spikeauto (x, 0.5, 10);
141
%! assert (res, spikeauto_res, 1);
143
%% Testing input validation
144
%!error <Invalid call> spikeauto (1)
145
%!error <2 differing elements> spikeauto (ones (10,1), 1,3);
146
%!error <vector> spikeauto ([(1:10);(1:10)],1,2);