-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrift_grating.m
64 lines (51 loc) · 1.9 KB
/
Drift_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function DriftDemo
% DriftDemo
% Original code was developed by PTB-3 http://psychtoolbox.org/
% I have developed the original code to drift the grating with the
% movement of the mouse throughout the entire monitor.
% The drift of the grating helps to monitor the ratinal response of
% experiment animal.
try
AssertOpenGL;
screens=Screen('Screens');
screenNumber=max(screens);
white=WhiteIndex(screenNumber);
black=BlackIndex(screenNumber);
gray=round((white+black)/2);
if gray == white
gray=white / 2;
end
inc=white-gray;
% Open a double buffered fullscreen window and select a gray background
w = Screen('OpenWindow',screenNumber, gray);
[width, height] = Screen('WindowSize', screenNumber);
% Compute each frame of the movie and convert the those frames, stored in
% MATLAB matices, into Psychtoolbox OpenGL textures using 'MakeTexture';
numFrames=5;
[keyIsDown, secs, keyCode] = KbCheck;
while ~keyCode(38) % UP KEY
[keyIsDown, secs, keyCode] = KbCheck;
[a, b, buttons] = GetMouse;
centreX = width/2 - a;
centreY = height/2 - b;
for i=1:numFrames
phase=(i/numFrames)*2*pi;
dim = 500; % related to dimension of the monitor
[x,y]= meshgrid(-dim + centreX:dim+centreX,-dim + centreY:dim + centreY);
angle=30*pi/180; % 30 deg orientation.
f=0.05*2*pi; % cycles/pixel
a=cos(angle)*f;
b=sin(angle)*f;
m=exp(-((x/90).^2)-((y/90).^2)).*sin(a*x+b*y+phase);
tex(i)=Screen('MakeTexture', w, round(gray+inc*m));
Screen('DrawTexture', w, tex(i));
Screen('Flip', w);
end
end
Screen('Close');
sca;
catch
sca;
Priority(0);
psychrethrow(psychlasterror);
end