-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeSpikeAvg.m
More file actions
64 lines (53 loc) · 2.13 KB
/
makeSpikeAvg.m
File metadata and controls
64 lines (53 loc) · 2.13 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
function data = makeSpikeAvg(data)
spikeBarrier = .5; % Spike Widths
colorList = [pretty(1);pretty(4);pretty(5);pretty(2);[1,0,1];pretty(7);pretty(8)];
% Remove old averages
data.spikeAvg = {};
% ffsubplot(2,1,1);
% For each cluster make an average
clusterList = unique(data.spikeClusters);
spikeHalfWidth = round(data.spikeWidth/2*data.sampleRate);
for clustNn = 1:length(clusterList)
clustN = clusterList(clustNn);
% Get a spike triggered average for each cluster
ix = find(data.spikeClusters == clustN);
sampIxs = data.spikeSamples(ix);
allSpikes = [];
for sampIxN = 1:length(sampIxs)
sampIx = sampIxs(sampIxN);
% Only average well separated spikes
spikeDiffs = sampIx - data.spikeSamples(:);
ix = find(spikeDiffs == 0);
spikeDiffs(ix) = [];
if (min(abs(spikeDiffs)) > 2*spikeBarrier*spikeHalfWidth)
stSamp = sampIx - spikeHalfWidth;
enSamp = sampIx + spikeHalfWidth;
if ((stSamp > 0) && (enSamp < length(data.dVdT)))
allSpikes(:,end+1) = data.dVdT(stSamp:enSamp);
end
end
end
% But if you don't find any, use them all
if (size(allSpikes,2) == 0)
for sampIxN = 1:length(sampIxs)
sampIx = sampIxs(sampIxN);
stSamp = sampIx - spikeHalfWidth;
enSamp = sampIx + spikeHalfWidth;
if ((stSamp > 0) && (enSamp < length(data.dVdT)))
allSpikes(:,end+1) = data.dVdT(stSamp:enSamp);
end
end
end
% Make a zero-waveform for empty clusters
if size(allSpikes, 2) == 0
data.spikeAvg{clustN} = zeros(2*spikeHalfWidth+1,1);
else
data.spikeAvg{clustN} = mean(allSpikes,2);
end
% for n = 1:size(allSpikes,2)
% plot(allSpikes(:,n),'Color',colorList(clustN,:)); hold on;
%
% end
% xlim([20 80]);
% axis square;
end