-
Notifications
You must be signed in to change notification settings - Fork 0
/
slide_waveforms.m
72 lines (63 loc) · 2.46 KB
/
slide_waveforms.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
60
61
62
63
64
65
66
67
68
69
70
71
72
function slide_waveforms(handles,direction)
%SLIDE_WAVEFORMS Move waveforms left or right to align peak
% SLIDE_WAVEFORMS Shifts all waveforms to the left or to the right until the maximum peak on the current channel is
% aligned with t=0.
%
% Written by Marshall Crumiller
% email: [email protected]
%
% Updates
% 2015-06-03: Created
%-----------------------------------------------------------------------------------------------------------------------
global waveforms palette;
% we need to look for peaks to the right of the current peak, of opposite
% polarity
idx=getappdata(handles.output,'idx');
selected_waveforms=getappdata(handles.output,'selected_waveforms');
cluster_number=getappdata(handles.output,'cluster_number');
if(isempty(selected_waveforms))
selected_waveforms=idx==cluster_number;
end
% get selected channels
selected_channels=getappdata(handles.output,'selected_channels');
if(sum(selected_channels)~=1 && length(selected_channels)>1)
set(handles.status_label,'String','This action can only be performed if with a single channel selected.');
set(handles.status_light,'BackgroundColor',palette.orange);
return;
end
if(~any(selected_channels)),selected_channels=~selected_channels; end
t=getappdata(handles.output,'t');
zeroloc=find(t==0);
% move waveforms left
if(direction==-1)
wfs = squeeze(waveforms(selected_channels,selected_waveforms,zeroloc:end));
t=t(zeroloc:end);
%peak_sin = sign(mean(wfs(:,1)));
% move waveforms right
else
wfs = squeeze(waveforms(selected_channels,selected_waveforms,1:zeroloc));
t=t(1:zeroloc);
%peak_sin = sign(mean(wfs(:,end)));
end
%if(peak_sin==1), wfs=-wfs; end
wfs=abs(wfs);
% find peak, set a threshold of 1
[peaks,peaklocs] = find_peaks(wfs,std(wfs(:)));
if(isempty(peaks)),return; end
[~,locs]=max(peaks,[],2);
inds=sub2ind(size(peaklocs),1:size(peaklocs,1),locs');
peaklocs=peaklocs(inds);
timestamp_locs=peaklocs~=0;
peaklocs=peaklocs(timestamp_locs);
offset=t(peaklocs);
timestamps=getappdata(handles.output,'timestamps');
s=find(selected_waveforms);
timestamps(s(timestamp_locs))=timestamps(s(timestamp_locs))+offset;
setappdata(handles.output,'timestamps',timestamps);
% update trigger channels for these waveforms
trigger_ch=getappdata(handles.output,'trigger_ch');
trigger_ch(s(timestamp_locs))=find(selected_channels);
setappdata(handles.output,'trigger_ch',trigger_ch);
setappdata(handles.output,'selected_waveforms',[]);
capture_waveforms(handles);
show_featurespanel(handles);