Tutorial #1

In this short walkthrough, we will perform the basic signal-processing steps required to obtain an average ERP waveform. This includes (1) importing the dataset into letswave, (2) applying a band-pass frequency filter, (3) segment the continuous EEG recording into epochs aligned to stimulus onset, (4) apply a baseline correction, (5) reject epochs contaminated by artefacts, (6) computing an average waveform and (7) characterzing the latency, amplitude and scalp topography of the obtained ERPs.

The dataset used for this tutorial can be downloaded here.

 

1. Launching the Letswave user interface

After launching Matlab, set the current working directory to the folder where your dataset is located. Note that this step is optional, as you can alo navigate through folders directly within the Letswave interface.


Launch the Letswave user interface by typing letswave within the Matlab Command Window.

This will open the Letswave user interface. Check that the path located in the top edit box corresponds to the path where your dataset is located. At present, the data files list box should be empty, as it does not contain any letswave datasets. All Letswave functions are accessed using the top menu bar.

2. Import the original dataset

The data was acquired using a Micromed EEG system which stores the continuous EEG recording in its own format (System98 TRC files). To import the data into Letswave, it must first be imported in Letswave's own file format. To do so, select Import TRC Micromed files from the top menu bar (located in Import/Export > Import Signals). This opens a new window titled Import TRC. Within this window, click Select Files to select all the datafiles to import. The dataset consists of 11 TRC files. Each TRC file corresponds to a continuous EEG recording. In this experiment, transcutaneous electrical stimuli were delivered to the right median nerve. The stimuli were presented in blocks, using a variable 4-10 s inter-stimulus interval. Each EEG recording corresponds to one block.

After selecting the 11 TRC datafiles, click Open. The list of datafiles to import now appears within the Import TRC window.

Click Import datafiles to import the 11 TRC files into Letswave. You can check the progress of the import procedure in the Matlab Command Window.

Close the Import TRC window (note that you can close the TRC window before the process of importing the datafiles has finished).

 

3. Assigning digital triggers corresponding to stimulus onset

Go back to the Letswave user interface. To view the imported datafiles, you must click on the Refresh button (button R). The data files listbox should now display the 11 datafiles that you just imported. In this EEG recording, the triggers corresponding to the onsets of the stimulus were not stored as separate digital events. Instead, they were recorded as an analog 3,500 uV pulse embedded in the recording of channel O1. 

The level trigger function can be used to create digital events based on the location of these analog triggers. After selecting all 11 datafiles, launch Edit > Events > Level trigger from the top menu.

This will open a new window, titled Level trigger. This window controls a function that creates digital events based on an amplitude criterion. Set the Threshold parameter to 2500. This means that a digital event will be added to the dataset as soon as the signal exceeds 2500 uV.  Leave the Min ISI (s) parameter unchanged (1 second). This means that after locating an event, no additional event will be added to the dataset for a duration of 1 second.  To avoid assigning multiple events to the same analog trigger, this parameter should be greater than the duration of the analog trigger. To avoid missing any analog triggers, this value should be shorter than the minimum time interval between two triggers (i.e. the minimum inter-stimulus interval). The Direction defines the polarity of the analog trigger. Leave it unchanged (positive). The Channel parameter defines the channel containing the analog trigger. Set this parameter to O1 as, in the present dataset, analog triggers were stored in channel O1. The Event code parameter allows defining a label used to identify the trigger. Leave this parameter unchanged (s1). This can be useful if the dataset contains different types of events  (e.g. events corresponding to stimulus onset, events corresponding to reaction times, etc.).

Click Process to begin searching for events. This will create a new set of 11 datafiles which now include digital events labeled 's1'. Such as in all other Letswave functions, the Prefix parameter defines the prefix that will be appended to these new datafiles.  You can check the progress of the function within the Command Window. A total of 30 triggers should be found in each datafile.

 

4. Frequency filter

Go back to the Letswave user interface. After clicking the R button to refresh the list of data files, you should now see 11 files with the prefix 'lt', corresponding to the 11 new files that were created by the Level Trigger function. Select those 11 files and launch Preprocess > Filters > FFT filter from the top menu.

This opens a new window titled FFT filter. This window controls a function that allows filtering the select datasets using a low-pass, high-pass, band-pass or notch FFT filter. Select Band-pass filter from the dropdown menu. The Remove frequencies below (Hz) parameter defines the low-frequency cut-off (i.e. frequencies below that frequency will be removed from the signal). By setting this parameter to 0.5 Hz, the filter will remove the very slow drifts in the EEG signal. The Cutoff width parameter defines the width (in Hz) of the transition slope (Hanning function centered on the cut-off frequency; see the following link for an introduction on the Fourier method for designing digital filters). Set this parameter to 0.25 Hz. The Remove frequencies above (Hz) parameter  defines the high-frequency cut-off (i.e. frequencies abobe that frequency will be removed from the signal). By setting this parameter to 30 Hz, the filter will remove high-frequency activities such as muscle artefacts and 50/60 Hz environmental noise. Finally, set the associated Cutoff width parameter to 1 Hz.

