Psychtoolbox checkerboard alternation error
    7 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
Hi,
I'm new to Psychtoolbox and am using it to create a reversing checkerboard pattern on the screen. The checkerboard has been coloured such that it is more like vertical stripes rather than checks. I have two contrasting conditions a regular black/white striped pattern and then a light grey/dark grey striped pattern. At first, I was struggling with the timing aspect of things and was not able to get the screen to switch from the grey screen to black and white screen. The waitframes fixed this. However, now that I have each screen appearing for a set duration, the alternation of the pattern has stopped for each texture. Does anybody have advice on how to fix this? What is missing in my code currently that's stopping the reversing of the stripes??
Can anyone provide advice? My code is below - some very small bits of it my redundant/irrelevant, I'll clean it up later.
        % Clear the workspace and the screen
       sca;
       close all;
       clearvars;
       %Screen('Preference', 'SkipSyncTests', 1);
       % Here we call some default settings for setting up Psychtoolbox
       PsychDefaultSetup(2);
       % Get the screen numbers
       screens = Screen('Screens');
       % Draw to the external screen if avaliable
       screenNumber = max(screens);
       % Define black and white
       white = WhiteIndex(screenNumber);
       black = BlackIndex(screenNumber);
       grey = white / 2;
       % Open an on screen window
       [window, windowRect] = PsychImaging('OpenWindow', screenNumber, grey, [0 0 400 400]);
       ifi = Screen('GetFlipInterval', window);
       % Query the maximum priority level
       topPriorityLevel = MaxPriority(window);
       % Get the size of the on screen window
       [screenXpixels, screenYpixels] = Screen('WindowSize', window);
       %%%%%%%%%Stripe information
       % Get the centre coordinate of the window
       [xCenter, yCenter] = RectCenter(windowRect);
       cx = (screenXpixels/2);
       cy = (screenYpixels/2);
       % Make a base Rect of 200 by 200 pixels
       dimx = cx;
       dimy = cy;
       baseRect = [0 0 dimx dimy];
       pos = [cx- dimx/2 ,cy - dimy/2,cx+ dimx/2 ,cy + dimy/2];
       % Make the coordinates for our grid of squares
       [xPos, yPos] = meshgrid(-2:0.5:2, -2:0.5:2);
       % Calculate the number of squares and reshape the matrices of coordinates
       % into a vector
       [s1, s2] = size(xPos);
       numSquares = s1 * s2;
       xPos = reshape(xPos, 1, numSquares);
       yPos = reshape(yPos, 1, numSquares);
       % Scale the grid spacing to the size of our squares and centre
       xPosLeft = xPos .* dimx + screenXpixels * 0.25;
       yPosLeft = yPos .* dimy + yCenter;
       xPosRight = xPos .* dimx + screenXpixels * 0.75;
       yPosRight = yPos .* dimy + yCenter;
       % Set the colours of each of our squares
       % light grey and dark grey colours 
       bwColors = repmat([0.55 0.46; 0.55 0.46], 5, 5);
       bwColors = bwColors(1:end-1, 1:end-1);
       bwColors = reshape(bwColors, 1, numSquares);
       bwColors = repmat(bwColors, 3, 1);
       multiColors = repmat([0.45 0.58; 0.45 0.58], 5, 5);
       multiColors = multiColors(1:end-1, 1:end-1);
       multiColors = reshape( multiColors, 1, numSquares);
       multiColors = repmat( multiColors, 3, 1);
       %black and white colours 
       board3 = repmat([1 0; 1 0], 5, 5);
       board3 = board3(1:end-1, 1:end-1);
       board3 = reshape(board3, 1, numSquares);
       board3 = repmat(board3, 3, 1);
       board4 = repmat([0 1; 0 1], 5, 5);
       board4 = board4(1:end-1, 1:end-1);
       board4 = reshape( board4, 1, numSquares);
       board4 = repmat( board4, 3, 1);
       % Make our rectangle coordinates
       allRectsLeft = nan(4, 3);
       allRectsRight = nan(4, 3);
      for i = 1:numSquares
            allRectsLeft(:, i) = CenterRectOnPointd(baseRect,...
        xPosLeft(i), yPosLeft(i));
            allRectsRight(:, i) = CenterRectOnPointd(baseRect,...
        xPosRight(i), yPosRight(i));
      end
       % Texture cue that determines which texture we will show
       textureCue = [1 2];
       % Sync us to the vertical retrace
       vbl = Screen('Flip', window);
        %----------------------------------------------------------------------
        %                       Timing Information
        %----------------------------------------------------------------------
        % Interstimulus interval time in seconds and frames
        isiTimeSecs = 10;
        isiTimeFrames = round(isiTimeSecs / ifi);
      % Numer of frames to wait before re-drawing
       flipSecs = 12;
      waitframes = round(flipSecs / ifi);
      % How long should the image stay up during flicker in time and frames
      imageSecs = 0.5;
      imageFrames = round(imageSecs / ifi);
      % Duration (in seconds) of the blanks between the images during flicker
      blankSecs = 0.25;
      blankFrames = round(blankSecs / ifi);
      %----------------------------------------------------------------------
      %                       Keyboard information
      %----------------------------------------------------------------------
      % Keybpard setup
      spaceKey = KbName('space');
      tabKey = KbName('tab');
      escapeKey = KbName('ESCAPE');
      RestrictKeysForKbCheck([spaceKey escapeKey tabKey]);
      % Time we want to wait before reversing the contrast of the checkerboard
      checkFlipTimeSecs = 0.5;
      checkFlipTimeFrames = round(checkFlipTimeSecs / ifi);
      frameCounter = 0;
      %----------------------------------------------------------------------
      %                      Experimental Loop
      %----------------------------------------------------------------------
      % Start screen
      DrawFormattedText(window, 'Press Space To Begin', 'center', 'center', black);
      Screen('Flip', window);
      KbWait;
      numTrials = 10;
      StartTime = GetSecs;
      for trial=1:numTrials
        textureCue = [1 2];
        tex(1)= Screen('MakeTexture',window,multiColors);
        tex(2)= Screen('MakeTexture',window,bwColors);
        tex2(1)=Screen('MakeTexture',window,board3);
        tex2(2)=Screen('MakeTexture',window,board4);
    % Draw a fixation cross for the start of the trial
    Screen('FillRect', window, grey);
    Screen('Flip', window);
    % WaitSecs(1);
    % This is our drawing loop
    respMade = 0;
    numFrames = 0;
    frame = 0;
    Priority(topPriorityLevel);
        % Increment the number of frames
        numFrames = numFrames + 1;
        frame = frame + 1;
        if frame > numPresLoopFrames
            frame = 1;
        end
        % Decide what we are showing on this frame
        showWhat = presVector(frame);
         startTime = GetSecs();
         limit = 12;
         counter=0;
        while ~KbCheck
               % Draw the textures or a blank frame
               frameCounter = frameCounter + 1;
               if frameCounter == checkFlipTimeFrames
                     textureCue = fliplr(textureCue);
                     frameCounter = 0;
               end
         Screen('DrawTexture', window, tex(textureCue(1)), [],pos);
       % Flip to the screen
            vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
         Screen('DrawTexture', window, tex2(textureCue(1)), [],pos);
       % Flip to the screen
            vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
       % Poll the keyboard for the space key
        [keyIsDown, secs, keyCode] = KbCheck(-1);
        if keyCode(KbName('space')) == 1
            respMade = 1;
        elseif keyCode(KbName('ESCAPE')) == 1
            sca;
            disp('*** Experiment terminated ***');
            return
        end
     end
     end
      % Bin the textures we used
           Screen('Close', tex);
           Screen('Close', tex2);
      % Clear up and leave the building
      sca;
4 commentaires
Réponses (0)
Voir également
Catégories
				En savoir plus sur Timing and presenting 2D and 3D stimuli dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

