-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreshEstimate_v2.m
More file actions
89 lines (64 loc) · 2.48 KB
/
threshEstimate_v2.m
File metadata and controls
89 lines (64 loc) · 2.48 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function [ outthresh , outKclu ] = threshEstimate_v2( sampData , spkData, spkFS , posnegFlag )
%UNTITLED7 Summary of this function goes here
% Detailed explanation goes here
% V2 - Added negative threshold 12/31/2017
startThresh = 4;
startKclu = 6;
crit = true;
knCount = 0;
thCount = 0;
while crit
if posnegFlag
thresh = (mean(double(sampData)) + round(std(double(sampData)) * startThresh));
noise = (mean(double(sampData)) + round(std(double(sampData)) * 12));
else
thresh = (mean(double(sampData)) - round(std(double(sampData)) * startThresh));
noise = (mean(double(sampData)) - round(std(double(sampData)) * 12));
end
minDist = round(spkFS/1000) * 2; % was 1.9
[ waveData ] = extractWaveforms_Clz_v01(spkData, thresh, noise, minDist, spkFS);
waveForms = waveData.allWaves.waves;
% STEP 4 COMPILE FEATURES
if size(waveForms,2) < 7
outKclu = startKclu;
outthresh = startThresh;
return
end
[ xFeats ] = createSpkFeatures( waveForms, spkFS );
% STEP 5 OBTAIN INITIAL CLUSTERS
[idxF, Cen] = kmeans(xFeats,startKclu,'Distance','cityblock',...
'Replicates',6);
if size(xFeats,1) < 30
outKclu = startKclu;
outthresh = startThresh;
crit = false;
else
[ ~ , lmetrics , ~] = spkClusterQual( xFeats, idxF, Cen, 1 );
if startThresh <= 6
if all(lmetrics.IsDs < 20 | lmetrics.LRat > 0.4)
startThresh = startThresh + 0.5;
elseif any(lmetrics.IsDs > 20 | lmetrics.LRat < 0.4)
if sum(lmetrics.IsDs > 20 & lmetrics.LRat < 0.4) >= 2
outKclu = startKclu;
outthresh = startThresh;
crit = false;
else
if knCount == thCount
startThresh = startThresh + 0.5;
thCount = thCount + 1;
crit = true;
elseif knCount ~= thCount
startKclu = startKclu - 1;
knCount = knCount + 1;
crit = true;
end
end
end
else
outKclu = 5;
outthresh = 5;
crit = false;
end
end
end
end