# Problem in collecting RT during RSVP detection task

**URL:** <https://psychtoolbox.discourse.group/t/problem-in-collecting-rt-during-rsvp-detection-task/412>\
**Category:** Uncategorized\
**Created:** [October 4, 2017, 9:11am UTC](https://psychtoolbox.discourse.group/t/problem-in-collecting-rt-during-rsvp-detection-task/412 "2017-10-04T09:11:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jessica.galliussi](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@jessica.galliussi](https://psychtoolbox.discourse.group/u/jessica.galliussi)\
**Post date:** [October 4, 2017, 9:11am UTC](https://psychtoolbox.discourse.group/t/problem-in-collecting-rt-during-rsvp-detection-task/412/1 "2017-10-04T09:11:34Z")

</div>

Hi All,

I'm writing a code for execute an RSVP detection task, but I have a problem in collecting RT and accuracy.

Basically, what the code do at the moment is to present (in each trial) 16 squares: All squares are black except one which is white and is presented randomly in sequence positions from 6 to 11.

The stimulus (square) time is 133 ms, while the ISI (blank screen) is 367. Therefore the SOA is 500ms.

Participant will have to rapidly press a button (spacebar) when he/she see the white square. So I want to start collect the reaction time from the onset of the white square up to 500 ms (before the next black square appears). If participant will no respond during this time window, no reaction time is collected and accuracy is 0. Importantly, what I want is that the timing of the stimuli and the black screen doesn't change if participant press the spacebar (i.e., i don't want that the keypress determine a short ISI).

The code I usually use to record RT (and accuracy) is like this:

&nbsp;[starttime]= Screen('Flip',window);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; endtime=KbQueueWait();&nbsp; % Wait a Keypress

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StimTime=GetSecs;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; % while loop to show stimulus until subjects response&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;while (StimTime-starttime)\<=StimTime  

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [KeyIsDown, endtime, KeyCode]=KbCheck;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if KeyIsDown

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RT= round(1000\*(endtime-starttime)); %Compute reaction time in second

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PressBt=KbName(KeyCode);

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if KeyCode(seenSquare)==1

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; acSquare=1;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elseif KeyCode(seenSquare)==0

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; acSquare=0;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end

  

  

I tried to make some changes to the code (and to use KbQueueStart, KbQueueStop...), but what I always get is that the code wait for a keypress to present the next square, or that when the key is pressed it goes to the next stimulus shortening the duration of the blank screen (ISI).

Could you help me?

Thank you very much!

Jessica

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [October 18, 2017, 12:30pm UTC](https://psychtoolbox.discourse.group/t/problem-in-collecting-rt-during-rsvp-detection-task/412/2 "2017-10-18T12:30:49Z")

</div>

Hi Jessica,

  

what you Could do is just do the presentation of white square and blank screen without

any response collection, then check if there was a 'space' key response in the stimulation

interval after the visual stimulation ended, given that the key response is not supposed to

alter presentation schedule anyway.  

  

whiteDuration being 0.1333 seconds, or maybe expressed in frames or whatever,

totalStimDuration = 0.5 etc.  

  

spaceKey = KbName('space');  

KbQueueStart;  

KbQueueFlush();  

startTime = Sreen('Flip', window); % Onset of white square?

% Draw black stuff...  

blankStart = Screen('Flip', window, startTime + whiteDuration);  

endTime = Screen('Flip', window, startTime + totalStimDuration);

  

% Get all first key press times since KbQueueFlush():  

[~, firstPress] = KbQueueCheck();  

if (firstPress(spaceKey) \>= startTime) && (firstPress(spaceKey) \<= startTime + totalStimDuration) 

&nbsp;&nbsp;&nbsp; % Valid 'space' key response within the totalStimDuration interval:

&nbsp;&nbsp;&nbsp; RT = firstPress(spaceKey) - startTime;

else

&nbsp;&nbsp;&nbsp; % No space press or outside response interval:  

&nbsp;&nbsp;&nbsp; RT = 0;  

end

  

-mario

  

  

---In PSYCHTOOLBOX@yahoogroups.com, \<jessica.galliussi@...\> wrote :  
  

Hi All,

I'm writing a code for execute an RSVP detection task, but I have a problem in collecting RT and accuracy.

Basically, what the code do at the moment is to present (in each trial) 16 squares: All squares are black except one which is white and is presented randomly in sequence positions from 6 to 11.

The stimulus (square) time is 133 ms, while the ISI (blank screen) is 367. Therefore the SOA is 500ms.

Participant will have to rapidly press a button (spacebar) when he/she see the white square. So I want to start collect the reaction time from the onset of the white square up to 500 ms (before the next black square appears). If participant will no respond during this time window, no reaction time is collected and accuracy is 0. Importantly, what I want is that the timing of the stimuli and the black screen doesn't change if participant press the spacebar (i.e., i don't want that the keypress determine a short ISI).

The code I usually use to record RT (and accuracy) is like this:

&nbsp;[starttime]= Screen('Flip',window);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; endtime=KbQueueWait();&nbsp; % Wait a Keypress

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StimTime=GetSecs;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; % while loop to show stimulus until subjects response&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;while (StimTime-starttime)\<=StimTime  

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [KeyIsDown, endtime, KeyCode]=KbCheck;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if KeyIsDown

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RT= round(1000\*(endtime-starttime)); %Compute reaction time in second

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PressBt=KbName(KeyCode);

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if KeyCode(seenSquare)==1

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; acSquare=1;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elseif KeyCode(seenSquare)==0

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; acSquare=0;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end

  

  

I tried to make some changes to the code (and to use KbQueueStart, KbQueueStop...), but what I always get is that the code wait for a keypress to present the next square, or that when the key is pressed it goes to the next stimulus shortening the duration of the blank screen (ISI).

Could you help me?

Thank you very much!

Jessica

---

<div class="post-metadata">

**Author:** ![Mikel](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@Mikel](https://psychtoolbox.discourse.group/u/Mikel)\
**Post date:** [February 16, 2023, 1:54pm UTC](https://psychtoolbox.discourse.group/t/problem-in-collecting-rt-during-rsvp-detection-task/412/3 "2023-02-16T13:54:43Z")

</div>

Hi,

I need to run a RSVP experiment, and I’m trying to implement the code suggested by Mario to collect the resposnes. However, the KbQueueStart command is giving me an error:  
Error using PsychHID.

I’m using Windows 10, my “deviceIndex” according to GetKeyboardIndices is 0.

Any help would be very much appreciated.  
Thanks.

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [February 16, 2023, 2:08pm UTC](https://psychtoolbox.discourse.group/t/problem-in-collecting-rt-during-rsvp-detection-task/412/4 "2023-02-16T14:08:49Z")

</div>

Please provide the full error message, and minimal code that causes it

---

<div class="post-metadata">

**Author:** ![Mikel](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@Mikel](https://psychtoolbox.discourse.group/u/Mikel)\
**Post date:** [February 16, 2023, 3:39pm UTC](https://psychtoolbox.discourse.group/t/problem-in-collecting-rt-during-rsvp-detection-task/412/5 "2023-02-16T15:39:17Z")

</div>

Hi,

I have added “PsychHID(‘KbQueueCreate’)” at the beginning of my code. Now, however, I’m getting the following error message when the code gets to KbQueueCheck:

Error using KbQueueCheck  
Keyboard queue for device NaN already in use by GetChar () et al. Use of GetChar and keyboard queues is mutually exclusive!

I’ve posted this as an independent question here: [Collecting responses on RSVP paradigm](https://psychtoolbox.discourse.group/t/collecting-responses-on-rsvp-paradigm/4854)

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [February 17, 2023, 1:58am UTC](https://psychtoolbox.discourse.group/t/problem-in-collecting-rt-during-rsvp-detection-task/412/6 "2023-02-17T01:58:16Z")

</div>

Please don’t double-post, it wastes peoples time. Closing and locking.  
-mario

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [February 17, 2023, 1:58am UTC](https://psychtoolbox.discourse.group/t/problem-in-collecting-rt-during-rsvp-detection-task/412/7 "2023-02-17T01:58:21Z")

</div>


