This is an old revision of the document!


A PCRE internal error occured. This might be caused by a faulty plugin

{{tag>faq trigger trialfun preprocessing}} ===== How can I check or decipher the sequence of triggers in my data? ===== Triggers, stimuli, responses, annotations, etcetera in the recording are in FieldTrip jointly represented as "events" and read from the dataset using **[[:reference:ft_read_event]]**. The following code demonstrates how you can do a visual check of the triggers and export them to an excel file. We start by reading the header (which we need for the sampling frequency) and the events. In case of NeuroMag *.fif data that was recorded with internal active shielding (IAS) and that has not been maxfiltered yet, you can disable the check for maxfilter. hdr = ft_read_header(dataset, 'checkmaxfilter', 'no'); event = ft_read_event(dataset, 'checkmaxfilter', 'no'); The "event" variable is a structure array, in which each element represent one event. >> event event = 528x1 struct array with fields: type sample value offset duration For convenience, you can represent the sample number (which is an integer), event type (which is a string) and the event value (which is usually an integer) like this smp = [event.sample]; typ = {event.type}; val = [event.value]; You can plot the events in a scatter plot. Along the horizontal axis is time, vertical is the value. figure plot(smp/hdr.Fs, val, '.'); {{:faq:screen_shot_2017-09-20_at_17.50.53.png?400|}} The visual inspection of the figure shows you the overall structure of the events in the recording. Often it allows you to decipher part of the experimental design. ==== Elekta Neuromag ==== The trigger coding in the Elekta Neuromag system is more complex than in most systems. One physical event gets coded in multiple trigger channels in the fif file and hence also in multiple FieldTrip events. There are STI101 and STI102 channels, which represent combined values; these are usually between 1 and 255. There are also STI00x with x running from 1 to 8, which represent the individual bits of the combined value. The STI00x channels are expressed in Volt and contain [[https://en.wikipedia.org/wiki/Transistor–transistor_logic|TTL]] level voltages. The following code finds all unique events and aligns the individual bits in the STI00x channels with the combined value in a table. <code> sample = unique(smp)'; latency = (sample-1)/hdr.Fs; type = unique(typ)'; trigarray = nan(length(sample), length(type)); for i=1:numel(sample) sel = find(smp==sample(i)); for j=1:numel(sel) trigarray(i, strcmp(type, typ{sel(j)})) = val(sel(j)); end end trigtable = array2table(trigarray, 'VariableNames', type); trigtable = [table(sample, latency) trigtable]; writetable(trigtable, 'trigger.xls'); </code> The table can easily be exported to Excel or LibreOffice, where you can do additional checks on the columns. {{:faq:screen_shot_2017-09-20_at_17.50.22.png?600|}}