Skip to content

Commit 9ed183d

Browse files
committed
improved variable naming | made more obvious that stimulus images need to be square | added option for linear sampling of VF | added compressive spatial summation
1 parent dc2a8d5 commit 9ed183d

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

code/matlab/pRF.m

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
% - n_rows : number of rows (in-plane resolution)
3333
% - n_cols : number of columns (in-plance resolution)
3434
% - n_slices : number of slices
35-
% - w_stimulus: width of stimulus images in pixels
36-
% - h_stimulus: height of stimulus images in pixels
35+
% - r_stimulus: width/height of stimulus images in pixels
3736
%
3837
% optional inputs are
3938
% - hrf : either a column vector containing a single hemodynamic
@@ -81,8 +80,7 @@
8180
n_slices
8281
n_total
8382
l_hrf
84-
w_stimulus
85-
h_stimulus
83+
r_stimulus
8684
idx
8785
ecc
8886
pa
@@ -115,8 +113,8 @@
115113
self.n_cols = p.Results.params.n_cols;
116114
self.n_slices = p.Results.params.n_slices;
117115
self.n_total = self.n_rows*self.n_cols*self.n_slices;
118-
self.w_stimulus = p.Results.params.w_stimulus;
119-
self.h_stimulus = p.Results.params.h_stimulus;
116+
self.r_stimulus = p.Results.params.r_stimulus;
117+
120118
if ~isempty(p.Results.hrf)
121119
self.l_hrf = size(p.Results.hrf,1);
122120
if ndims(p.Results.hrf)>2
@@ -151,8 +149,8 @@
151149
function stimulus = get_stimulus(self)
152150
% returns the stimulus used by the class as a 3D matrix of
153151
% dimensions height-by-width-by-time.
154-
stimulus = reshape(self.stimulus,self.h_stimulus,...
155-
self.w_stimulus,self.n_samples);
152+
stimulus = reshape(self.stimulus,self.r_stimulus,...
153+
self.r_stimulus,self.n_samples);
156154
end
157155

158156
function tc = get_timecourses(self)
@@ -184,7 +182,7 @@ function set_stimulus(self,stimulus)
184182
% (height-by-width-by-time) or 2D (height*width-by-time).
185183
if ndims(stimulus)==3
186184
self.stimulus = reshape(stimulus,...
187-
self.w_stimulus*self.h_stimulus,...
185+
self.r_stimulus^2,...
188186
self.n_samples);
189187
else
190188
self.stimulus = stimulus;
@@ -206,7 +204,7 @@ function import_stimulus(self)
206204
wb = waitbar(0,text,'Name',self.is);
207205

