25
25
%
26
26
% Population receptive field (pRF) mapping tool.
27
27
%
28
- % prf = pRF(params ) creates an instance of the pRF class.
29
- % params is a structure with 7 required fields
28
+ % prf = pRF(parameters ) creates an instance of the pRF class.
29
+ % parameters is a structure with 7 required fields
30
30
% - f_sampling: sampling frequency (1/TR)
31
31
% - n_samples : number of samples (volumes)
32
32
% - n_rows : number of rows (in-plane resolution)
57
57
% (e.g. help pRF.mapping)
58
58
%
59
59
% typical workflow:
60
- % 1. prf = pRF(params );
60
+ % 1. prf = pRF(parameters );
61
61
% 2. prf.import_stimulus();
62
62
% 3. prf.create_timecourses();
63
63
% 4. results = prf.mapping(data);
92
92
93
93
methods (Access = public )
94
94
95
- function self = pRF(params ,varargin )
95
+ function self = pRF(parameters ,varargin )
96
96
% constructor
97
97
p = inputParser ;
98
- addRequired(p ,' params ' ,@isstruct );
98
+ addRequired(p ,' parameters ' ,@isstruct );
99
99
addOptional(p ,' hrf' ,[]);
100
- p .parse(params ,varargin{: });
100
+ p .parse(parameters ,varargin{: });
101
101
102
102
self.is = ' pRF mapping tool' ;
103
103
106
106
self.gauss = @(mu_x ,mu_y ,sigma ,X ,Y ) exp(-((X - mu_x ).^2 + ...
107
107
(Y - mu_y ).^2 )/(2 * sigma ^ 2 ));
108
108
109
- self.f_sampling = p .Results .params .f_sampling ;
109
+ self.f_sampling = p .Results .parameters .f_sampling ;
110
110
self.p_sampling = 1 / self .f_sampling ;
111
- self.n_samples = p .Results .params .n_samples ;
112
- self.n_rows = p .Results .params .n_rows ;
113
- self.n_cols = p .Results .params .n_cols ;
114
- self.n_slices = p .Results .params .n_slices ;
111
+ self.n_samples = p .Results .parameters .n_samples ;
112
+ self.n_rows = p .Results .parameters .n_rows ;
113
+ self.n_cols = p .Results .parameters .n_cols ;
114
+ self.n_slices = p .Results .parameters .n_slices ;
115
115
self.n_total = self .n_rows * self .n_cols * self .n_slices ;
116
- self.r_stimulus = p .Results .params .r_stimulus ;
116
+ self.r_stimulus = p .Results .parameters .r_stimulus ;
117
117
118
118
if ~isempty(p .Results .hrf )
119
119
self.l_hrf = size(p .Results .hrf ,1 );
@@ -237,10 +237,10 @@ function create_timecourses(self,varargin)
237
237
%
238
238
% optional inputs are
239
239
% - max_radius : radius of the field of fiew (default = 10.0)
240
- % - num_xy : steps in x and y direction (default = 30.0)
240
+ % - num_xy : steps in x and y direction (default = 30.0)
241
241
% - min_slope : lower bound of RF size slope (default = 0.1)
242
242
% - max_slope : upper bound of RF size slope (default = 1.2)
243
- % - num_slope: steps from lower to upper bound (default = 10.0)
243
+ % - num_slope : steps from lower to upper bound (default = 10.0)
244
244
245
245
text = ' creating timecourses...' ;
246
246
fprintf(' %s\n ' ,text )
@@ -252,26 +252,26 @@ function create_timecourses(self,varargin)
252
252
addOptional(p ,' num_slope' ,10 );
253
253
addOptional(p ,' min_slope' ,0.1 );
254
254
addOptional(p ,' max_slope' ,1.2 );
255
- addoptional (p ,' css_exponent' ,1 );
256
- addoptional (p ,' sampling' ,' log' );
255
+ addOptional (p ,' css_exponent' ,1 );
256
+ addOptional (p ,' sampling' ,' log' );
257
257
p .parse(varargin{: });
258
258
259
259
num_xy = p .Results .num_xy ;
260
- max_r = p .Results .max_radius ;
260
+ max_radius = p .Results .max_radius ;
261
261
num_slope = p .Results .num_slope ;
262
262
min_slope = p .Results .min_slope ;
263
263
max_slope = p .Results .max_slope ;
264
264
css_exponent = p .Results .css_exponent ;
265
265
sampling = p .Results .sampling ;
266
266
self.n_points = num_xy ^ 2 * num_slope ;
267
267
268
- X_ = ones(self .r_stimulus ,1 ) * linspace(-max_r ,...
269
- max_r ,self .r_stimulus );
270
- Y_ = - linspace(-max_r , max_r ,...
268
+ X_ = ones(self .r_stimulus ,1 ) * linspace(-max_radius ,...
269
+ max_radius ,self .r_stimulus );
270
+ Y_ = - linspace(-max_radius , max_radius ,...
271
271
self .r_stimulus )' * ones(1 ,self .r_stimulus );
272
272
273
- X_ = reshape( X_ , self . r_stimulus ^ 2 , 1 );
274
- Y_ = reshape( Y_ , self . r_stimulus ^ 2 , 1 );
273
+ X_ = X_( : );
274
+ Y_ = Y_( : );
275
275
276
276
i = (0 : self .n_points - 1 )' ;
277
277
self.idx = [floor(i /(num_xy * num_slope ))+1 ,...
@@ -342,7 +342,7 @@ function create_timecourses(self,varargin)
342
342
data = reshape(data(1 : self .n_samples ,: ,: ,: ),...
343
343
self .n_samples ,self .n_total );
344
344
mean_signal = mean(data );
345
- data = zscore( data );
345
+
346
346
347
347
if isempty(mask )
348
348
mask = mean_signal >= threshold ;
@@ -351,14 +351,14 @@ function create_timecourses(self,varargin)
351
351
voxel_index = find(mask );
352
352
n_voxels = numel(voxel_index );
353
353
354
- mag_d = sqrt(sum(data(: ,mask ).^2 ));
354
+ data = zscore(data(: ,mask ));
355
+ mag_d = sqrt(sum(data .^ 2 ));
355
356
356
357
results.corr_fit = zeros(self .n_total ,1 );
357
358
results.mu_x = zeros(self .n_total ,1 );
358
359
results.mu_y = zeros(self .n_total ,1 );
359
360
results.sigma = zeros(self .n_total ,1 );
360
361
361
-
362
362
if size(self .hrf ,2 )==1
363
363
hrf_fft = fft(repmat([self .hrf ;...
364
364
zeros(self .n_samples - self .l_hrf ,1 )],...
@@ -368,7 +368,7 @@ function create_timecourses(self,varargin)
368
368
for m= 1 : n_voxels
369
369
v = voxel_index(m );
370
370
371
- CS = (tc * data(: ,v ))./...
371
+ CS = (tc * data(: ,m ))./...
372
372
(mag_tc * mag_d(m ));
373
373
id = isinf(CS ) | isnan(CS );
374
374
CS(id ) = 0 ;
@@ -383,17 +383,15 @@ function create_timecourses(self,varargin)
383
383
waitbar(v / n_voxels ,wb )
384
384
end
385
385
else
386
- hrf_fft_all = fft([self .hrf ;...
387
- zeros(self .n_samples - self .l_hrf ,self . n_total )]);
386
+ hrf_fft_all = fft([self .hrf( : , mask ) ;...
387
+ zeros(self .n_samples - self .l_hrf ,n_voxels )]);
388
388
for m= 1 : n_voxels
389
389
v = voxel_index(m );
390
390
391
- hrf_fft = repmat(hrf_fft_all(: ,v ),...
392
- [1 ,self .n_points ]);
393
- tc = zscore(ifft(self .tc_fft .* hrf_fft ))' ;
391
+ tc = zscore(ifft(self .tc_fft .* hrf_fft_all(: ,m )))' ;
394
392
mag_tc = sqrt(sum(tc .^ 2 ,2 ));
395
393
396
- CS = (tc * data(: ,v ))./...
394
+ CS = (tc * data(: ,m ))./...
397
395
(mag_tc * mag_d(m ));
398
396
id = isinf(CS ) | isnan(CS );
399
397
CS(id ) = 0 ;
0 commit comments