34
34
% - n_slices : number of slices
35
35
%
36
36
% optional inputs are
37
- % - hrf : either a column vector containing a single hemodynamic
37
+ % - hrf : either a column vector containing a single hemodynamic
38
38
% response used for every voxel;
39
39
% or a matrix with a unique hemodynamic response along
40
40
% its columns for each voxel.
41
- % By default the canonical two-gamma hemodynamic response
41
+ % By default the canonical two-gamma hemodynamic response
42
42
% function is generated internally based on the scan parameters.
43
43
%
44
44
% this class has the following functions
125
125
126
126
function hrf = get_hrf(self )
127
127
% returns the hemodynamic response used by the class.
128
- % If a single hrf is used for every voxel, this function
128
+ % If a single hrf is used for every voxel, this function
129
129
% returns a column vector.
130
- % If a unique hrf is used for each voxel, this function returns
130
+ % If a unique hrf is used for each voxel, this function returns
131
131
% a matrix with columns corresponding to time and the remaining
132
132
% dimensions reflecting the spatial dimensions of the data.
133
133
if size(self .hrf ,2 )>1
144
144
end
145
145
146
146
function tc = get_timecourses(self )
147
- % returns the timecourses predicted based on the stimulus
148
- % protocol and each combination of the input-referred model
147
+ % returns the timecourses predicted based on the stimulus
148
+ % protocol and each combination of the input-referred model
149
149
% parameters as a time-by-combinations matrix.
150
- % Note that the predicted timecourses have not been convolved
150
+ % Note that the predicted timecourses have not been convolved
151
151
% with a hemodynamic response.
152
152
tc = ifft(self .tc_fft );
153
153
end
@@ -170,7 +170,7 @@ function set_stimulus(self,stimulus)
170
170
end
171
171
172
172
function create_timecourse(self ,FUN ,xdata )
173
- % creates predicted timecourses based on the stimulus protocol
173
+ % creates predicted timecourses based on the stimulus protocol
174
174
% and a range of parameters for an input referred model.
175
175
%
176
176
% required inputs are
@@ -195,7 +195,7 @@ function create_timecourse(self,FUN,xdata)
195
195
196
196
for p= 1 : self .n_predictors
197
197
self .idx(: ,p ) = mod(floor(i / prod(n_observations(p + 1 : end ))),...
198
- n_observations(p )) + 1 ;
198
+ n_observations(p )) + 1 ;
199
199
end
200
200
201
201
tc = zeros(self .n_samples ,self .n_points );
@@ -217,9 +217,9 @@ function create_timecourse(self,FUN,xdata)
217
217
% returns the corresponding parameter values of the
218
218
% input-referred model. The class returns a structure with two
219
219
% fields.
220
- % - R: correlations (fit) - dimension corresponds to the
220
+ % - R: correlations (fit) - dimension corresponds to the
221
221
% dimensions of the data.
222
- % - P: estimate parameters - dimension corresponds to the
222
+ % - P: estimate parameters - dimension corresponds to the
223
223
% dimensions of the data + 1.
224
224
%
225
225
% required inputs are
@@ -228,6 +228,7 @@ function create_timecourse(self,FUN,xdata)
228
228
%
229
229
% optional inputs are
230
230
% - threshold: minimum voxel intensity (default = 100.0)
231
+ % - mask : binary mask for selecting voxels
231
232
232
233
text = ' mapping input-referred model...' ;
233
234
fprintf(' %s\n ' ,text )
@@ -236,16 +237,26 @@ function create_timecourse(self,FUN,xdata)
236
237
p = inputParser ;
237
238
addRequired(p ,' data' ,@isnumeric );
238
239
addOptional(p ,' threshold' ,100 );
240
+ addOptional(p ,' mask' ,[]);
239
241
p .parse(data ,varargin{: });
240
242
241
243
data = p .Results .data ;
242
244
threshold = p .Results .threshold ;
245
+ mask = p .Results .mask ;
243
246
244
247
data = reshape(data(1 : self .n_samples ,: ,: ,: ),...
245
248
self .n_samples ,self .n_total );
246
249
mean_signal = mean(data );
247
250
data = zscore(data );
248
- mag_d = sqrt(sum(data .^ 2 ));
251
+
252
+ if isempty(mask )
253
+ mask = mean_signal >= threshold ;
254
+ end
255
+ mask = mask(: );
256
+ voxel_index = find(mask );
257
+ n_voxels = numel(voxel_index );
258
+
259
+ mag_d = sqrt(sum(data(: ,mask ).^2 ));
249
260
250
261
results.R = zeros(self .n_total ,1 );
251
262
results.P = zeros(self .n_total ,self .n_predictors );
@@ -257,38 +268,40 @@ function create_timecourse(self,FUN,xdata)
257
268
tc = zscore(ifft(self .tc_fft .* hrf_fft ))' ;
258
269
259
270
mag_tc = sqrt(sum(tc .^ 2 ,2 ));
260
- for v = 1 : self . n_total
261
- if mean_signal( v )> threshold
262
- CS = ( tc * data( : , v ))./...
263
- ( mag_tc * mag_d( v ));
264
- id = isinf( CS ) | isnan( CS );
265
- CS( id ) = 0 ;
266
- [ results .R( v ), j ] = max( CS ) ;
267
- for p = 1 : self . n_predictors
268
- results .P( v , p ) = self.xdata{ p }( self .idx( j , p ));
269
- end
271
+ for m = 1 : n_voxels
272
+ v = voxel_index( m );
273
+
274
+ CS = ( tc * data( : , v ))./...
275
+ ( mag_tc * mag_d( v ) );
276
+ id = isinf( CS ) | isnan( CS ) ;
277
+ CS( id ) = 0 ;
278
+ [ results .R( v ), j ] = max( CS );
279
+ for p = 1 : self .n_predictors
280
+ results .P( v , p ) = self.xdata{ p }( self .idx( j , p ));
270
281
end
282
+
271
283
waitbar(v / self .n_total ,wb )
272
284
end
273
285
else
274
286
hrf_fft_all = fft([self .hrf ;...
275
287
zeros(self .n_samples - self .l_hrf ,self .n_total )]);
276
- for v = 1 : self . n_total
277
- if mean_signal( v )> threshold
278
- hrf_fft = repmat(hrf_fft_all( : , v ),...
279
- [ 1 , self . n_points ]);
280
- tc = zscore(ifft( self .tc_fft .* hrf_fft )) ' ;
281
- mag_tc = sqrt(sum( tc .^ 2 , 2 )) ;
282
-
283
- CS = ( tc * data( : , v ))./...
284
- ( mag_tc * mag_d( v ));
285
- id = isinf( CS ) | isnan( CS );
286
- CS( id ) = 0 ;
287
- [ results .R( v ), j ] = max( CS ) ;
288
- for p = 1 : self . n_predictors
289
- results .P( v , p ) = self .xdata( self .idx( j , p ), p );
290
- end
288
+ for m = 1 : n_voxels
289
+ v = voxel_index( m );
290
+
291
+ hrf_fft = repmat(hrf_fft_all( : , v ),...
292
+ [ 1 , self .n_points ]) ;
293
+ tc = zscore(ifft( self . tc_fft .* hrf_fft )) ' ;
294
+ mag_tc = sqrt(sum( tc .^ 2 , 2 ));
295
+
296
+ CS = ( tc * data( : , v ))./...
297
+ ( mag_tc * mag_d( v ) );
298
+ id = isinf( CS ) | isnan( CS ) ;
299
+ CS( id ) = 0 ;
300
+ [ results .R( v ), j ] = max( CS );
301
+ for p = 1 : self .n_predictors
302
+ results .P( v , p ) = self .xdata( self .idx( j , p ), p );
291
303
end
304
+
292
305
waitbar(v / self .n_total ,wb )
293
306
end
294
307
end
0 commit comments