comparison utilities/UTIL_CV.m @ 0:f233164f4c86

first commit
author Ray Meddis <rmeddis@essex.ac.uk>
date Fri, 27 May 2011 13:19:21 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f233164f4c86
1 function [cv, cvTimes, allTimeStamps, allISIs]= UTIL_CV(earObject, dt, timeStep)
2 % UTIL_CV computes coefficient of variation for multiple spike trains
3 % earObject must be logical 0/1. Each row is a separate run
4 % CV is computed for successive time regions specified by timeStep
5
6 if ~islogical(earObject),error('UTIL_CV: input is not logical/ spikes'), end
7
8 [rows cols]=size(earObject);
9 totalDuration=cols*dt;
10
11 if nargin<3, timeStep=totalDuration/5; end
12
13 % identify all intervals
14 allISIs=[]; allTimeStamps=[];
15 for i=1:rows
16 temp=find(earObject(i,:))*dt; % find spikes
17 isi{i}=diff(temp); % find ISIs
18 timeStamps{i}=temp(2:end); % time of isi is time of second spike
19 allISIs=[allISIs isi{i}];
20 allTimeStamps=[allTimeStamps timeStamps{i}];
21 end
22
23 count=0;
24 cvTimes=0: timeStep:totalDuration-timeStep; % bin edges
25 for t= cvTimes
26 % sort ISIs according to when they happened
27 idx=find(allTimeStamps>t & allTimeStamps<=t+timeStep);
28 count=count+1;
29 if ~isempty(allISIs(idx))
30 cv(count)=std(allISIs(idx))/mean(allISIs(idx));
31 else
32 cv(count)=0;
33 end
34 end
35