"taz_liraz",
I think there were some conceptual/programming errors in your code. The code below
seems to produce smoothly rotating (and phase shifting) gratings.
Gr.
Frans
function better_rotating_grating
if nargin<2
ifis=2;
end;
if nargin<1
numFrames=16;
end;
try
commandwindow;
Screen('Preference','SkipSyncTests', 1);
AssertOpenGL;
screens=Screen('Screens');
screenNumber=max(screens);
w=Screen('OpenWindow',screenNumber);
[widthp, heightp]=Screen('WindowSize', w);
[width, height]=Screen('DisplaySize', screenNumber);
pixelratio=widthp/width;
spatial=2;
white=WhiteIndex(screenNumber);
black=BlackIndex(screenNumber);
gray=(white+black)/2;
if round(gray)==white
gray=black;
end
inc=white-gray;
s=min(widthp, heightp) /1;
[x,y]=meshgrid(-s:s-1, -s:s-1);
angle=0*pi/180; % 30 deg orientation.
f=0.2/34*2*pi; % cycles/pixel
a=cos(angle)*f;
b=sin(angle)*f;
for i=1:numFrames
phase=(i/numFrames)*2*pi
m=sin(a*x+b*y+phase);
gratingtex=(gray+inc*m);
tex(i)=Screen('MakeTexture', w, gratingtex);
end
i
tavg=0;
ifi_duration = Screen('GetFlipInterval', w)
movieDurationSecs=2.5;
frameRate=Screen('FrameRate',screenNumber);
if(frameRate==0)
frameRate=60; % 60 Hz is a good guess for flat-panels...
end
movieDurationFrames=round(movieDurationSecs * frameRate / ifis)
movieFrameIndices=mod(0:(movieDurationFrames-1), numFrames) + 1
priorityLevel=MaxPriority(w);
Priority(priorityLevel)
Screen('FillRect',w, gray);
vbl = Screen('Flip', w);
tic
rotSp=60; %( deg/s)
movieFrameAngle=(0:(length(movieFrameIndices)-1))*(rotSp/frameRate);
lengthMovieFrameAngle=length(movieFrameAngle)
lengthMovieFrameIndices=length(movieFrameIndices)
if length(movieFrameAngle)~=length(movieFrameIndices)
error('Error: Different length of movie index and angle vectors');
end
i=0; j=0;
Screen('Flip', w);
t1=Getsecs;
tx=GetSecs;
if 0 % do not use movieFrameAngle vector, but calculate angle based on time passed
while 1
i=i+1;
if i>length(tex)
i=1;
end
tx=GetSecs;
angle=rotSp*(GetSecs-t1);
Screen('DrawTexture', w, tex(movieFrameIndices(i)), [], [], angle);
vbl=Screen('Flip', w);
tavg=tavg+(GetSecs - tx);
j=j+1;
tx=GetSecs;
% We also abort on keypress...
if KbCheck
break;
end;
end
else
while 1
for i=1:length(movieFrameIndices)
Screen('DrawTexture', w, tex(movieFrameIndices(i)), [], [], movieFrameAngle(i));
vbl=Screen('Flip', w);
tavg=tavg+(GetSecs - tx);
j=j+1;
tx=GetSecs;
% We also abort on keypress...
if KbCheck
break;
end;
end
if KbCheck
break;
end;
end
end
toc
Priority(0);
tavg=tavg / j % average frameduration
% We're done: Close all windows and textures:
Screen('CloseAll');
catch
%this "catch" section executes in case of an error in the "try" section
%above. Importantly, it closes the onscreen window if its open.
Priority(0);
Screen('CloseAll');
psychrethrow(psychlasterror);
end %try..catch..
--- In psychtoolbox@yahoogroups.com, "taz_liraz" <taz_liraz@...> wrote:
>
> if nargin<2
> ifis=2;
> end;
>
> if nargin<1
> numFrames=1
> end;
>
> try
> AssertOpenGL;
> screens=Screen('Screens');
> screenNumber=max(screens);
> w=Screen('OpenWindow',screenNumber);
> [widthp, heightp]=Screen('WindowSize', w);
> [width, height]=Screen('DisplaySize', screenNumber);
> pixelratio=widthp/width;
> spatial=2;
> white=WhiteIndex(screenNumber);
> black=BlackIndex(screenNumber);
> gray=(white+black)/2;
> if round(gray)==white
> gray=black;
> end
> inc=white-gray;
> s=min(widthp, heightp) /1;
> [x,y]=meshgrid(-s:s-1, -s:s-1);
> angle=0*pi/180; % 30 deg orientation.
> f=0.2/34*2*pi; % cycles/pixel
> a=cos(angle)*f;
> b=sin(angle)*f;
> for i=1:numFrames
> phase=(i/numFrames)*2*pi;
> m=sin(a*x+b*y+phase);
> gratingtex=(gray+inc*m);
> tex(i)=Screen('MakeTexture', w, gratingtex);
> end
>
> tavg=0;
> ifi_duration = Screen('GetFlipInterval', w)
> movieDurationSecs=0.5;
> frameRate=Screen('FrameRate',screenNumber);
> if(frameRate==0)
> frameRate=60; % 60 Hz is a good guess for flat-panels...
> end
> movieDurationFrames=round(movieDurationSecs * frameRate / ifis);
> movieFrameIndices=mod(0:(movieDurationFrames-1), numFrames) + 1;
> priorityLevel=MaxPriority(w);
> Priority(priorityLevel)
> Screen('FillRect',w, gray);
> vbl = Screen('Flip', w);
> tic
> for j=0:1:30
> for i=1:movieDurationFrames
> t1=GetSecs;
> Screen('DrawTexture', w, tex(movieFrameIndices(i)), [], [], j);
> vbl=Screen('Flip', w, vbl + (ifis - 0.5) * ifi_duration);
>
> t1=GetSecs - t1;
> if (i>numFrames)
> tavg=tavg+t1;
> end;
>
> % We also abort on keypress...
> if KbCheck
> break;
> end;
> end;
> end
> toc
> Priority(0);
>
> tavg=tavg / (movieDurationFrames - numFrames)
>
> % We're done: Close all windows and textures:
> Screen('CloseAll');
>
> catch
> %this "catch" section executes in case of an error in the "try"
> section
> %above. Importantly, it closes the onscreen window if its open.
> Priority(0);
> Screen('CloseAll');
> psychrethrow(psychlasterror);
> end %try..catch..
>
>
>
>
> --- In psychtoolbox@yahoogroups.com, "Mario Kleiner"
> <mario.kleiner@> wrote:
> >
> > I still don't get it, this should simply work by providing a proper
> > rotation angle to the Screen('DrawTexture'...) command - the angle
> is
> > in degress ie 0-360 degrees. Did you try DriftDemo2 for a more
> > efficient way of doing drifting gratings?
> >
> > You could describe your hardware specs and display settings, post
> the
> > snippet of code that you use and/or provide a much more detailed
> > explanation of what you mean with "jumps".
> >
> > Your jumps could be jumps in the graphics, due to overloading the
> > machine by bad coding or due to a coding bug. It also could be
> > temporal aliasing if you happen to hit a unlucky combination of
> > spatial wavelength of your grating, drifting speed of the grating
> and
> > monitor refresh / redraw rate, but this shouldn't be related to
> > rotation...
> >
> > -mario
> >
> > --- In psychtoolbox@yahoogroups.com, Li-Raz R <taz_liraz@> wrote:
> > >
> > > hi
> > > i am trying to create a stimulus that has 2 degrees of fridom.
> drift
> > and angular rotation. when i tried to do the grating when it changed
> > orientation (1 degree) it allways jumped. i trying to do a continues
> > grating stimulus that drift and rotate. but i only succed partly
> cause
> > it has "jumps" in the rotation. i think the reason is the phase of
> the
> > grating
> > > thanks
> > >
> > >
> > > ----- Original Message ----
> > > From: Mario Kleiner <mario.kleiner@>
> > > To: psychtoolbox@yahoogroups.com
> > > Sent: Wednesday, December 20, 2006 9:16:55 PM
> > > Subject: [psychtoolbox] Re: rotating grating
> > >
> > > hmm,
> > >
> > > could you explain in more detail or in a different way what you
> want
> > > to do and what goes wrong? I don't understand the problem from
> your
> > > posting...
> > >
> > > -mario
> > >
> > > --- In psychtoolbox@ yahoogroups. com, "taz_liraz" <taz_liraz@ ..>
> > wrote:
> > > >
> > > > hi
> > > > i am new with this toolbox. i am trying to do drifting and
> rotating
> > > > grating. i modified the driftdemo (reomved the mask) and
> iserted a
> > loop
> > > > that changing the angle in the drawtexture line but the result
> is
> > > > drifting rotating and jumping every time it changes orientation
> it
> > > > jumps back. does anyone has an idea how to fix it?
> > > > thanks
> > > >
> > >
> > >
> > >
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Tired of spam? Yahoo! Mail has the best spam protection around
> > > http://mail.yahoo.com
> > >
> >
>