User Tutorial:Performing an Offline Analysis of EEG Data

From BCI2000 Wiki
Jump to: navigation, search

Although the basic properties of the Mu rhythm are identical for all humans, its spatial pattern and exact frequency are unique for each individual and depend on the current state of that individual. In order to facilitate online BCI, we must determine how properties like these change in response to a given action. For best results, we seek to find actions that produce the greatest response. BCI2000 Offline Analysis is a tool that will help you to perform just this task.

Experimental Design

This tutorial will make use of the eeg1_1.dat, eeg1_2.dat and eeg1_3.dat sessions that are included with BCI2000 and can be found in data/samplefiles/. In these sessions, the subject was asked to move both hands and both feet in a predefined pattern. The resulting data was recorded using BCI2000 and labeled using the StimulusCode state variable such that StimulusCode is equal to 1 when the subject is responding to the instruction to move both hands, 2 when the subject is responding to the instruction to move both feet and 0 when the subject is responding to the instruction to rest. If you are relatively new to BCI2000, you may find it helpful to inspect the data files we'll be using with the BCI2000 Viewer. Using this tool, you will be able to see how state variables like StimulusCode change with respect to the data over time. For instruction on how to inspect data using the BCI2000 Viewer, please see User Reference:BCI2000Viewer.

Performing an Offline Analysis

BCI2000 Offline Analysis is a useful tool for finding good features for use in an online task such as controlling a 2-D cursor. For this particular task, it is necessary to find two real or imagined actions whose corresponding responses will allow the subject to control up and down movement of the cursor. Of course the level of success will depend significantly on how much the responses differ (i.e., the more the responses differ the easier it will be to tell them apart). So, our task is simply to find two opposing actions that produce significantly different responses. Given the experimental design, there are three combinations to choose from: rest vs. both hands, rest vs. both feet, both hands vs. both feet. In the sections to follow, we will perform a thorough inspection of rest vs. both feet but the same steps can be easily modified to produce similar results for the other two combinations.

Generating a Feature Plot

BCI2000 Offline Analysis provides us with 3 different plots that will be useful during the analysis process. One of these plots, the feature plot, provides an overview of the data and is useful for choosing potential features. Let's begin by generating the feature plot:

  1. Open BCI2000 Offline Analysis. If this is your first time using BCI2000 Offline Analysis, you may want to review the instructions on how to install and run this application: User Reference:BCI2000 Offline Analysis.
  2. Set the analysis parameters as follows:
    1. Analysis Domain: Choose "Frequency" in order to perform a frequency-domain analysis
    2. Acquisition Type: Choose "EEG" since the data we'll be working with in this section was recorded using an EEG.
    3. Data Files: Click the "Add" button and navigate to data/samplefiles/. From there, select the files eeg1_1.dat, eeg1_2.dat and eeg1_3.dat and click "Open". To select multiple files, you'll need to first click on any one file and then, while holding down the control button on your keyboard, click the remaining files.
    4. Montage File: Leave this blank. The reason for doing so will be explained shortly.
    5. Target Condition 1: Enter the value "states.StimulusCode == 0". This instructs BCI2000 Offline Analysis to search the data for sections where the StimulusCode indicates that the subject was responding to the instruction to rest.
    6. Target Condition Label 1: The text entered here will be used to label data that is specific to condition 1. Since condition 1 corresponds to sections of rest, type "Rest" into this field.
    7. Target Condition 2: Enter the value "states.StimulusCode == 2". This instructs BCI2000 Offline Analysis to search the data for sections where StimulusCode indicates that the subject was responding to the instruction to move both feet.
    8. Target Condition Label 2: The text entered here will be used to label data that is specific to condition 2. Since condition 2 corresponds to sections where the subject was moving both feet, type "Both Feet" into this field.
    9. Trial Change Condition Enter the value "states.StimulusBegin == 1". This instructs BCI2000 Offline Analysis that the trial edges correspond to data samples where StimlusBegin becomes 1 or is 1 and becomes something else. Please see User Reference:BCI2000Viewer for instructions on how use BCI2000 Viewer to see how state variables like StimulusBegin change over time with respect to the data.
    10. Spectra Channels: Leave this blank. The reason for doing so will become clear.
    11. Topo Frequencies: Leave this blank. The reason for doing so will become clear.
    12. Spatial Filter: Choose "Common Average Reference (CAR)". Typically, for frequency domain analyses, filtering the data with a simple spatial filter such as the CAR filter results in sharper, more useful plots.
    13. Ignore Warnings: Leave this field unchecked. For more information on this field, please see User Reference:BCI2000 Offline Analysis.
    14. Overwrite existing plots: If you have not yet run any analyses, this field should be disabled. If it is enabled, it is best for the purposes of this tutorial to leave it checked. Unchecking this box will instruct BCI2000 Offline Analysis to open new figures whenever it plots which may be useful in situations where you want to compare the results of one analysis against another.
  3. Click "Generate Plots".

Once the analysis is complete, you will see a feature plot similar to the one below. This plot displays the r-squared values between the two distributions (i.e., the average signal for condition 1 and the average signal for condition 2) as a function of frequency and channel.

Eeg1FeaturePlt.png

The feature plot provides an overview of the data. Thus, it is typically the best place to start your analysis. Using this plot, we can find potential features simply by looking for clusters of high r-squared values. In the generated feature plot, we notice some clusters centered around (31 Hz, Channel 18), (31 Hz, Channel 10), (19 Hz, Channel 10) and (19 Hz, Channel 16). To estimate the effectiveness of these features, we will need to look at them in more detail.

Spectra and Topographies