Click Process to filter the data. This will create a new set of 11 datafiles with the prefix 'f'. Check the progress of the filtering function within the Matlab Command Window.

 

5. Epoch segmentation

Go back to the Letswave user interface. After clicking the R button to refresh the list of data files, you should now see 11 files with the prefix 'f', corresponding to the 11 new files that were created by the FFT filter function. Select those 11 files and launch Preprocess > Segmentation > Segmentation relative to events from the top menu.


This opens a new window titled Segmentation (multiple files). The box on the left displays a list of all the different types of events contained in the selected data files. In this example, there is only one type of event, labeled 's1' (i.e. the events previously created using the Level Trigger function). Select this event to generate epochs segmented relative to the latency of 's1', i.e. epochs segmented relative to the onset of the stimulus. The parameter Epoch Start defines the latency (in seconds) of the first bin of the epoch, relative to the onset of the event. Set this value to -0.5. The parameter Epoch End defines the latency (in seconds) of the last bin of the epoch, relative to the onset of the event. Set this value to 1. With these two parameters, the function will create one epoch for each event, extending from -0.5 to +1.0 s relative to the onset of the stimulus (i.e. the event 's1'). Note that, as an alternative to Epoch End, the segmentation can be defined using the parameter Epoch Size (in number of bins).  To do so, you must first check the Epoch Size checkbox.

Click Process to epoch the data. This will create a new set of 11 datafiles with the prefix 'ep_s1'. Check the progress of the epoching function within the Matlab Command Window.

 

6. Baseline subtraction

Go back to the Letswave user interface. After clicking the R button to refresh the list of data files, you should now see 11 files with the prefix 'ep_s1', corresponding to the 11 new files that were created by the Segmentation function. Select those 11 files and launch Preprocess > Baseline Operations > Baseline Correction from the top menu.


This opens a new window titled Baseline Subtraction. This window controls a function that allows applying a baseline correction to the selected epoched datasets. The parameter Reference Interval is used to define (in seconds) the time interval used as baseline. Set the first value to -0.5 and the second value to 0 (i.e. the time interval corresponding to the EEG segmenting preceding the onset of the stimulus). For each epoch and channel, the function will subtract the average of the amplitude values enclosed within the reference interval. Hence, in the output files, the average of the amplitude enclosed within the reference interval will equal 0.

Click Process to apply the baseline correction. This will create a new set of 11 datafiles with the prefix 'bl'. Check the progress of the baseline correction within the Matlab Command Window.

 

7. Merging epochs of the 11 datafiles into a single datafile

Go back to the Letswave user interface. After clicking the R button to refresh the list of data files, you should now see 11 files with the prefix 'bl', corresponding to the 11 new files that were created by the Baseline Correction function. Select those 11 files and launch Preprocess > Arrange Signals > Merge Epochs from Multiple Datasets from the top menu.


This opens a new window titled Merge Epochs. This window controls a function that allows merging the epochs of a selection of data files into a single data file. The files selected in the Letswave user interface are dispayed in the left window. The files to be merged are shown in the right window. Click the Add All button to add all the data files listed in the left window to the right window. This will create a new datafile containing all the epochs of all the selected data files. Given that each of the 11 original data file contains 30 epochs, the merged data file will contain 11*30=330 epochs. The parameter Output Filename is used to define the name of the merged data file. Because this is subject 6 of our experiment, set this parameter to merged_S06.

Click Process to merge the datafiles. This will create one single datafile named merged_S06. Check the progress of the merge function within the Matlab Command Window.

 

8. Using the Filter setting of the Letswave user interface

Go back to the Letswave user interface. After clicking the R button to refresh the list of data files, you should now see one additional file named merged_S06. Note that the list of data files is becoming a bit crowded. The Filter option of the Letswave user interface can be used to make it much easier to find and select given datafiles within a long list. Note that the filter box on the left lists all the different filename segments (e.g., 'bl', 'ep_s1', ...) found in the current data file list. Check the Filter option to enable the filter function.  Now select the 'bl' item in the filter box. Notice that the list shown in the right window now only shows files whose filename contain the string 'bl'. By selecting one or more items in the filter box, it is thus possible to display only a given set of data files.  For the rest of this tutorial, we will use the 'merged_S06' data file. Select the 'merged_S06' item in the filter box.


