Need suggestions

Dear Friend:

I want to display stimulus for 1 second, and 2 seconds blank screen, so the
total inter-stimuli interval is 3 seconds. In the following codes, I try to
use the out while loop for inter-stimuli interval, and the inner loop for
display time. The problem is the stimulus "red" was displayed for 3 seconds
instead of 1.

Any comments are appreciated. Once again, it will be great if any one can
send me some programs for me to study. I have studied all the demo programs.

Jiansong Xu


w=Screen('OpenWindow', screenNumber,0,[],32,2);
Screen('FillRect', w, white);
Screen('TextFont',w, 'Courier');
Screen('TextSize',w, 50);
Screen('TextStyle', w, 0);

isi_start = GetSecs;
isi_duration = 0; % inter-stimuli interval

display_end = 0; % display time

while isi_duration < 3000

display_start = GetSecs;


while display_end < 1000
Screen('DrawText', w, 'red', 530, 530, [255,0,0]);
Screen('Flip',w);

display_end = (GetSecs - display_start)*1000;
end
Screen('DrawText', w, ' ', 530, 530, [255,0,0]);

isi_duration = (GetSecs - isi_start)*1000;
display_end = (GetSecs - display_start)*1000;

end
Am 10.11.2004 um 16:16 schrieb Jiansong Xu:
> Dear Friend:
>
> I want to display stimulus for 1 second, and 2 seconds blank screen,
> so the
> total inter-stimuli interval is 3 seconds. In the following codes, I
> try to
> use the out while loop for inter-stimuli interval, and the inner loop
> for
> display time. The problem is the stimulus "red" was displayed for 3
> seconds
> instead of 1.

> while isi_duration < 3000
> while display_end < 1000
> Screen('DrawText', w, 'red', 530, 530, [255,0,0]);
> Screen('Flip',w);
> display_end = (GetSecs - display_start)*1000;
> end
> Screen('DrawText', w, ' ', 530, 530, [255,0,0])
> isi_duration = (GetSecs - isi_start)*1000;
> display_end = (GetSecs - display_start)*1000;
> end

> Any comments are appreciated. Once again, it will be great if any one
> can
> send me some programs for me to study. I have studied all the demo
> programs.
>
> Jiansong Xu

Hi,

I think the stimulus "red" was shown for three seconds because you did
not include a "screen('flip") statement after the second call to
DrawText.
You can also save many function calls. First, because you are using
static stimuli, there is no need to redraw the screen on every pass
through the loop. Instead, just use drawing calls when things are
supposed to change, as shown in the example below. Second, getsecs
needs to be called only once within the loop.

hth, jochen

try
white=[255 255 255];
w=Screen('OpenWindow', screenNumber,0,[],32,2);
Screen('FillRect', w, white);
Screen('TextFont',w, 'Courier');
Screen('TextSize',w, 50);
Screen('TextStyle', w, 0);

MS2S = 1/1000; % milliseconds to seconds factor
ISI_DURATION = 3000*MS2S; % inter-stimuli interval
STIM_DURATION = 1000*MS2S; % display time

stimTimeExceeded=0; % flag: is stimulus time exceeded? (logical)
t = 0;
Screen('DrawText', w, 'red', 530, 530, [255,0,0]);
Screen('Flip',w);
t0 = GetSecs;
while t < ISI_DURATION
if ~stimTimeExceeded
if t >= STIM_DURATION
Screen('DrawText', w, ' ', 530, 530, [255,0,0]);
Screen('Flip',w);
stimTimeExceeded=1;
end
end
t = GetSecs-t0;
end
screen('CloseAll');
catch
Screen('CloseAll');
ShowCursor;
end
Hi, Jochen:

Thanks a lot. One more question (a lot more in the near future till no one
want to response). Where should I put KbCheck to measure the reaction time?

Best Wishes

Jiansong

> From: Jochen Laubrock <laubrock@...-potsdam.de>
> Date: Thu, 11 Nov 2004 11:13:04 +0100
> To: psychtoolbox@yahoogroups.com
> Cc: Jiansong Xu <jiansong@...>
> Subject: Re: [psychtoolbox] Need suggestions (OS X)
>
> Am 10.11.2004 um 16:16 schrieb Jiansong Xu:
>> Dear Friend:
>>
>> I want to display stimulus for 1 second, and 2 seconds blank screen,
>> so the
>> total inter-stimuli interval is 3 seconds. In the following codes, I
>> try to
>> use the out while loop for inter-stimuli interval, and the inner loop
>> for
>> display time. The problem is the stimulus "red" was displayed for 3
>> seconds
>> instead of 1.
>
>> while isi_duration < 3000
>> while display_end < 1000
>> Screen('DrawText', w, 'red', 530, 530, [255,0,0]);
>> Screen('Flip',w);
>> display_end = (GetSecs - display_start)*1000;
>> end
>> Screen('DrawText', w, ' ', 530, 530, [255,0,0])
>> isi_duration = (GetSecs - isi_start)*1000;
>> display_end = (GetSecs - display_start)*1000;
>> end
>
>> Any comments are appreciated. Once again, it will be great if any one
>> can
>> send me some programs for me to study. I have studied all the demo
>> programs.
>>
>> Jiansong Xu
>
> Hi,
>
> I think the stimulus "red" was shown for three seconds because you did
> not include a "screen('flip") statement after the second call to
> DrawText.
> You can also save many function calls. First, because you are using
> static stimuli, there is no need to redraw the screen on every pass
> through the loop. Instead, just use drawing calls when things are
> supposed to change, as shown in the example below. Second, getsecs
> needs to be called only once within the loop.
>
> hth, jochen
>
> try
> white=[255 255 255];
> w=Screen('OpenWindow', screenNumber,0,[],32,2);
> Screen('FillRect', w, white);
> Screen('TextFont',w, 'Courier');
> Screen('TextSize',w, 50);
> Screen('TextStyle', w, 0);
>
> MS2S = 1/1000; % milliseconds to seconds factor
> ISI_DURATION = 3000*MS2S; % inter-stimuli interval
> STIM_DURATION = 1000*MS2S; % display time
>
> stimTimeExceeded=0; % flag: is stimulus time exceeded? (logical)
> t = 0;
> Screen('DrawText', w, 'red', 530, 530, [255,0,0]);
> Screen('Flip',w);
> t0 = GetSecs;
> while t < ISI_DURATION
> if ~stimTimeExceeded
> if t >= STIM_DURATION
> Screen('DrawText', w, ' ', 530, 530, [255,0,0]);
> Screen('Flip',w);
> stimTimeExceeded=1;
> end
> end
> t = GetSecs-t0;
> end
> screen('CloseAll');
> catch
> Screen('CloseAll');
> ShowCursor;
> end