Skip to content

Commit d42129e

Browse files
committed
changed params -> parameters | minor improvements
1 parent 72295f3 commit d42129e

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

code/matlab/pRF.m

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
%
2626
% Population receptive field (pRF) mapping tool.
2727
%
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
3030
% - f_sampling: sampling frequency (1/TR)
3131
% - n_samples : number of samples (volumes)
3232
% - n_rows : number of rows (in-plane resolution)
@@ -57,7 +57,7 @@
5757
% (e.g. help pRF.mapping)
5858
%
5959
% typical workflow:
60-
% 1. prf = pRF(params);
60+
% 1. prf = pRF(parameters);
6161
% 2. prf.import_stimulus();
6262
% 3. prf.create_timecourses();
6363
% 4. results = prf.mapping(data);
@@ -92,12 +92,12 @@
9292

9393
methods (Access = public)
9494

95-
function self = pRF(params,varargin)
95+
function self = pRF(parameters,varargin)
9696
% constructor
9797
p = inputParser;
98-
addRequired(p,'params',@isstruct);
98+
addRequired(p,'parameters',@isstruct);
9999
addOptional(p,'hrf',[]);
100-
p.parse(params,varargin{:});
100+
p.parse(parameters,varargin{:});
101101

102102
self.is = 'pRF mapping tool';
103103

@@ -106,14 +106,14 @@
106106
self.gauss = @(mu_x,mu_y,sigma,X,Y) exp(-((X-mu_x).^2+...
107107
(Y-mu_y).^2)/(2*sigma^2));
108108

109-
self.f_sampling = p.Results.params.f_sampling;
109+
self.f_sampling = p.Results.parameters.f_sampling;
110110
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;
115115
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;
117117

118118
if ~isempty(p.Results.hrf)
119119
self.l_hrf = size(p.Results.hrf,1);
@@ -237,10 +237,10 @@ function create_timecourses(self,varargin)
237237
%
238238
% optional inputs are
239239
% - 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)
241241
% - min_slope : lower bound of RF size slope (default = 0.1)
242242
% - 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)
244244

245245
text = 'creating timecourses...';
246246
fprintf('%s\n',text)
@@ -252,26 +252,26 @@ function create_timecourses(self,varargin)
252252
addOptional(p,'num_slope',10);
253253
addOptional(p,'min_slope',0.1);
254254
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');
257257
p.parse(varargin{:});
258258

259259
num_xy = p.Results.num_xy;
260-
max_r = p.Results.max_radius;
260+
max_radius = p.Results.max_radius;
261261
num_slope = p.Results.num_slope;
262262
min_slope = p.Results.min_slope;
263263
max_slope = p.Results.max_slope;
264264
css_exponent = p.Results.css_exponent;
265265
sampling = p.Results.sampling;
266266
self.n_points = num_xy^2 * num_slope;
267267

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,...
271271
self.r_stimulus)' * ones(1,self.r_stimulus);
272272

273-
X_ = reshape(X_,self.r_stimulus^2,1);
274-
Y_ = reshape(Y_,self.r_stimulus^2,1);
273+
X_ = X_(:);
274+
Y_ = Y_(:);
275275

276276
i = (0:self.n_points-1)';
277277
self.idx = [floor(i/(num_xy*num_slope))+1,...
@@ -342,7 +342,7 @@ function create_timecourses(self,varargin)
342342
data = reshape(data(1:self.n_samples,:,:,:),...
343343
self.n_samples,self.n_total);
344344
mean_signal = mean(data);
345-
data = zscore(data);
345+
346346

347347
if isempty(mask)
348348
mask = mean_signal>=threshold;
@@ -351,14 +351,14 @@ function create_timecourses(self,varargin)
351351
voxel_index = find(mask);
352352
n_voxels = numel(voxel_index);
353353

354-
mag_d = sqrt(sum(data(:,mask).^2));
354+
data = zscore(data(:,mask));
355+
mag_d = sqrt(sum(data.^2));
355356

356357
results.corr_fit = zeros(self.n_total,1);
357358
results.mu_x = zeros(self.n_total,1);
358359
results.mu_y = zeros(self.n_total,1);
359360
results.sigma = zeros(self.n_total,1);
360361

361-
362362
if size(self.hrf,2)==1
363363
hrf_fft = fft(repmat([self.hrf;...
364364
zeros(self.n_samples-self.l_hrf,1)],...
@@ -368,7 +368,7 @@ function create_timecourses(self,varargin)
368368
for m=1:n_voxels
369369
v = voxel_index(m);
370370

371-
CS = (tc*data(:,v))./...
371+
CS = (tc*data(:,m))./...
372372
(mag_tc*mag_d(m));
373373
id = isinf(CS) | isnan(CS);
374374
CS(id) = 0;
@@ -383,17 +383,15 @@ function create_timecourses(self,varargin)
383383
waitbar(v/n_voxels,wb)
384384
end
385385
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)]);
388388
for m=1:n_voxels
389389
v = voxel_index(m);
390390

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)))';
394392
mag_tc = sqrt(sum(tc.^2,2));
395393

396-
CS = (tc*data(:,v))./...
394+
CS = (tc*data(:,m))./...
397395
(mag_tc*mag_d(m));
398396
id = isinf(CS) | isnan(CS);
399397
CS(id) = 0;

0 commit comments

Comments
 (0)