Using this filter option, the interface will only show files whose filename contain the string 'merged_S06'. At present, there is only one file fulfilling this criterion, i.e. the merged_S06 file that was created in the preceding step.

 

9. Assigning electrode coordinates and building a splinefile (required to display scalp topographies)

Select the 'merged_S06' file and  launch Edit > Electrodes > Assign Standard Spherical Locations from the top menu.

This opens a new window titled Lookup Channel Locations. This window controls a function that allows setting the electrode coordinates of all channels whose labels match those of a 'locs' file containing electrode locations (see this link for additional information concerning EEG channel location files). By default, the function will use the standard spherical coordinates provided in the 'Standard-10-20-Cap81.locs' file. This file contains standard spherical coordinates for 81 channels labeled according to the International 10-20 system. Therefore, you need to click on the Select Locations File button only if you want to use a custom channel locations file.

Click Process to assign coordinates to the different channel labels. Note that this will not create a new data file. Indeed, the channel information is added to the currently selected data file (i.e. the merged_S06 data file).

Now that the datafile has information concerning the 3D location of each electrode, it will be possible to display 2D scalp topographies. An additional step is required to display scalp topographies on a semi-realistic 3D head model (referred to as headplots). Indeed, generating headplots requires computing a spline file specific for the corresponding electrode montage (see this link to the EEGLAB website for additional information).

Within the Letswave user interface, select the 'merged_S06' file and  launch Edit > Electrodes > Build Spline File from the top menu. This opens a new window titled Build Splinefiles This window controls a function that allows creating a spline file corresponding to the electrode montage of the selected dataset. Note that this is possible only after having assigned electrode coordinates (see preceding step).

Click Process to build the spline file. This will create a new file with the name merged_S06.spl and link this file to the merged_S06 data file.

 

10. Rejecting artefacted epochs

A small number of epochs are contaminated by artefacts such as artefacts related to eye blinks or head movements. To reduce the contribution of artefacts to the final average waveforms, these epochs will first be identified and rejected. To do so, select the 'merged_S06' file from the Letswave user interface and  launch Preprocess > Artefacts > Reject Epoch (amplitude criterion) from the top menu.

This opens a new window titled Artefact Rejection. This window controls a function that allows removing epochs contaminated by artefacts. The top drop-down menu contains the list of data files to process. In this example, only one file will be processed. Accepted Epochs are shown in the left list and Rejected Epochs are shown in the right list. Using the > and < buttons, it is possible to manually move one (or a selection) of epochs between the Accepted and Rejected lists. The >> and << buttons can be used to set all epochs as Accepted or Rejected. The right part of the window is used to define the criterion to automatically identify artefacted epochs using a simple amplitude criterion. The Channels box is used to define one or more channels within which artefacts should be detected. Select the channel labeled Cz. The Maximum Accepted Amplitude and Minimum Accepted Amplitude parameters define the amplitude criterion. Epochs containing amplitude values above the maximum accepted amplitude or below the minimum accepted amplitude will be rejected. Set the Maximum Accepted Amplitude to 75 uV and the Minimum Accepted Amplitude to -75 uV. The Included Time Interval parameter allows defining the time interval within which to search for artefacts. Set the time interval to -0.5 - 1 seconds (i.e. the entire epoch duration). Note that using this parameter, it is possible to only test for artefacts within a given time interval. The Excluded Time Interval parameter  allows excluding a specific time interval when searching for artefacts. This can be useful, for example, to exclude the short time interval contaminated by a stimulation artefact.

Click the Apply to Current File button to apply the defined rejection criteria to the currently selected dataset. Note that if several datasets had been selected, the Apply to All Files button could be used to apply the defined rejection criteria to all datasets listed in the top dropdown menu.  The Summary button can be used to display a list of the number of rejected epochs in each datafile.

 

After applying the rejection criteria, there should be 13 epochs marked as rejected. The Plot Epochs panel can be used to quickly visualize accepted and rejected epochs. Set the channel to visualize (e.g. 'Cz') using the Select Channel dropdown list. Click the Plot Rejected button to display rejected epochs. This opens a new figure where each thin colored waveform corresponds to a single rejected epoch and the thick black waveform corresponds to the average of rejected epochs.

 

Now click the Plot Accepted button to display accepted epochs. This opens a new figure where each thin colored waveform corresponds to a single accepted epoch and the thick black waveform corresponds to the average of accepted epochs.

Finally, click Process. This will create a new data file with the prefix 'bl'. Check the progress of the artefact rejection function within the Matlab Command Window.

 

11. Average epochs across trials

We are now ready to compute the average waveform. Go back to the Letswave user interface. After clicking the R button, you should see one additional file named 'ar merged_S06'. Select that file and launch Postprocess > Average > Average Epochs.

This opens a new window titled Average Epochs. This window controls a function that computes the average across trials.

