-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_snippet_ch.m
102 lines (91 loc) · 3.95 KB
/
get_snippet_ch.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function snippet=get_snippet_ch(signal,trial,event_align,timevec)
%function snippet=get_snippet_ch(signal,trial,event_align,timevec)
% get snippet of spiketimes in timevec based on event that is different
% for each trial
%
% see also compute_fr
%
% Corentin Massot based on Uday Jagadisan's code
% Cognition and Sensorimotor Integration Lab, Neeraj J. Gandhi
% University of Pittsburgh
% created 10/17/2017 last modified 10/17/2017
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%nchs
nchs=numel(trial.spikeTimestamps);
%timevec
if isempty(timevec)
timevec=[1:size(trial.lfp,2)];
end
snippet=nan(nchs,length(timevec));
switch signal
case 'spk'
for ch=1:nchs
if event_align(ch)~=0
spiketimes=round(1000*trial.spikeTimestamps{ch});
spiketimes_align = spiketimes - event_align(ch);
ind = ismember(spiketimes_align,timevec);
%NOTE:hist (spike may be = 2 or 3 because of round to nearest integer)
snippet(ch,:)= hist(spiketimes_align(ind),timevec);
end
end
case 'fr'
%get fr (see also compute_fr)
trial_fr=trial.offline.fr_epsp_6;
for ch=1:nchs
if event_align(ch)~=0
pre = event_align(ch)+min(timevec);
post = event_align(ch)+max(timevec);
if pre<0;
%NOTE: if pre<0, adjust wind lim instead of risking alignment error
display('Error: inferior lim of wind is outside lfp signal!')
pause
elseif pre>0 & post<=size(trial_fr,2)
snippet(ch,:) = trial_fr(ch,event_align(ch)+timevec);
elseif post>size(trial_fr,2)
%display('Warning: lfp signal shorter than wind limit!')
lfpaux=[trial_fr(ch,:),NaN(1,post-size(trial_fr,2))];
snippet(ch,:) = lfpaux(event_align(ch)+timevec);
end
end
end
case 'lfp'
for ch=1:nchs
if event_align(ch)~=0
pre = event_align(ch)+min(timevec);
post = event_align(ch)+max(timevec);
if pre<0;
%NOTE: if pre<0, adjust wind lim instead of risking alignment error
display('Error: inferior lim of wind is outside lfp signal!')
pause
elseif pre>0 & post<=size(trial.lfp,2)
snippet(ch,:) = trial.lfp(ch,event_align(ch)+timevec);
elseif post>size(trial.lfp,2)
%display('Warning: lfp signal shorter than wind limit!')
lfpaux=[trial.lfp(ch,:),NaN(1,post-size(trial.lfp,2))];
snippet(ch,:) = lfpaux(event_align(ch)+timevec);
end
end
end
case 'raw'
samp=30;%30KHz
for ch=1:nchs
if event_align(ch)~=0
pre = samp*(event_align(ch)+min(timevec));
post = samp*(event_align(ch)+max(timevec));
timings=samp*event_align(ch)+ [samp*min(timevec):1:samp*max(timevec)];
if pre<0;
%NOTE: if pre<0, adjust wind lim instead of risking alignment error
display('Error: inferior lim of wind is outside raw signal!')
pause
elseif pre>0 & post<=size(trial.raw,2)
snippet(ch,:) = trial.raw(ch,timings);
elseif post>size(trial.raw,2)
%display('Warning: raw signal shorter than wind limit!')
rawpaux=[trial.raw(ch,:),NaN(1,post-size(trial.raw,2))];
snippet(ch,:) = rawpaux(timings);
end
else
snippet(ch,:)=nan;
end
end
end