-
Notifications
You must be signed in to change notification settings - Fork 0
/
dfa_ripfeatures_bytet.m
56 lines (42 loc) · 1.78 KB
/
dfa_ripfeatures_bytet.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function out = dfa_ripfeatures_bytet(index, excludeperiods, ripple, ripdecodes, marks, varargin)
% part 1 of ripfeatures: compute instantaneous ripple band frequency and # spikes during event per tetrode
% output: per-tet riptsz equivalent [time instfreq numspikes]
% Options:
% appendindex-- Determines whether index is included in output vector
% Default: 1
%parse the options
Fs = 1500;
appendindex = 1;
ripthresh = 2;
% process varargin if present and overwrite default values
if (~isempty(varargin))
assign(varargin{:});
end
d = index(1);
e = index(2);
t = index(3); % use for indexing into the appropriate marks cell
if isempty(ripdecodes) || length(ripdecodes{d})< e || isempty(ripdecodes{d}{e})
out.riptsz = [];
else
q = ripdecodes{d}{e};
% exclude events during mobility, calc instfreq of each
immoevents = ~isExcluded(q.riptimes(:,1), excludeperiods) & ~isExcluded(q.riptimes(:,2), excludeperiods);
overthresh = q.ripsizes>ripthresh;
ripstarttimes = q.riptimes(immoevents & overthresh,1);
ripendtimes = q.riptimes(immoevents & overthresh,2);
eegtimesvec = geteegtimes(ripple{d}{e}{index(3)});
startinds = lookup(ripstarttimes,eegtimesvec);
endinds = lookup(ripendtimes,eegtimesvec);
for r = 1:length(startinds)
% Calculate distance between peaks of rip filtered data for each rip
[pks, pkinds] = findpeaks(double(ripple{d}{e}{t}.data(startinds(r):endinds(r),1)));
instfreq(r) = mean(Fs./diff(pkinds));
% count number of marks on this tet during each rip
spikenum(r) = sum(marks{d}{e}{t}.times>=ripstarttimes(r) & marks{d}{e}{t}.times<=ripendtimes(r));
end
out.riptsz = [ripstarttimes instfreq' spikenum'];
end
if appendindex
out.index = index;
end
end