-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfindActiveFrames.m
More file actions
63 lines (53 loc) · 1.87 KB
/
findActiveFrames.m
File metadata and controls
63 lines (53 loc) · 1.87 KB
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
57
58
59
60
61
62
63
function [data_high,pks_frame,pks] = findActiveFrames(data,pks)
% find high activity frame using a threshold determined from shuffled data
% INPUT:
% data: N-by-T spike matrix
% pks: significant level of frame activity; if left empty ([]), this
% function will determine its value using shuffled data
% OUTPUT:
% data_high: N-by-T' data matrix with only significant frames
% pks_frame: 1-by-T' vector containing indices of significant frames
% pks: value of the final threshold
%
% Shuting Han, 2017
% LCR Changed to S_index distributions to determine pks. The idea is that
% after some pk value the similarity between vectors in real data will be
% significantly higher than the similarity between vectors in random data
% some parameters
num_shuff = 100;
p = 0.98; %LCR
dims = size(data);
S_out = zeros(num_shuff);
% determine threshold from shuffled data
if isempty(pks)
% make shuffled data
data_shuff = zeros(dims(1),dims(2),num_shuff);
for ii = 1:num_shuff
data_shuff(:,:,ii) = shuffle(data,'time');
end
for n = 3:max(sum(data,1))
% find significant frames data
data_high = data(:,sum(data,1)>=n);
S = 1-pdist2(data_high',data_high','cosine');
% calculate similarity matrix shuffled
warning('off')
for ii = 1:num_shuff
data_high_rnd = data_shuff(:,sum(data_shuff(:,:,ii))>=n);
S_rd = 1-pdist2(data_high_rnd',data_high_rnd','cosine');
S_out(ii) = nanmean(S_rd(:));
end
warning('on')
% determine threshold
bins = 0:0.02:max(S_out);
cd = histc(S_out,bins);
cd = cumsum(cd/sum(cd));
scut = bins(find(cd>p,1));
if mean(S(:))>scut
pks = n;
break;
end
end
end
pks_frame = find(sum(data,1)>=pks);
data_high = data(:,pks_frame);
end