-
Notifications
You must be signed in to change notification settings - Fork 0
/
rd_grating.m
45 lines (35 loc) · 1.04 KB
/
rd_grating.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
39
40
41
42
43
44
function grating = rd_grating(pixelsPerDegree, sizeDegrees, ...
spatialFrequency, tiltDegrees, phase, contrast)
% function grating = rd_grating(pixelsPerDegree, sizeDegrees, ...
% spatialFrequency, tiltDegrees, phase, contrast)
%
% Inputs:
% pixelsPerDegree [=99]: pixels per degree of visual angle
% sizeDegrees [=2]: side length in degrees of visual angle
% spatialFrequency [=3]
% tiltDegrees [=0]
% phase [=0]
% contrast [=1]: contrast of the grating, 0-1
%
% Outputs:
% grating image scaled 0-1
%% inputs
if nargin==0
pixelsPerDegree = 100;
sizeDegrees = 2;
spatialFrequency = 1;
tiltDegrees = 0;
phase = 0;
contrast = 1;
end
%% Make meshgrid
sizePixels = round(sizeDegrees * pixelsPerDegree);
grid = linspace(-sizeDegrees/2, sizeDegrees/2, sizePixels);
[x, y] = meshgrid(grid, grid);
%% Make grating
a = cos(tiltDegrees * pi/180) * spatialFrequency * 2*pi;
b = sin(tiltDegrees * pi/180) * spatialFrequency * 2*pi;
sinwav = sin(a*x+b*y+phase);
grating = .5 + .5*(contrast * sinwav);
%% Show grating
% imshow(grating)