Question about update_stimulus_display

Hi there,

I try to present rhythmic stimuli in a part of my experiment like"…1212121…" (start and end can both either be 1 or 2), so i write a transitional sentence that will go to the previous task_system_state to make a loop (for the related code see line 80-88 and 150-197).

The experiment generally works fine; however, approximately 1 in 5 trials there will be a display problem like “… 1(1 second) 2 (1 second) 1 (a blink, maybe 1 frame) 2(1 second) …” (given the period is 2 second). I check the code myself first. I find when this problem happens, after “update_stimulus_display” either "stimulus_ending_1” or “stimulus_ending_2” will change (e.g. 0 , 0 → 0, true; they should always be 0; in line 180 and 184), but I do not know why this happens.

Besides, I am a beginner in MWorks. I used to program on psychtoolbox and I was taught to always write a time slack: if the refresh rate of a monitor is 50Hz (20ms per frame), and the stimulus duration I want to present is 600ms, I should let the computer update the stimulus at 590ms. Otherwise, if I make it 600ms, due to the delay of the command or whatever, stimulus may present 31 (30+1) frames. I do not know if this works for the MWorks Timer.

Thanks,
Xiang

Attachment: pingpong.xml (25.1 KB)

I forget to mention my MWorks version is 0.7 and my OS X version is 10.10.5 .

Hi Xiang,

I think I see what’s going on.

Because you reset stimulus_ending_1 and stimulus_ending_2 after dequeueing the stimuli but before invoking update_stimulus_display, the “old” stimulus is sometimes setting the “ending” variable a second time. (This happens due to some details of the implementation – not a bug, exactly, but certainly unhelpful in this case.)

The fix is to alter the transitions out of the stimulus_execution_3 state to require that the current stimulus is ending and ignore the previous stimulus. For example, on line 195, you should change the transition condition from

(stimulus_ending_1 OR stimulus_ending_2) AND half_period_number_remain

to

((stimulus_current == 2 AND stimulus_ending_1) OR (stimulus_current == 1 AND stimulus_ending_2)) AND half_period_number_remain

I was taught to always write a time slack: if the refresh rate of a monitor is 50Hz (20ms per frame), and the stimulus duration I want to present is 600ms, I should let the computer update the stimulus at 590ms.

That’s exactly how the ending parameter works: It becomes true during the frame immediately preceding the final frame. This lets your protocol use the time spent rendering the last frame to prepare the next stimulus, which will then be displayed during the frame immediately after the last frame.

Cheers,
Chris Stawarz

Hi Chris,

I have revised the program and it works out!

Thanks,
Xiang