Click on Process. This will compute the average across trials and store it in a new data file with the prefix 'avg'. Check the progress of the function within the Matlab Command Window.

 

12. Visualizing results

Go back to the Letswave user interface. After clicking the R button, you should see one additional file named 'avg ar merged_S06'. You can view the waveforms contained in that data-file by simply double clicking the file (Simpleviewer interface). Here, we will use the Multiviewer interface which offers more features. The main difference between the two viewers is that the Multiviewer interface can be used to compare waveforms belonging to multiple datasets. This is most useful to compare ERPs obtained, for example, in different experimental conditions. To open the multiviewer, select the 'avg ar merged_S06' file and launch View > Wave Multiviewer from the top menu.

This opens a new window and its companion figure. The window is used to define a number of visualization options. The Data Files box lists all the selected data files (in the present example, it contains one single file, the 'avg ar merged_S06' file). The Epochs box lists all epochs in the selected data file (in the present example, it contains one single epoch, corresponding to the average waveform). The Channels box lists all the channels in the selected data file. You can select one or more items within each of these three boxes to choose the waveforms to display in the figure.

Select the channel labeled 'Cz'. The waveform shown in the figure now corresponds to the signal stored at Cz.

It is possible to simultaneously display several waveforms, either in separate graphs, or superimposed within the same graph. The Display as Separate Graphs (columns) parameter defines the data to be shown as separate graphs displayed as adjacent columns. The Display as Separate Graphs (rows) parameter defines the data to be shown as separate graphs displayed as adjacent rows. The Display as Superimposed Waveforms parameter defines the data to be shown as superimposed waveforms within the same graph. Select the channels labeled T3, C3, CZ, C4 and T4 in the Channels box. Now set the Display as Superimposed Waveforms parameter to Selection of Channels. Note that the figure now displays a single graph with five superimposed waveforms corresponding to the signal recorded at electrodes  T3, C3, CZ, C4 and T4. Now check the option Legend (channel). Note that the figure now displays a legend with the corresponding channel labels. Finally, set the Display as Separate Graphs (rows) parameter to Selection of Channels. Note that the figure now displays five graphs organized in separate rows, each displaying the signal recorded at a different channel.

By default, the X-axis and Y-axis scales are set to Auto. When Auto is enabled, the scales are automatically set to fit the entire waveform. It is also possible to define the axes manually, by entering minimum and maximum values to the X- and/or Y-axis parameters. When the Reverse option is checked, negative values are upwards and positive values are downwards (common convention when displaying ERP waveforms). When the Reverse option is unchecked, negative values are downwards and positive values are upwards. The Legend (filename), Legend (epoch) and Legend (channel) options allow displaying a figure legend with corresponding filename, epoch and/or channel information.

We will now estimate the latency, amplitude and scalp topography of the positive P200 peak which is best seen at electrode Cz, around 200 ms after stimulus onset. To do so, define a time interval by clicking on the figure at a position before the P200 peak, keeping the mouse button clicked, and releasing the mouse button at a position after the P200 peak. The range of the defined time interval appears in the Explore Interval panel and is shown as red and blue vertical dashed lines in the figure. Alternatively, you can define this range by editing the values displayed in the Explore Interval panel (e.g. 0.1 and 0.3 s). 

Click on Peak Table. This creates a table displaying, for each displayed waveform (here, the waveforms obtained at channels T3, C3, CZ, C4 and T4) the latency (x) and amplitude (y) of the minimum (min) and maximum (max) values found in the  defined time interval. Because the P200 is a positive peak, its latency and amplitude corresponds to the max(x) and max(y) values, respectively. The table also reports the mean (mean(x)) and standard deviation (sd(x)) of all the values located within the defined interval. The Sort According To parameter can be used to sort the content of the table according to the desired column. Values shown in the table can be copied and pasted into another application such as Excel. The Generate button creates a Matlab variable (cell array) with all table values in the Matlab workspace.

Set the dropdown menu to Maximum. Click on Scalp Maps. This generates a 2D scalp map of signal amplitude at the maximum within the defined time interval (i.e. a scalp map of signal amplitude at the latency of the positive P200 peak). This scalp map is generated using the EEGLAB topoplot() function (see this link for additional information).  The colorscale is defined by the values of the Y-axis scale of the main figure.

Click on Head Plots. This generates a 3D representation of the signal onto a semi-realistic head. Such as for 2D scalp maps, the topography that is shown corresponds to the signal amplitude at the maximum within the defined time interval (i.e. a scalp map of signal amplitude at the latency of the positive P200 peak). This scalp map is generated using the EEGLAB headplot() function (see this link for additional information).  The colorscale is defined by the values of the Y-axis scale of the main figure.