Howdy, Stranger!

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

Supported by

[open] General P300 Oddball Presentation

edited March 2013 in OpenSesame

Hi Everyone!

Just wanted to speak up and introduce myself, I am a PhD candidate at the Centre for Intelligent Systems Research in Australia; I am currently working on some P3/ERP oddball paradigms and recently stumbled upon this neat little app.

Just a couple of questions regarding setting up the program, my experiment is as follows:

Visual task requiring the participant to observe a computer screen which will display a target and non-target stimulus images, there is no response mechanism (such as a reaction time switch) implemented as we do not want to activate the motor cortex. The stimulus (target - blue circle) screen is shown a set number of times (50) at random intervals during the test, a non-target screen (red square) is shown as the default image, a fixation point is shown at all other times. The target/stim image can not be shown two consecutive times, also the random timing of the stim target must change each iteration. See below for an example)
At each target/stim screen the software must trigger a parallel port pin which is connected to a NeuroScan SynAmpsRT EEG system. (this is already implemented)

Non-Target O(750ms)
Fixation (500ms)
Non-Target O(750ms)
Fixation (500ms)
Target <-
Fixation (500ms)
Non-Target O(750ms)
Fixation (500ms)
Non-Target O(750ms)
Fixation (500ms)
Fixation (500ms)
...(repeat for 6 minutes)

My question is this, can this software generate the random numbers/allocation so that the target/stim screens are not duplicated/shown twice in a row?

Any help will be greatly appreciated :)




  • edited 3:29AM

    wow Luke,
    how cool. I am going to hopefully use this software to run a auditory oddball task. I wish I could advise you and or answer your questions. the EEG/ERP doc page has info on triggers for EEG/ERP as well as links to forum. These links address tiggers and connections between eeg equipment and this software. I do not think however, that they will answer you question. I will watching your post closely and hopefully someone will be able to answer your questions.

  • edited 3:29AM


    We will answer your post as soon as possible!

  • edited 3:29AM

    Hi Luke,

    You can avoid the target from being presented twice in a row by preparing your trial list at the start of your experiment. This can be achieved by placing something like the following code in an inline_script item at the beginning of your experiment:

    # Import the built-in Python module random:
    import random
    # Define counters:
    nTarget = 50
    nNonTarget = 250
    # Create a list containing for example 50 targets and 
    # 250 non target:
    trial_list = ["target"]*nTarget+ ["non_target"]*nNonTarget
    # Shuffle the list by using the random.shuffle() function:
    # Check for two targets in a row:
    # Give the Boolean keepRunning a starting value:
    keepRunning = True
    # We walk through the list until our criteria are met:
    while keepRunning:
        # Set keepRunning to False
        keepRunning = False
        # For every item in the list, check whether this item AND the next
        # one are 'target' (note that we skip the very last one because
        # it has no following item):
        for i in range(len(trial_list)-1):
            # If the current item and the next one are 'target':
            if trial_list[i] == trial_list[i+1] == "target":
                # Set keepRunning to True, meaning the list doesn't meet our criteria yet:
                keepRunning = True
                # Swap the content of the current item and the previous one:
                trial_list[i], trial_list[i-1] = trial_list[i-1], trial_list[i]
                # And break from the current loop to walk through the list again:
    # Make the trial_list global such that it becomes available in future inline_sript
    # items as well:
    global trial_list

    Next, to determine whether a given trial is a target or a non-target, append a second inline_script item at the beginning of your trial sequence and place something like the following in its Prepare phase tab:

    # Determine the trial type of the current trial 
    # by 'popping' (i.e. taking without replacement) 
    # one item from the previously-defined trial list.
    # We do this by using the built-in Python function pop():
    trial_type = trial_list.pop()
    # Next, we should set the variable 'trial_type' to
    # make it available in the GUI (notably, the Run-if 
    # boxes in the trial_sequence item).
    # We do this by using the built-in OpenSesame experiment 
    # function exp.set():
    exp.set("trial_type", trial_type)

    Finally, prepare your sketchpad items for the target and the non-target like normal. However, set their "Run if" statements in the trial_sequence item to [trial_type] = target and [trial_type] = non-target, respectively.

    After applying this, your overview area and trial sequence item should look like this:


    An example experiment can be downloaded here (download, change the extension to '.opensesame' instead of '.txt' and open as normally):

    If you would like to apply more constraints to your trial list, you could try one of the following pseudo-randomisation programs:

    I hope this helps!



  • edited 3:29AM

    Lotje, you are a champion!

    Many thanks for the rather extensive help with the program, I have updated my experiment and it is running beautifully (sans LPT triggers).

    One (hopefully) little issue remains, I am running a Win7x32 PC (and an additional W7 x64 system) with a PCI Parallel port card, I have been trawling the internet for a solid method of sending trigger codes via the parallel port through to the SynAmpsRT system with various degrees of failure.

    Some say you can, some say you can't; all in all it seems to be a Win7 issue. I had been previously using a custom uController circuit to perform the triggering; which was based on running an Arduino Pro Mini, running the firmata sketch, from this I had been using a small sketch based on the Processing program for the visualisation which triggered the Arduino which triggered the optoisolator circuit connected to the parallel trigger port on the SynAmpsRT system. This worked quite well however I am a little concerned with the temporal accuracy of the triggering circuit as it is isolated from all other interfaces/computers/participants using a series of optoisolators (each with their own timing characteristics, this was to medically isolate the system from the participant and to ensure that any 'direct stimulation' via the electrodes was impossible).

    Hence the subsequent trial of OpenSesame :). (A far more extendable solution, without the need for time consuming custom/proprietary hardware)

    I have attempted to use the examples given in the ERP trigger tutorial however I see in the event window that both the target and non-target triggers are being sent in succession regardless of the visual presentation.


    Figure 1 - Debug Window


    Figure 2 - Full Screen Shot


    Figure 3 - Sequence Image

    Am I performing this in the right manner/order? I am not much of a python programmer, but if need be I can learn it, and I can follow code quite well (C, C++, assembly and Matlab are my 'normal' languages).

    In the meantime I think I may have to head down to the electronics lab and make a physical parallel port monitor with a few LEDs as I am yet to find any parallel port monitor software which works (robustly) under Windows 7.

    Again, thanks for your time Lotje and ajspoerner.

    Kind regards,

  • edited 3:29AM

    Luke and Lotje,

    Thank you both so much. I think I get what I need to do. Luke, good luck on your project. Lotje, thank you again for your suggestions.

    Kind Regards,
    AJ spoerner

  • edited 3:29AM

    Great news, I managed to get the PCIe card working to trigger the SynAmpsRT system :) however it is only showing one trigger code, not separate codes for target and non-target stimuli. But it's working under Win7 x32 with a PCIe card! Happy days.

    Will post how I managed to get it working when I have some spare time (at work atm).


  • edited 3:29AM

    Hi Luke,

    Great that you managed to get this far! If you have information to add for the triggers page, please don't hesitate to post (or add directly).

    I have attempted to use the examples given in the ERP trigger tutorial however I see in the event window that both the target and non-target triggers are being sent in succession regardless of the visual presentation.

    Could it be that you have placed the code in the prepare phase of the inline_script item? The prepare phase is always executed, regardless of the Run-if statement. Since you really want to send the trigger 'when the action happens', the code should be in the run phase.


  • edited 3:29AM

    'var.trial_type == "non"_"target"' is not a valid conditional statement

    Can anyone help me?

Sign In or Register to comment.