-
Notifications
You must be signed in to change notification settings - Fork 1
/
createGratingStimulus.m
41 lines (30 loc) · 1.42 KB
/
createGratingStimulus.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
function output = createGratingStimulus(stimParams, cyclesPerDegree, gratingOrientation, peak2peakContrast)
% CREATE GRATING STIMULUS
% stimParams - defined using stimInitialize.m; should contain a the
% convolutional bandpass filter to use, in space domain
% (stimParams.bpfilter)
% stripesPerImage - Define approximate number of repetitions of lines
% across image (previous variable name: relCutOff)
% orientation - Orientation of grating in [0,2*pi]
% peak2peakContrast - Michelson contrast of grating in percent [0 100];
% Note: uses a randomly determined phase
stimWidth = stimParams.stimulus.srcRect(3)-stimParams.stimulus.srcRect(1);
stimHeight = stimParams.stimulus.srcRect(4)-stimParams.stimulus.srcRect(2);
imSizeInDeg = stimParams.experimentSpecs.radii * 2;
cpi = cyclesPerDegree * imSizeInDeg;
% Create a grating: superimpose number of orientations in
% gratingOrientation
[x,y] = meshgrid(linspace(0,1,stimWidth), linspace(0,1,stimHeight));
for ii = 1:length(gratingOrientation)
th = gratingOrientation(ii);
xr = x*cos(th) - y*sin(th);
phX = rand*2*pi; % phase
if ii == 1
output = cos(2*pi*xr*cpi+phX) * peak2peakContrast/2/100; rms_single = rms(output(:));
else
output = output + cos(2*pi*xr*cpi+phX) * peak2peakContrast/2/100;
end
end
% equalize rms contrast to that of a single grating
output = output / rms(output(:)) * rms_single;
return