0001 function [ccg,x,y] = ShortTimeCCG(times1,times2,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 auto = 0;
0053
0054
0055 if nargin < 1,
0056 error('Incorrect number of parameters (type ''help <a href="matlab:help ShortTimeCCG">ShortTimeCCG</a>'' for details).');
0057 end
0058 if nargin >= 2 && isa(times2,'char'),
0059
0060 varargin = {times2,varargin{:}};
0061 times2 = times1;
0062 auto = 1;
0063 end
0064 if ~isvector(times1) || ~isvector(times2) || isempty(times1) || isempty(times2),
0065 error('Parameters ''times1'' and ''time2'' must be non-empty vectors (type ''help <a href="matlab:help ShortTimeCCG">ShortTimeCCG</a>'' for details).');
0066 end
0067
0068
0069 binSize = 0.01;
0070 duration = 2;
0071 window = 5*60;
0072 overlap = [];
0073 mode = 'count';
0074 smooth = [];
0075 minEvents = 1;
0076
0077
0078 for i = 1:2:length(varargin),
0079 if ~ischar(varargin{i}),
0080 error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help ShortTimeCCG">ShortTimeCCG</a>'' for details).']);
0081 end
0082 switch(lower(varargin{i})),
0083
0084 case 'binsize',
0085 binSize = varargin{i+1};
0086 if ~isdscalar(binSize,'>0'),
0087 error('Incorrect value for property ''binSize'' (type ''help <a href="matlab:help ShortTimeCCG">ShortTimeCCG</a>'' for details).');
0088 end
0089
0090 case 'duration',
0091 duration = varargin{i+1};
0092 if ~isdscalar(duration,'>0'),
0093 error('Incorrect value for property ''duration'' (type ''help <a href="matlab:help ShortTimeCCG">ShortTimeCCG</a>'' for details).');
0094 end
0095
0096 case 'window',
0097 window = varargin{i+1};
0098 if ~isdscalar(window,'>0'),
0099 error('Incorrect value for property ''window'' (type ''help <a href="matlab:help ShortTimeCCG">ShortTimeCCG</a>'' for details).');
0100 end
0101
0102 case 'overlap',
0103 overlap = varargin{i+1};
0104 if ~isdscalar(overlap,'>0'),
0105 error('Incorrect value for property ''overlap'' (type ''help <a href="matlab:help ShortTimeCCG">ShortTimeCCG</a>'' for details).');
0106 end
0107
0108 case 'mode',
0109 mode = lower(varargin{i+1});
0110 if ~isastring(mode,'norm','count'),
0111 error('Incorrect value for property ''mode'' (type ''help <a href="matlab:help ShortTimeCCG">ShortTimeCCG</a>'' for details).');
0112 end
0113
0114 case 'smooth',
0115 smooth = varargin{i+1};
0116 if ~isdvector(smooth,'>=0') | length(smooth) > 2,
0117 error('Incorrect value for property ''smooth'' (type ''help <a href="matlab:help ShortTimeCCG">ShortTimeCCG</a>'' for details).');
0118 end
0119
0120 case 'min',
0121 minEvents = varargin{i+1};
0122 if ~isiscalar(minEvents,'>=0'),
0123 error('Incorrect value for property ''min'' (type ''help <a href="matlab:help ShortTimeCCG">ShortTimeCCG</a>'' for details).');
0124 end
0125
0126 otherwise,
0127 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help ShortTimeCCG">ShortTimeCCG</a>'' for details).']);
0128
0129 end
0130 end
0131
0132
0133 if isempty(overlap), overlap = 0.8*window; end
0134
0135
0136 start = min([times1(1) times2(1)]+window/2);
0137 stop = max([times1(end) times2(end)]-window/2);
0138 times1 = times1(:);
0139 times2 = times2(:);
0140 times = [times1;times2];
0141 groups = 1+[zeros(size(times1));ones(size(times2))];
0142 halfBins = round(duration/binSize/2);
0143
0144
0145 i = 1;
0146 t = start;
0147 ccg = [];
0148 while t+window/2 <= stop,
0149 x(i,1) = t;
0150 ok = InIntervals(times,t+[-0.5 0.5]*window);
0151 if sum(ok) < minEvents,
0152 ccg(1:(2*halfBins+1),i) = nan;
0153 else
0154 out = CCG(times(ok),groups(ok),'binSize',binSize,'duration',duration);
0155 if auto,
0156 ccg(:,i) = out(:,1,1);
0157 else
0158 ccg(:,i) = out(:,1,2);
0159 end
0160 end
0161 t = t + window - overlap;
0162 i = i + 1;
0163 end
0164
0165 y = (-duration/2:binSize:duration/2)';
0166
0167
0168 if auto,
0169 center = ceil(size(ccg,1)/2);
0170 ccg(center,:) = 0;
0171 end
0172
0173
0174 if strcmp(mode,'norm'),
0175 ccg = ccg ./ repmat(sum(ccg,1),size(ccg,1),1);
0176 end
0177
0178
0179 if ~isempty(smooth),
0180 ccg = Smooth(ccg,smooth);
0181 end