-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinit.m
59 lines (44 loc) · 1.48 KB
/
init.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
57
58
59
% Initialization using traditional spike detection + clustering approach
%% Read probe configuration
configFile = 'V1x32-Poly2';
layout = Layout(configFile);
%% Create channel groups
num = 5;
overlap = 4;
ndx = bsxfun(@plus, 1 : num, (0 : (num - overlap) : numel(channels) - num)');
groups = channels(ndx);
nGroups = size(groups, 1);
%% Load raw data
T = 10; % minutes
% file = '/kyb/agmbrecordings/raw/Dennis/2014-08-01_12-35-36/2014-08-01_12-35-43/Electrophysiology%d.h5';
% file = '/kyb/agmbrecordings/raw/Charles/2014-06-26_13-17-59/2014-06-26_13-20-39/Electrophysiology%d.h5';
file = '/kyb/agmbrecordings/raw/Charles/2014-07-21_13-50-16/2014-07-21_13-52-57/Electrophysiology%d.h5';
br = baseReader(file, 's1c*');
Fs = getSamplingRate(br);
fr = filteredReader(br, filterFactory.createHighpass(400, 600, Fs));
V = fr(1 : Fs * T * 60, :);
V = toMuV(br, V);
% downsample
Nyq = 6000;
[p, q] = rat(2 * Nyq / Fs);
V = resample(V, p, q);
Fs = p / q * Fs;
%% detect and sort spikes in groups
df = 5;
results = struct('s', {}, 'w', {}, 'b', {}, 'model', {});
for i = 1 : nGroups
xi = V(:, groups(i, :));
[s, t] = detectSpikes(xi, Fs);
w = extractWaveforms(xi, s);
b = extractFeatures(w);
model = MixtureModel.fit(b, df);
results(i).s = s;
results(i).w = w;
results(i).b = b;
results(i).model = model;
end
%% remove doubles
X0 = keepMaxClusters(results, round(Fs * T * 60), 0.6);
%% extract spikes
bp = BP('V1x32-Poly2', 'pruningRadius', 55);
[X, W] = bp.fit(V, X0, 2);