= Tutorial 8: Stimulation delays = ''Authors: Francois Tadel, Elizabeth Bock'' The event markers that are saved in the file might not accurate. In most cases, the stimulation triggers saved by the acquisition system indicate when the stimulation computer requested a stimulus to be presented. After this request, the equipment used to deliver the stimulus to the subject (projector, screen, sound card, electric or tactile device) always introduce some delays. Therefore, the stimulus triggers are saved before the instant when the subject actually receives the stimulus. For accurate timing of the brain responses, it is very important to estimate those delays precisly and if possible to account for them in the analysis. This tutorial explains how to correct for the different types of delays in the case of an auditory study, if the output of the soundcard is saved together with the MEG/EEG recordings. A similar approach can be used in visual experiments using a photodiode. <> == Existing delays == Reminder: The full description of this auditory dataset is available on this page: [[DatasetIntroduction|Introduction dataset]]. '''Delay #1''': Production of the sound * The stimulation software generates the request to play a sound, the corresponding trigger is recorded in the stim channel by the MEG acquisition software. * Then this request goes through different software layers (operating system, sound card drivers) and the sound card electronics. The sound card produces an analog sound signal that is sent at the same time to the subject and to MEG acquisition system. The acquisition software saves a copy of it in an audio channel together with the MEG recordings and the stim channel. * The delay can be measured from the recorded files by comparing the triggers in the stim channel and the actual sound in the audio channel. We measured delays''' between 11.5ms and 12.8ms''' (std = 0.3ms). These delays are '''not constant''', we should correct for them. Jitters in the stimulus triggers cause the different trials to be aligned incorrectly in time, hence "blurred" averaged responses. '''Delay #2''': Transmission of the sound * The sound card plays the sound, the audio signal is sent with a cable to two transducers located in the MEG room, close to the subject. This causes no observable delay. * The transducers convert the analog audio signal into a sound (air vibration). Then this sound is delivered to the subject's ears through air tubes. Those two operations cause a small delay. * This delay cannot be estimated from the recorded signals: before the acquisition, we placed a sound meter at the extremity of the tubes to record when the sound is delivered. We measured delays '''between 4.8ms and 5.0ms''' (std = 0.08ms). At a sampling rate of 2400Hz, this delay can be considered '''constant''', we will not compensate for it. '''Delay #3''': Recording of the signals * The CTF MEG systems have a constant delay of '''4 samples''' between the MEG/EEG channels and the analog channels (such as the audio signal), because of an anti-aliasing filtered that is applied to the first and not the second. This translate here to a '''constant delay''' of '''1.7ms'''. <
> {{attachment:delays_sketch.gif||height="156",width="708"}} <
> == Evaluation of the delay == Let's display simultaneously the stimulus channel and the audio signal. * Right-click AEF#01 link > '''Stim '''> Display time series: The audio channel is '''UADC001'''. * Right-click AEF#01 link > '''ADC V''' > Display time series: The audio channel is '''UDIO001'''. * In the Record tab, set the duration of display window to '''0.200s'''. * Jump to the third event in the "standard" category. * We can observe that there is a delay of about '''13ms''' between the time where the stimulus trigger is generated by the stimulation computer and the moment where the sound is actually played by the sound card of the stimulation computer ('''delay #1'''). <
><
> {{attachment:delays_evaluate.gif||height="241",width="631"}} * What we want to do is to discard the existing triggers and replace them with new, more accurate ones created based on the audio signal. We need to detect the beginning of the sound on analog channel UDIO001. * Note that the representation of the oscillation of the sound tone is really bad represented here. The frequency of this standard tone is 440Hz. This was correctly captured by the original recordings at 2400Hz, but not in the downsampled version we use in the tutorial for taster processing. It should still be good enough for performing the detection of the stimulus. == Detection of the analog triggers == ==== Detecting the standard triggers ==== Run the detection of the "standard" audio triggers on channel UDIO001 for file AEF#01. * Keep the same windows open as previously. * In the Record tab, select the menu '''File > Detect analog triggers'''. * This opens the Pipeline editor with the process '''Events > Detect analog triggers''' selected. This window will be introduced later, for now we will just use it to configure the process options. Configure it as illustrated below:<
><
> {{attachment:delays_detect.gif||height="497",width="558"}} '''Explanation of the options''' (for future reference, you can skip this now): * '''Event name''': Name of the new event category created to store the detected triggers. <
>We can start with the event "standard", and call the corrected triggers "standard_fix". * '''Channel name''': Channel on which to perform the detection (audio channel UADC001). * '''Time window''': Time segment on which you want to detect analog triggers. <
>Leave the default time window or check the box "All file", it will do the same thing. * '''Amplitude threshold''': A sliding window screens all the file, and a trigger is set whenever the amplitude of the signal increases above X times the standard deviation of the signal over this sliding window. Increase this value if you want the detection to be less sensitive. * '''Min duration between two events''': If the event we want to detect is an oscillation, we don't want to detect a trigger at each cycle of this oscillation. After we detect one, we stop the detection for a short time. Use a value that is always between the duration of the stimulus (here 100ms) and the inter-stimulus interval (here > 700ms). * '''Apply band-pass filter before the detection''': Use this option if the effect you are trying to detect is more visible in a specific frequency band. In our case, the effect is obvious in the broadband signal, we don't need to apply any filter. * '''Reference''': If you have an approximation of the triggers timing, you can specify it here. Here we have the events "standard" and we want to detect a trigger in their neighborhood. <
>If we do not use this option, the process creates only one new group with all the audio signals, without distinction between the deviant and standard tones. * '''Detect falling edge''' (instead of rising edge): Detects the end of the tone instead of the beginning. * '''Remove DC offset''': If the signal on which we perform the detection does not oscillate around zero or has a high continuous component, removing the average of the signal can improve the detection. * '''Enable classification''': Tries to classify automatically the different types of events that are detected based on the morphology of the signal in the neighborhood of the trigger. ==== Results of the detection ==== * Navigate through a few of the new "standard_fix" events to evaluate if the result is correct. You can observe that the corrected triggers are consistently detected after the rising partion of the audio signal, two samples after the last sample where the signal was flat. * This means that we are over-compensating by 3.3ms. But at least this delay is constant and will not affect the analysis. We can count this as a '''constant delay''' of '''-3.3ms'''.<
><
> {{attachment:delays_results.gif||height="237",width="520"}} ==== Detecting the deviant triggers ==== * Repeat the same operation for the deviant tones. * In the Record tab, select the menu '''File > Detect analog triggers'''. <
><
> {{attachment:delays_deviant.gif||height="522",width="589"}} ==== Some cleaning ==== * We will only use the corrected triggers, we can delete the original ones for avoiding any confusion. * Delete the event groups "deviant" and "standard" (select them and press the '''Delete '''key). * Rename the group "deviant_fix" into "deviant" (double-click on the group name). * Rename the group "standard_fix" into "standard". * Close all: Answer YES to save the modifications.<
><
> {{attachment:delays_final.gif}} == Repeat on Run #02 == Repeat all the exact same operations on the link to file''' AEF#02''': * Right-click AEF#01 link > '''Stim '''> Display time series: The audio channel is '''UADC001'''. * Right-click AEF#01 link > '''ADC V''' > Display time series: The audio channel is '''UDIO001'''. * In the Record tab, select menu '''File > Detect analog triggers''': '''standard''' * In the Record tab, select menu '''File > Detect analog triggers''': '''deviant''' * Check that the events are correctly detected. * Delete the event groups "deviant" and "standard" (select them and press the '''Delete '''key). * Rename the group "deviant_fix" into "deviant" (double-click on the group name). * Rename the group "standard_fix" into "standard". * Close all: Answer YES to save the modifications. == Delays after this correction == We compensated for the jittered delays (delay #1), but not for the other ones (delays #2, #3). The final delay between the production of "standard_fix" triggers and the moment when the subject gets the stimulus is now: delay #2 + delay #3 + over-compensation. '''Final constant delay''': 4.9 + 1.7 - 3.3 = '''3.3ms''' We decide not to compensate for those delays because they do not introduce any jitter in the responses and they are not going to change anything in the interpretation of the data. == Selecting files to process == First thing to do is to define the files you are going to process. This is done easily by picking files or folders in the database explorer and dropping them in the empty list of the Process1 tab. 1. Drag and drop the following nodes in the Process1 list: Right/ERF (recordings), Right (condition), and Subject01 (subject) . {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutProcesses?action=AttachFile&do=get&target=files1.gif|files1.gif|class="attachment"}} * The number in the brackets next to each node represents the number of data files that where found in each of them. The node ERF "contains" only itself (1), Subject01/Right contains ERF and Std files (2), and Subject01 contains 2 conditions x 2 recordings (4). * The total number of files, ie. the sum of all those values, appears in the title of the panel "Files to process [7]". 1. The buttons on the left side allow you to select what type of file you want to process: Recordings, sources, time-frequency, other. Now select the second button "Sources". All the counts are updated and now reflect the number of sources files that are found for each node. . {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutProcesses?action=AttachFile&do=get&target=files2.gif|files2.gif|class="attachment"}} 1. If you select the third button "Time-frequency", you would see "0" everywhere because there are no time-frequency decompositions in the database yet. . {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutProcesses?action=AttachFile&do=get&target=files3.gif|files3.gif|class="attachment"}} 1. Now clear the list from all the files. You may either right-click on the list (popup menu ''Clear list''), or select all the nodes (holding ''Shift ''or ''Crtl ''key) and then press the ''Delete ''key. 1. Select both files Left/ERF and Right/ERF in the tree (holding ''Ctrl ''key), and put the in Process list. We are going to apply some functions on those two files. You cannot distinguish them after they are dropped in the list, because they are both referred as "ERP". If at some point you need to know what is in the list, just leave you mouse over a node for a few seconds, and a tooltip would give you information about it. Just like in the database explorer. . {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutProcesses?action=AttachFile&do=get&target=files4.gif|files4.gif|class="attachment"}} == Similar topics == === Button responses === Same thing with button responses: re-detect from Stim/UDIO001 === Photodiode === You can do similar things with a photodiode in the case of a visual experiment. <> <>