Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[open] Triggers in loop

edited June 2013 in OpenSesame

I try to use OpenSesame for ERP. So I decided to start with chess pattern. Here is my code for it:

# Generated by OpenSesame 0.27.3~pre1 (Frisky Freud)
# Tue Jun 11 15:04:49 2013 (nt)
# <>

set foreground "white"
set subject_parity "even"
set font_size "18"
set description "Default description"
set title "New experiment"
set transparent_variables "no"
set font_bold "no"
set coordinates "relative"
set height "768"
set mouse_backend "xpyriment"
set width "1024"
set compensation "0"
set sampler_backend "legacy"
set font_italic "no"
set background "black"
set subject_nr "0"
set keyboard_backend "legacy"
set start "experiment"
set font_family "mono"
set synth_backend "legacy"
set canvas_backend "xpyriment"

define sketchpad Chess2
    set duration "0"
    set description "Displays stimuli"
    draw image 0 0 "Chess2max8.jpg" scale=1 center=1 show_if="always"

define sequence experiment
    run trigger "always"
    run loop "always"
    run __inline_script "always"

define sketchpad Chess1
    set duration "0"
    set description "Displays stimuli"
    draw image 0 0 "Chess1max8.jpg" scale=1 center=1 show_if="always"

define sequence sequence
    run Chess1 "always"
    run inline_script "always"
    run Chess2 "always"
    run _inline_script "always"

define inline_script _inline_script
    set _prepare ""
    set description "Executes Python code"

define inline_script trigger
    import serial
    exp.serial_port = serial.Serial('COM4')
    set _prepare ""
    set description "Executes Python code"

define inline_script inline_script
    set _prepare ""
    set description "Executes Python code"

define inline_script __inline_script
    set _run "exp.serial_port.close()"
    set _prepare ""
    set description "Executes Python code"

define loop loop
    set repeat "1"
    set description "Repeatedly runs another item"
    set skip "0"
    set item "sequence"
    set column_order ""
    set cycles "50"
    set order "sequential"
    run sequence

Unfortunately ERP I am gating are blurred.
May be it is because delay between trigger 1 and trigger 2 is less than between trigger 2 and trigger 1. So addition time appears when new cycle of loop is started. How can I rewrite my code to solve this problem?
Also please find attached OpenSesame experiment archive and pictures:


  • edited 1:06AM

    Unfortunately ERP I am gating are blurred.

    I'm not sure what you mean by this?

    If the problem is that the interval between trigger 1 and trigger 2 (same trial) is not the same as that between trigger 2 of one trial and trigger 1 of the next trial, then you're essentially looking for "non-slip" or "absolute" timing. In that case, this post should get you started:

  • edited 1:06AM

    Let me show what I mean. On this picture ERP was registered with two programs. You can see that peak №1 is very sharp with first one, and latency of peak №1 is approximately 100 ms. And this correct form and latency.
    With OpenSesame I have slightly different results. Peak №1 is not sharp and latency is longer a bit. I think it's because of not very stable duration between stimuli and triggers. Can you give any suggestions how rewrite code to fix it.
    My script:

  • edited June 2013

    Ah, I see. In principle your code is fine. One thing that you could do to optimize the code is create the canvas object in an inline_script (i.e. not use a sketchpad) and send the trigger immediately after (not before!) the display is shown.

    Realistically though, the timing difference with the sketchpad approach that you use now should be negligible. Of course I cannot vouch for the timing on your specific system, but I have tested both the serial port and the display presentation (of PsychoPy) on other systems, and this should be extremely accurate, particularly when implemented well.

    Looking at your graph, I would like to point out something that suggests, or might suggest, that it's actually the timing of Presentation that's off. As you say, OpenSesame gives higher latencies of the ERP components, which obviously means that the trigger is registered before the trigger sent by Presentation. This strongly suggests that the Presentation trigger is registered too late, at least on average.

    I'm not an EEG expert, so I cannot say too much about it. Just that in principle the approach that you are using now should be very accurate, although you will have to benchmark your system to know whether it works well in practice—which is difficult. Furthermore, I wouldn't rely too much on the shape of the ERP signal, or on the assumption that Presentation is a golden standard.

    Good luck!


  • edited 1:06AM

    Personally, I think the idea that Presentation's timing is worse than that of a free experiment builder quite hilarious and I do hope Sebastiaan is right on this one (although I do hope this does not mean EEG-data collected using Presentation is compromised). On their website, I found the following quote:

    "The port code is sent at the logged time of the picture event (the time of a picture stimulus is the start of the first vertical scan that contains the picture), and is bound to the uncertainty of the picture presentation (see Help Guide : Stimuli : Visual Stimuli : Picture Stimuli : Picture Timing Accuracy). As for testing, you could use a photometer to send a code to the recorder (while Presentation does the same), to check if the delays for receiving the codes are the same. In LCD monitors especially, there may be a delay between the onset of a new scan and the appearance of the stimuli." (see this thread)

    From this, I would conclude that Presentation basically does the same thing OpenSesame does, although I would not know what exactly the 'picture uncertainty' is that the guy from Neurobehavioral Systems mentions (I do not have the Help Guide he refers to). As far as I know, the source code for Presentation is not available, so we're pretty much in the dark about what exactly is going on anyhow.

Sign In or Register to comment.