Howdy, Stranger!

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

Supported by

EEG trigger and random time intervals

edited January 2018 in OpenSesame

Hi all. I'm a Phd Student and completely noob to Opensesame and to coding in general. I'm trying to write a very simple experiment where I want to send a trigger to an EEG system (Neuroconn system) every time I present an auditory cue (a beep). We would like to present the audio at a random time after a keypress (between 10 and 15 seconds after the key response lets say) for N trials. And here come the part where I'm struggling with. How can I say to Open Sesame ti randomly present this audio and set a trigger (and furthermore is possible to have a high temporal resolution between the audio and the trigger?!) Thats what I produced so far, and would really appreciate a lil help :)

define form_text_display Instructions_display
set timeout infinite
set spacing 10
set rows "1;4;1"
set only_render no
set ok_text Ok
set margins "50;50;50;50"
set form_title "Title"
set form_text "Your message"
set description "A simple text display form"
set cols "1;1;1"
set _theme gray
widget 0 0 3 1 label text="[form_title]"
widget 0 1 3 1 label center=no text="[form_text]"
widget 1 2 1 1 button text="[ok_text]"

define sampler Sound_sampler
set volume 1
set stop_after 0
set sample ""
set pitch 1
set pan 0
set fade_in 0
set duration sound
set description "Plays a sound file in .wav or .ogg format"

define sequence Trial_sequence
set flush_keyboard yes
set description "Runs a number of items in sequence"
run new_sketchpad always
run Sound_sampler always
run new_inline_script always

define loop Volontary_Actions_loop
set source_file ""
set source table
set repeat 1
set order random
set description "Repeatedly runs another item"
set cycles 1
set continuous no
set break_if_on_first yes
set break_if never
setcycle 0 empty_column ""
run Trial_sequence

define sequence experiment
set flush_keyboard yes
set description "Runs a number of items in sequence"
run new_inline_script_1 always
run Instructions_display always
run Volontary_Actions_loop always

define inline_script new_inline_script
set description "Executes Python code"
_run
global io
trigger = 1
port = 0x378
try:
io.DlPortWritePortUchar(port, trigger)
except:
print 'Failed to send trigger!'
end
set _prepare ""

define inline_script new_inline_script_1
set description "Executes Python code"
_run
try:
from ctypes import windll
global io
io = windll.dlportio # requires dlportio.dll !!!
except:
print 'The parallel port couldn\'t be opened'
end
set _prepare ""

define sketchpad new_sketchpad
set duration 745
set description "Displays stimuli"
draw fixdot color=white show_if=always style=default x=0 y=0 z_index=0

define sketchpad welcome
set start_response_interval no
set reset_variables no
set duration keypress
set description "Displays stimuli"
draw textline center=1 color=white font_bold=no font_family=serif font_italic=no font_size=32 html=yes show_if=always text="OpenSesame 3.1 Jazzy James" x=0 y=0 z_index=0

Thanks very much to everybody would like to help me :)
Bests,

Comments

  • And sorry for another question: What if I dont have a serial or parallel port?! What would be the best way to send triggers in that case ?
    Thanks everybody

  • Hi Flo,

    It depends a lot on your experiment, i.e. what happens in between the tone was presented? If it is a purely auditory experiment it is really simple. You can either randomly choose a delay, or if it supposed to be quite systematically random, you can also define intervals in the loop table and jitter them somewhat.
    Either way, you should do that in inline_scripts. I attach a small showcase experiment, to demonstrate the principle. If you want to use audio, check out the documentation: http://osdoc.cogsci.nl/3.1/manual/python/sampler/

    and furthermore is possible to have a high temporal resolution between the audio and the trigger?!)

    If you send the trigger right before you play the sounds, or vice versa, you should be good!

    And sorry for another question: What if I dont have a serial or parallel port?! What would be the best way to send triggers in that case ?

    Honestly, I've never heard about a case where neither parallel nor serial port were available. No idea what you would to in that case. Maybe USB?

    Hope this helps.

    Eduard

    Buy Me A Coffee

  • Dear Eduard,

    thank you very much. That alredy helped me a lot. Basically yes, we do not need anything to happen between the sounds, so we just want to send the triggers to the EEG (Which I will send before the sound) so that we can have a trigger on the EEG signal at the same time when the sound is played.

    I managed thanks to your example to make my sound play, the only thing I'm still struggling with is the number of time the sound is played. How can I determine this???
    Sorry, this are probably stupid question but its literally my first time I use Opensesame

    In attached the script (Its only a rough first draft) :)

    Thank you very much

  • Hi Flo,

    As I said, there are shload of different ways to determine how often your sound is being played. So, maybe first think about what makes most sense for your paradigm (normally/uniformly/exponentially randomly distributed). Once you decided which way to choose, I can help with the implementation. Okay?

    Eduard

    Buy Me A Coffee

  • Hi Eduard,

    Thanks again very much for your reply.
    Ok, let's say I want to present the sound randomly in an interval between 10 and 15 seconds for a fixed number of presentations (e.g 40 times) and then just stop. Nothing special needed.

    Thanks,
    Best,
    F.

  • Something like that:

    import random
    import numpy as np  
    src = pool['beep-07.wav']
    my_sampler = sampler(src, volume=.5)
    
    startTime = clock.time()
    
    # how many sounds
    n_events = 41
    # choose random time interval
    interval = random.randint(10000,15000)
    # choose random time points
    events = np.random.randint(0,interval,n_events)
    # sort chronologically
    events.sort()
    # keep track of the ith sound
    counter = 0
    play = 1
    while clock.time()-startTime<interval: # do that for 13 seconds
            if clock.time()-startTime>events[counter]:
                if play:
                    my_sampler.play()           
                counter += 1
                if counter == n_events:
                    play= 0
    

    Note that with this code, there is no restriction how close the tones are to each other. So there is a fair chance for overlap. One solution to fix this is predefine potential timepoints that are widely enough spaced, and select a certain number of them. e.g.

    import numpy as np
    potEvents = np.arange(0,interval,40) # at least 40ms between any two events
    events =random.sample(potEvents,40)
    events.sort()
    

    Goo dluck,

    Eduard

    Buy Me A Coffee

  • Dear Eduard,

    thank you very much again for your help. Much appreciated :)
    I will play around a bit with this.

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games