This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/pointprocesses/code/isiserialcorr.m
2017-11-28 10:13:59 +01:00

36 lines
966 B
Matlab

function isicorr = isiserialcorr(isivec, maxlag)
% serial correlation of interspike intervals
%
% isicorr = isiserialcorr(isivec, maxlag)
%
% Arguments:
% isivec: vector of interspike intervals in seconds
% maxlag: the maximum lag in seconds
%
% Returns:
% isicorr: vector with the serial correlations for lag 0 to maxlag
lags = 0:maxlag;
isicorr = zeros(size(lags));
for k = 1:length(lags)
lag = lags(k);
if length(isivec) > lag+10 % ensure "enough" data
% NOTE: the arguments to corr must be column vectors!
% We insure this in the isis() function that
% generates the isivec.
isicorr(k) = corr(isivec(1:end-lag), isivec(lag+1:end));
end
end
if nargout == 0
% plot:
plot(lags, isicorr, '-b');
hold on;
scatter(lags, isicorr, 50.0, 'b', 'filled');
hold off;
xlabel('Lag k')
ylabel('\rho_k')
end
end