Jump to content

User Tutorial:Performing an Offline Analysis of EEG Data

From BCI2000 Wiki
Revision as of 23:54, 18 January 2008 by Jfialkoff (talk | contribs)

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 TargetCode state variable such that TargetCode 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 TargetCode change with respect to the data over time. For instruction on how to inspect data using the BCI2000 Viewer, please see User Reference:BCI2000Viewer.

The 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.TargetCode == 0". This instructs BCI2000 Offline Analysis to search the data for sections where the TargetCode 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.TargetCode == 2". This instructs BCI2000 Offline Analysis to search the data for sections where TargetCode 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.IntertrialInterval == 1". This instructs BCI2000 Offline Analysis that the trial edges correspond to data samples where IntertrialInterval 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 IntertrialInterval 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.

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 was mentioned earlier, 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 the data in more detail. To see how the data behaves at specific electrodes, we'll generate the spectra - a plot of energy versus frequency - at those electrodes. To see how the data behaves at a specific frequency, we'll generate the topographies - a plot of the r-squared values at each electrode - at those frequencies. In order to generate the topographies we will need to communicate to BCI2000 Offline Analysis approximately how the electrodes we recorded from were distributed. We do this by specifying 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:Eloc Helper, 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 can skip to the steps below that will show you how to use BCI2000 Offline Analysis to generate the spectra and topographies. 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 has completed, you will see the same feature plot as was generated in the previous section. Additionally, you will see spectra and topographies for the channels and frequencies 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'll expect less power at these frequencies during activity than when at rest as we see in these spectra. The spectra for channels 16 and 18 also considerable power 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 the optimal frequencies for on-line control are multiples of each other (e.g., 11 and 22Hz) which indicates that the higher frequency may simply be a harmonic of the lower frequency and, thus, highly correcated. In this case, using both frequencies rather than a single frequency will likely provide little to no added benefit. Very often, however, the optimal feature frequencies seem to have this harmonic relationship but have very different spatial distributions which implies an orthogonal relationship.

The frequencies targeted in our analysis do not exhibit a harmonic relationship. So, their relationship likely tends towards uncorrelated. 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.


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 clusters centered around (31 Hz, Channel 18), (31 Hz, Channel 10), (19 Hz, Channel 10) and (19 Hz, Channel 16) exhibit positive qualities for choosing features. Using the topographies and spectra, we confirmed that the channels and frequencies accounted for in these coordinates 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 the coordinates we've been researching. While each additional feature may possibly improve performance, it will certainly increase latency. So, with the information we have, we should attempt to choose features that are worth the increase in latency. One additional piece of information we can consider is the location of the electrodes. The image below is the montage for the data we are currently analyzing.

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).

Next Step

At this point you should understand how to use the BCI2000 Offline Analysis plots 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