-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_alltrials_align.m
226 lines (188 loc) · 7.99 KB
/
get_alltrials_align.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
function [alltrials aligntime lut_trials]=get_alltrials_align(data,seltrials,wind,signal,info,targslist,sigma_FR,dispnan)
%[alltrials aligntime]=get_alltrials_align(data,seltrials,wind,signal,info,targslist,sigma_FR,dispnan)
% get all trials for each channels from data recorded with a laminar probe (LMA)
% spikes
% LFP
%
% seltrials: see select_trials
% wind: extracted windows over which signals will be analyzed
% dispnan: 1 if want to display trial where there are NaN values
%
% Corentin Massot
% Cognition and Sensorimotor Integration Lab, Neeraj J. Gandhi
% University of Pittsburgh
% created 07/06/2016 last modified 01/09/2017
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%timevec
if ~isempty(wind)
timevec=[wind(1):wind(2)];
else
timevec=[];
end
%seltrials
if isempty(seltrials)
seltrials=[1:numel(data)];
end
%initializations
nchs=numel(data(1).spikeTimestamps);
ntargs=size(targslist,1);
alltrials=cell(ntargs,1);
ntrials=zeros(ntargs,1);
ntrials_d=zeros(ntargs,1);
ntrials_n=zeros(ntargs,1);
%if dispnan,fignan=figure;hold off;end;
%trials loo-up table
lut_trials=cell(ntargs,1);
%get data only for selected_trials
for t=seltrials
%get target index for the trial
pos=data(t).offline.targpos;
it=find(pos(1,1)==targslist(:,1) & pos(1,2)==targslist(:,2));
%get data according to signal
option='';
switch info.align
% case 'no'
% switch signal
% case 'fr'
% trialsize=size(data(t).lfp,2)+20;
% trial=zeros(nchs,trialsize);
% for ch=1:nchs
% spiketimes=round(1000*data(t).spikeTimestamps{ch});
% spiketimes=spiketimes(find(spiketimes~=0));
% trial(ch,spiketimes)=1;
% end
% case 'lfp'
% trial=data(t).lfp;
% end
case 'targ'
code='targCode';
case 'go'
code='goCode';
case 'sacc'
code='sacc';
option='rpt'; %use .rpt file (EyeMove)
% if t==seltrials(1),data(t).offline.sacc_pburst_ch_align
% end
case 'peak'
code='peak';
%option='offline'; %use offline data
case 'targ_pburst'
code='targ_pburst';
case 'targ_pburst_ch'
code='targ_pburst_ch';
if t==seltrials(1),data(t).offline.targ_pburst_ch_align
end
case 'targ_rsburst'
code='targ_rsburst';
case 'targ_rsburst_ch'
code='targ_rsburst_ch';
if t==seltrials(1),data(t).offline.targ_rsburst_ch_align
end
case 'sacc_pburst'
code='sacc_pburst';
option='rpt'; %use .rpt file (EyeMove) for sacc
if t==seltrials(1),data(t).offline.sacc_pburst_ch_align
end
case 'sacc_rsburst'
code='sacc_rsburst';
option='rpt'; %use .rpt file (EyeMove) for sacc
if t==seltrials(1),data(t).offline.sacc_rsburst_ch_align
end
end
%get event and snippet of signal
%NOTE: there should not be missing event because select only successful trials
%t
%data(t).offline.targ_pburst_trial.b_begin
event_align = get_event(data(t),code,option);
%pause
% % data(t).offline
% lfpfeat=data(t).offline.lfpfeat.lfpfeat_sacc_1;
% event_align=event_align+round(lfpfeat(1))
% % %pause
if size(event_align,2)==1
trial = get_snippet(signal,data(t),event_align,timevec);
elseif size(event_align,2)>1
trial = get_snippet_ch(signal,data(t),event_align,timevec);
else
trial=NaN(nchs,1);
ntrials_n(it)=ntrials_n(it)+1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %signal filtering
% switch signal
% case 'fr'
% %compute firing rate of spiking activity
% for ch=1:nchs
% %gaussian filtering
% %trial(ch,:) = filter_FR(trial(ch,:),'gauss',1000,sigma_FR);
%
% %epsp filtering
% trial(ch,:) = filter_FR(trial(ch,:),'epsp',1000,1,6);
%
% %Chronux toolbox
% %[V,t,Err] = evoked(data,Fs,win,width,plt,err)
%
% end
%
% case 'lfp'
% % %remove 60Hz and harmonics
% % %bandpass digital filter design
% % [b60,a60]=butter(2,[(60-5)/500,(60+5)/500],'stop');
% % %[b60,a60]=butter(8,[(60)/500],'low');
% % %h = fvtool(b60,a60); % to visualize filter
% % %[b120,a120]=butter(2,[(120-2.5)/500,(120+2.5)/500],'stop');
% % %h = fvtool(b120,a120); %to visualize filter
% % trial60=zeros(size(trial));trial120=zeros(size(trial));
% % for ch=1:nchs
% % trial60(ch,:) = filtfilt(b60,a60,double(trial(ch,:)));
% % %trial120(ch,:) = filtfilt(b120,a120,double(trial(ch,:)));
% %
% % %figure;plot([1:length(trial)],trial(ch,:),'b');hold on
% % %plot([1:length(trial)],trial60(ch,:),'r');hold on
% % %%plot([1:length(trial)],trial120(ch,:),'g');hold on
% % %pause
% %
% % trial(ch,:)=trial60(ch,:);
% %
% % end
% end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%check if NaN values in trial
s=isnan(trial);
if sum(s(:))>=1
ntrials_d(it)=ntrials_d(it)+1;
% if dispnan
% figure(fignan);imagesc(~isnan(trial));axis ij; grid;
% colorbar;%('Ticks',[0,1]);%,'TickLabels',{'NaN','Value'});
% xlabel('Time (ms)');set(gca,'ytick', [1:16]);ylabel('Channels');
% title(['trial ' num2str(t) ' contains NaN values.']);
% display(['trial ' num2str(t) ' contains NaN values.']);
% pause(0.1)
% end
end
%creating list of trials (taking into account different sizes)
if ~isempty(alltrials{it}),alltrialsaux=alltrials{it};else alltrialsaux=[];end;
ntrials(it)=ntrials(it)+1;
if ntrials(it)==1, tlen=size(trial,2);else tlen=min(tlen,size(trial,2));end
%remapping of channels using info.chmap
alltrialsaux(:,ntrials(it),1:tlen)=trial(info.chmap(:),1:tlen);
%alltrialsaux(:,ntrials(it),1:tlen)=trial(:,1:tlen);
%update alltrials
alltrials{it}=alltrialsaux;
%update look-up table
lut_trials{it}=[lut_trials{it} t];
end
%aligntime (time of beginning of snippet in original signal)
if ~isempty(wind)
aligntime=abs(min(timevec));
else
aligntime=1;
end
%info
if dispnan
display([signal ' ' info.align])
display(['# of trials per channels: ' num2str(ntrials')])
display(['# of trials with NaN values per channels: ' num2str(ntrials_d')])
display(['# of trials with NaN values due to missing event: ' num2str(ntrials_n')])
display(['Duration of each trial: ' num2str(size(alltrials{1},3))])
end