208206
im = imread([path,files(1).name]);
209-
self.stimulus = zeros(self.h_stimulus,self.w_stimulus,...
207+
self.stimulus = zeros(self.r_stimulus,self.r_stimulus,...
210208
self.n_samples);
211209
self.stimulus(:,:,1) = im(:,:,1);
212210
l = regexp(files(1).name,'\d')-1;
@@ -225,7 +223,7 @@ function import_stimulus(self)
225223
range = max(self.stimulus(:))-mn;
226224

227225
self.stimulus = (reshape(self.stimulus,...
228-
self.w_stimulus*self.h_stimulus,...
226+
self.r_stimulus^2,...
229227
self.n_samples)-mn)/range;
230228
close(wb)
231229
fprintf('done\n');
@@ -239,52 +237,58 @@ function create_timecourses(self,varargin)
239237
%
240238
% optional inputs are
241239
% - max_radius : radius of the field of fiew (default = 10.0)
242-
% - number_XY : steps in x and y direction (default = 30.0)
240+
% - num_xy : steps in x and y direction (default = 30.0)
243241
% - min_slope : lower bound of RF size slope (default = 0.1)
244242
% - max_slope : upper bound of RF size slope (default = 1.2)
245-
% - number_slope: steps from lower to upper bound (default = 10.0)
243+
% - num_slope: steps from lower to upper bound (default = 10.0)
246244

247245
text = 'creating timecourses...';
248246
fprintf('%s\n',text)
249247
wb = waitbar(0,text,'Name',self.is);
250248

251249
p = inputParser;
252-
addOptional(p,'number_XY',30);
250+
addOptional(p,'num_xy',30);
253251
addOptional(p,'max_radius',10);
254-
addOptional(p,'number_slope',10);
252+
addOptional(p,'num_slope',10);
255253
addOptional(p,'min_slope',0.1);
256254
addOptional(p,'max_slope',1.2);
255+
addoptional(p,'css_exponent',1);
256+
addoptional(p,'sampling','log');
257257
p.parse(varargin{:});
258258

259-
n_xy = p.Results.number_XY;
259+
num_xy = p.Results.num_xy;
260260
max_r = p.Results.max_radius;
261-
n_slope = p.Results.number_slope;
261+
num_slope = p.Results.num_slope;
262262
min_slope = p.Results.min_slope;
263263
max_slope = p.Results.max_slope;
264-
self.n_points = n_xy^2 * n_slope;
264+
css_exponent = p.Results.css_exponent;
265+
sampling = p.Results.sampling;
266+
self.n_points = num_xy^2 * num_slope;
265267

266-
X_ = ones(self.h_stimulus,1) * linspace(-max_r,...
267-
max_r,self.w_stimulus);
268+
X_ = ones(self.r_stimulus,1) * linspace(-max_r,...
269+
max_r,self.r_stimulus);
268270
Y_ = -linspace(-max_r,max_r,...
269-
self.h_stimulus)' * ones(1,self.w_stimulus);
271+
self.r_stimulus)' * ones(1,self.r_stimulus);
270272

271-
X_ = reshape(X_,self.w_stimulus*self.h_stimulus,1);
272-
Y_ = reshape(Y_,self.w_stimulus*self.h_stimulus,1);
273+
X_ = reshape(X_,self.r_stimulus^2,1);
274+
Y_ = reshape(Y_,self.r_stimulus^2,1);
273275

274276
i = (0:self.n_points-1)';
275-
self.idx = [floor(i/(n_xy*n_slope))+1,...
276-
mod(floor(i/(n_slope)),n_xy)+1,...
277-
mod(i,n_slope)+1];
277+
self.idx = [floor(i/(num_xy*num_slope))+1,...
278+
mod(floor(i/(num_slope)),num_xy)+1,...
279+
mod(i,num_slope)+1];
280+
281+
if strcmp(sampling,'log')
282+
self.ecc = exp(linspace(log(.1),log(max_radius),num_xy));
283+
elseif strcmp(sampling,'linear')
284+
self.ecc = linspace(.1,max_radius,num_xy);
285+
end
278286

279-
n_lower = ceil(n_xy/2);
280-
n_upper = floor(n_xy/2);
281-
self.ecc = exp([linspace(log(max_r),log(.1),n_lower),...
282-
linspace(log(.1),log(max_r),n_upper)]);
283-
self.pa = linspace(0,(n_xy-1)/n_xy*2*pi,n_xy);
284-
self.slope = linspace(min_slope,max_slope,n_slope);
287+
self.pa = linspace(0,(num_xy-1)/num_xy*2*pi,num_xy);
288+
self.slope = linspace(min_slope,max_slope,num_slope);
285289

286290
W = single(zeros(self.n_points,...
287-
self.w_stimulus*self.h_stimulus));
291+
self.r_stimulus^2));
288292
for j=1:self.n_points
289293
x = cos(self.pa(self.idx(j,1))) * self.ecc(self.idx(j,2));
290294
y = sin(self.pa(self.idx(j,1))) * self.ecc(self.idx(j,2));
@@ -293,7 +297,7 @@ function create_timecourses(self,varargin)
293297
waitbar(j/self.n_points*.9,wb);
294298
end
295299

296-
tc = W * self.stimulus;
300+
tc = (W * self.stimulus).^css_exponent;
297301
waitbar(1,wb);
298302
self.tc_fft = fft(tc');
299303
close(wb)

0 commit comments

Comments
 (0)