Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
296 views
in Technique[技术] by (71.8m points)

psychtoolbox - Problem in showing sequence of static images for the desired amount of frames MATLAB

i have to show my participants a series of visual stimuli each lasting a certain amount of frames. each stimulus is coded as a number (reported in stimuli_matrix) and the amount of frames it should last is reported in stimframesVector. Rows of stimuli_matrix represents trials.

My problem is that the stimulus is not shown for the specified amount of frames. As an alternative i tried to create a matrix containing: the number of frames a trial should last and the sequence of stimuli to present, i only obtained a flickering, inaccurate and wrong (timewise) stimulus presentation. Could you please help me in improving the code so that it shows the stimuli for the specified amount of frames without flickering?

here is the code

vbl = Screen('Flip', window);

ifi = Screen('GetFlipInterval', window);

Screen('Flip',window);


for righe=1:size(stimuli_matrix,1)

    for prov=1:size(stimuli_matrix,2)
        waitframes=1;
        stimduration = .5;
        begduration = 1;
        rndnumb=rand;
        jitter= (rndnumb-0.5)*0.1;
        Jittered_stim = stimduration + jitter;
        Jittered_beg = begduration + jitter;
        
        % How long should the image stay up in frames
        
        Stim_Frames = round(Jittered_stim / ifi);
        
        % Duration in frames of trial start
        
        Beg_Frames = round(Jittered_beg / ifi);
        
        stimframesVector=ones(1,Stim_Frames);
        indice=stimuli_matrix(righe,prov)
        
        %stimframesVector1=stimframesVector(1)*1
        [keyIsDown,secs, keyCode] = KbCheck;
        if keyCode(escapeKey)
            sca;
        end
         tic;
        for frames=1:length(stimframesVector)
            if indice==0
                Screen('DrawLines', window, allCoords,lineWidthPix, white, [xCenter yCenter], 2);
                Screen('Flip', window, [], 1);
            elseif indice == 1
                Screen('DrawTextures', window, D1, [], allRects,0);
                Screen('Flip', window, [], 1);
            elseif indice == 2
                Screen('DrawTextures', window, C1, [], allRects,0);
                Screen('Flip', window, [], 1);
            elseif indice == 3
                Screen('DrawTextures', window, B1, [], allRects,0);
                Screen('Flip', window, [], 1);
            elseif indice == 4
                Screen('DrawTextures', window, A1, [], allRects,0);
                Screen('Flip', window, [], 1);
            elseif indice == 5
                Screen('DrawTextures', window, H1, [], allRects,0);
                Screen('Flip', window, [], 1);
            elseif indice == 6
                Screen('DrawTextures', window, G1, [], allRects,0);
                Screen('Flip', window, [], 1);
            elseif indice == 7
                Screen('DrawTextures', window, F1, [], allRects,0);
                Screen('Flip', window, [], 1);
            elseif  indice == 8
                Screen('DrawTextures', window, E1, [], allRects,0);
                Screen('Flip', window, [], 1);
            end
        end
     Screen('Flip', window, vbl+(waitframes-0.5)*ifi);
     stimvec2=stimframesVector %checking time
      toc; 
    end
end
question from:https://stackoverflow.com/questions/66058401/problem-in-showing-sequence-of-static-images-for-the-desired-amount-of-frames-ma

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I believe the issue is that you are not specifying when you want each stimulus in the sequence of stimuli to be flipped with the Screen Flip command. Below is a simplified example, which generates a sequence of Ovals with random colors and random timing intervals in terms of frames. The key is that each Screen Flip command includes the third parameter, which indicates the Psychtoolbox time that the stimulus should be presented.

try
    screenNum= max(Screen('Screens'));
    [wPtr, wRect]=PsychImaging('OpenWindow', screenNum, 0);
    ifi = Screen('GetFlipInterval', wPtr);
    
    number_stim = 10;
    stimuli_colors = round(rand(number_stim, 3) * 255);
    frame_deltas = 15 + round(rand(number_stim, 1) * 15);
   
    % initial flip
    [~, lastOnset] = Screen('Flip', wPtr);
    for f = 1:number_stim
        Screen('FillOval', wPtr, stimuli_colors(f, :), CenterRect([0 0, 400, 400], wRect));
        [~, lastOnset] = Screen('Flip', wPtr, lastOnset + ((frame_deltas(f) - 0.5) * ifi));
    end
   
    sca;
    
catch e
    sca;
    rethrow(e)
end

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...