As stated previously, the feature plot is useful for gaining an overview of the data and determining some of the more potentially useful features. BCI2000 Offline Analysis provides two more plots that allow us to look at these features in more detail. To see how the data behaves at specific electrodes, we'll generate spectra plots - plots that show the energy as a function of frequency. To see how the data behaves at a specific frequency, we'll generate the topographies - plots that show the r-squared values with respect to the location of a given electrode. In order to generate the topographies we will need to communicate the manner in which the electrodes were arranged. This is done with a montage file. While there is a montage file included with BCI2000 that is suitable for the data we'll be analyzing here, you will likely need to create or modify montage files for future analyses. For that reason, we recommend that you take the time now to familiarize yourself with the Eloc Helper. In User Tutorial:Designing an Eloc File, you will learn how to create a new montage file and modify an existing one so that you ultimately have your own montage file to use to complete this analysis. If you prefer not to complete the Eloc Helper tutorial at this time, you will still be able to complete this tutorial using one of the montage files that comes with BCI2000.

If you have finished designing your montage file or decided to use the one that's provided, please proceed to the steps below. Note that these steps pick up from the steps outlined in the previous section for generating the feature plot:

  1. Set the analysis parameters as follows:
    1. Montage File: Click the "Browse" button next to the field labeled "Montage Files" and browse to data/samplefiles/. If you completed the Eloc Helper tutorial and would like to use the montage file you created, double-click myeeg64.loc. Otherwise, double-click eeg64.loc to use the montage file that comes with BCI2000.
    2. Spectra Channels: In the previous section we found - by inspection of the feature plot - three channels that show considerable promise: 10, 16 and 18. To generate spectra for these channels, enter "10 16 18" into this field.
    3. Topo Frequencies: In the previous section we found - by inspection of the feature plot - two frequencies that show considerable promise: 19 and 31 Hz. To generate topographies for these frequencies, enter "19 31" into this field.
  2. Click "Generate Plots".

Once the analysis is complete, you will see the same feature plot as was generated in the previous section. Additionally, you will see a spectra plot and topographies similar to the ones below. In the spectra, we notice significant changes in spectral power at frequencies in the mu and beta ranges. Typically we expect less power at these frequencies during activity than when at rest as is these case in the generated spectra. The spectra for channels 16 and 18 also show significant differences in the lower frequencies (i.e., below the mu frequencies). Fluctuations at these frequencies have not been shown typically to be correlated to motor responses and are likely due to noise. Thus, we will want to avoid using these frequencies as possible feature candidates. As a note, it is often the case that one potential feature appears to be the harmonic of another. Take for example the case where one feature appeared at 11 Hz and the other at 22Hz. If, in this case, one feature were a harmonic of the other, the two would be highly correlated and there would likely be little to no benefit of using both features as opposed to just one. Very often, however, in the cases where there appears to be a harmonic relationship between two features, the features are very spatially dissimilar. In this case, the two features may not have such a high correlation and may both be useful for online classification.

Eeg1Spectra.png

The frequencies targeted in our analysis do not exhibit a harmonic relationship. Thus, it is likely the two are not highly correlated. The topographies below provide further evidence towards that assumption; notice the dissimilar spatial distributions for the two different frequencies. The topographies are also useful for evaluating the how physiologically plausible the recorded responses are. For instance, in the topographies below, the spatial distribution agrees with the expected spatial response for feet movement. See the User Tutorial:Introduction to the Mu Rhythm for more information about the physical properties of mu rhythms.


Eeg1Topos.png

Choosing the Optimal Features

Unfortunately, it is impossible to know which features will provide the best results. We can only speculate. The 3 plots we've generated with BCI2000 Offline Analysis, however, will surely help to make our guess a well-educated one.

From the feature plot we determined that the coordinates (31 Hz, Channel 18), (31 Hz, Channel 10), (19 Hz, Channel 10) and (19 Hz, Channel 16) may be effective features for online classification. Using the topographies and spectra, we confirmed that the channels and frequencies or these features agree with our expectations (i.e., the frequencies are in the mu or beta range and the spatial response is focused over the area of the motor cortex typically responsible for foot movement). We may, therefore, simply choose to use all of these features when attempting online control with this subject. While each additional feature may possibly improve performance, however, it will certainly increase latency. So, we will want to limit the number of features we select. So far we have limited our choices to only 4 potential features. To rule out some of these, we will consider the arrangement of the electrodes. The image below is the montage corresponding to the data we are currently analyzing.

Eloc64.png

Notice that electrodes 10 and 18 are very close to each other. We might, therefore, conclude that the (31 Hz, Channel 18) and (31 Hz, Channel 10) features may be highly correlated. Looking at the spectra and topographies, we can see that at 31 Hz, the r-squared values are slightly higher for channel 18 than they are for channel 10. So, in this case, we have sufficient reason to eliminate (31 Hz, Channel 10) as a feature. For a similar reason, we can eliminate (19 Hz, Channel 10). This leaves us with two features: (31 Hz, Channel 18) and (19 Hz, Channel 16).

Testing Other Combinations

In the previous section, we used BCI2000 Offline Analysis to compare rest vs. movement of both feet and found two features (i.e., frequency/channel combinations) that will be useful in determining which action the subject performed. At this point it may be useful to repeat the process above for the other two combinations: rest vs. both hands, both hands vs. both feet. Then, the best combination can be found by finding the best r-squared values amongst the three feature plots.

The Next Step

At this point you should understand how to use BCI2000 Offline Analysis to help you choose effective features. Now, let's continue on to User Tutorial:Interpreting the Results where we'll take a look at some other results from the same subject and compare them to what we've found here.

See also

User Tutorial:Obtaining Mu Rhythm Parameters in an Initial Session