User Tutorial:Obtaining P300 Parameters in a Calibration Session: Difference between revisions

From BCI2000 Wiki
Jump to navigation Jump to search
 
(14 intermediate revisions by 3 users not shown)
Line 7: Line 7:
==Design of Calibration Session==
==Design of Calibration Session==


During the calibration session, the subject is asked to spell out a given word by using a P300 character matrix, pictured below. During each run, the subject is asked to focus on the next letter in the word he is spelling, as the rows and columns flash randomly and successively so that sometimes the flashing corresponds to the column or row containing the target character and sometimes it will not. As the subject counts the number of times the desired letter in the word flashes, a P300 response is generated. The purpose of the calibration session is to identify those features that discriminate between the desired and undesired rows/columns.  
During the calibration session, the subject is asked to spell out a given word by using a P300 character matrix, pictured below. During each run, the subject is asked to focus on the next letter in the word he is spelling, as the rows and columns flash randomly and successively so that sometimes the flashing corresponds to the column or row containing the target character and sometimes it will not. As the subject counts the number of times the desired letter in the word flashes, a P300 response is generated. In our example, each letter will flash 30 times in total (15 rows and 15 columns). The purpose of the calibration session is to identify those features that discriminate between the desired and undesired rows/columns. Without that information, it is impossible to interpret the subject's brain signal. Thus, do not expect any correct letter selection during the calibration session.


[[Image:P3SpellerMatrix.PNG|298px]]
[[Image:P3SpellerMatrix.PNG|450px]]


After the first few runs are collected, we will use the BCI2000 "Offline Analysis" tool to determine which features (in this case, signals at a particular location and time after the stimulus) correspond to the row or column of the desired character.
After the first few runs are collected, we will use the BCI2000 "Offline Analysis" tool to determine which features (in this case, signals at a particular location and time after the stimulus) correspond to the row or column of the desired character.
Line 23: Line 23:
*In the '''Application''' tab:
*In the '''Application''' tab:
**Make sure that ''InterpretMode'' is set to <tt>copy mode</tt>, and ''DisplayResults'' (directly below InterpretMode) is unchecked
**Make sure that ''InterpretMode'' is set to <tt>copy mode</tt>, and ''DisplayResults'' (directly below InterpretMode) is unchecked
**Find the ''TextToSpell'' field. This should be set to ‘THE’, and you will be changing it after each run.  
**Find the ''TextToSpell'' field. This should be set to ‘THEQUICKBROWNFOX’, and you will be changing it after each run.  
*Press '''Set Config''' to apply this configuration.
*Press '''Set Config''' to apply this configuration.


Line 29: Line 29:
*Turning off or dimming the lights can improve the subject's focus and performance.
*Turning off or dimming the lights can improve the subject's focus and performance.
*Showing the brain wave readouts to the subject can help understanding how artifact-generating behavior can be detrimental to the data.
*Showing the brain wave readouts to the subject can help understanding how artifact-generating behavior can be detrimental to the data.
[[Image:RecordingEnd.PNG|right|500px]]
*Press '''Start''' to show the flashing character matrix, and describe what the subject is expected to do.
*Press '''Start''' to show the flashing character matrix, and describe what the subject is expected to do.
*After you’ve explained the procedure, click '''Suspend''' to stop.
*After you’ve explained the procedure, click '''Suspend''' to stop.
*Delete that run of data (the file will be found at <tt>data\P300\<Subject Initials>001\<Subject Initials>S001R01.dat</tt>).
*Delete that run of data (the file will be found at <tt>data\P300\<Subject Initials>001\<Subject Initials>S001R01.dat</tt>).


*Press '''Start''' to record the run.
{|
*Once it has finished automatically, click '''Config''' and change the ''TextToSpell'' in the '''Application''' tab to <tt>QUICK</tt>.
|height="200px"|
*Press '''Start''' to record the run.
|}
*Once it has finished automatically, click '''Config''' and change the ''TextToSpell'' in the '''Application''' tab to <tt>BROWN</tt>.
 
*Press '''Start''' to record the run.
*Once it has finished automatically, click '''Config''' and change the ''TextToSpell'' in the '''Application''' tab to <tt>FOX</tt>.
*Press '''Start''' to record the run.
*Press '''Start''' to record the run.
*Once this recording has finished, close BCI2000 and locate the saved data files below the BCI2000 <tt>data</tt> directory.
*Once this recording has finished, close BCI2000 and locate the saved data files below the BCI2000 <tt>data</tt> directory.
Line 47: Line 50:
**If you have a version of Matlab installed, run <tt>tools/OfflineAnalysis/OfflineAnalysis.bat</tt>.
**If you have a version of Matlab installed, run <tt>tools/OfflineAnalysis/OfflineAnalysis.bat</tt>.
**Otherwise, follow the instructions provided [[User_Reference:BCI2000_Offline_Analysis#Systems_that_do_not_have_MATLAB_installed_or_with_versions_that_predate_MATLAB_v7.0|elsewhere]].
**Otherwise, follow the instructions provided [[User_Reference:BCI2000_Offline_Analysis#Systems_that_do_not_have_MATLAB_installed_or_with_versions_that_predate_MATLAB_v7.0|elsewhere]].
[[Image:OfflineGUI.PNG|right]]
[[Image:OfflineGUI.PNG|right|500px]]
*In the ''Analysis Domain'' field, choose '''Time (P300)'''
*In the ''Analysis Domain'' field, choose '''Time (P300)'''
*In the ''Acquisition Type'' field, choose '''EEG'''
*In the ''Acquisition Type'' field, choose '''EEG'''
*Next to ''Spatial Filter'', choose '''Common Average Reference (CAR)'''
*Next to ''Spatial Filter'', choose '''Common Average Reference (CAR)'''
*For '''Trial Change Condition''' enter <tt>states.StimulusBegin == 1</tt>
*For '''Trial Change Condition''' enter <tt>auto</tt>
*For '''Target Condition 1''' enter <tt>(states.StimulusCode > 0) & (states.StimulusType == 1)</tt>
*For '''Target Condition 1''' enter <tt>(states.StimulusCode > 0) & (states.StimulusType == 1)</tt>
*For '''Target Condition Label 1''' enter <tt>Attended Stimuli</tt>
*For '''Target Condition Label 1''' enter <tt>Attended Stimuli</tt>
Line 70: Line 73:


*When this is complete, you will see a feature plot similar to the one to the right. The vertical axis corresponds to the locations while the horizontal corresponds to the time delay after the stimulus. The color coding shows the r-squared value of that datapoint, with dark red colors indicating a high predictability that a response is produced by the desired letter being flashed.
*When this is complete, you will see a feature plot similar to the one to the right. The vertical axis corresponds to the locations while the horizontal corresponds to the time delay after the stimulus. The color coding shows the r-squared value of that datapoint, with dark red colors indicating a high predictability that a response is produced by the desired letter being flashed.
*The largest of these r-squared values between 250 and 550ms are what we are interested in. Pick the 4 points with the largest r-squared values between these times and record their time points and channels. The plot’s ''Data Cursor'' tool (Tools Menu &rarr; Data Cursor) allows for discrete identification of time points.
*The largest of these r-squared values between 250 and 550ms are what we are interested in. Pick 2-4 points with the largest r-squared values between these times and record their time points and channels. The plot’s ''Data Cursor'' tool (Tools Menu &rarr; Data Cursor) allows for discrete identification of time points.


*With these four points, close the feature plot, and enter the channel numbers of the data points you found into the ''Waveform Channels'' field and the time points into the ''Topo Times'' field.
*With these points, close the feature plot, and enter the channels of the data points you found into the ''Waveform Channels'' field and the time points into the ''Topo Times'' field.
**In the example above, the four best data points have r-squared values <tt>0.02218</tt>, <tt>0.02179</tt>, <tt>0.01928</tt>, and <tt>0.019</tt>, occur at times <tt>388.7ms</tt>, <tt>392.6ms</tt>, <tt>384.8ms</tt>, and <tt>365.2ms</tt> respectively, and all four are located in channel six. <tt>6, 6, 6, 6</tt> would be entered into ''Waveform Channels'' and <tt>388.7, 392.6, 384.8, 365.2</tt> would be entered into the ''Topo Times'' field. The order of the data points here does not matter, only that they are in the same order in both fields.
**In the example above, three data points have r-squared values <tt>0.032</tt>, <tt>0.055</tt>, and <tt>0.021</tt>, occur at times <tt>250ms</tt> around channel Po7, Po8, and Oz. <tt>6, 7, 8</tt> would be entered into ''Waveform Channels'' and <tt>250</tt> would be entered into the ''Topo Times'' field.
**If there are less than four points that seem appropriate, either because they are at the wrong electrodes, at the wrong times, or simply have too low of an r-squared value, that is fine, three or two values can work, though the fewer values used the lower the accuracy will be.
*Click '''Generate Plots''' to create the features plot again with a set of three graphs that show the correlation between the selected times after the desired stimulus is given (the red line) and the brain’s responses to when the desired stimulus is not given (the blue line). Topographies is also given at <tt>250ms</tt>.  
**Additionally, it may be helpful to re-run the analysis by setting the ''Spatial Filter'' to '''None''', particularly when few channels are used.
*Click '''Generate Plots''' to create the features plot again with a set of four graphs that show the correlation between the selected times after the desired stimulus is given (the red line) and the brain’s responses to when the desired stimulus is not given (the blue line).
**As seen below, the attended-stimulus reaction will typically be stronger than for the unattended stimuli, but in some cases the reverse is true. If the ‘unattended’ curve is larger than the ‘attended’ curve then make a note of this before moving on. The waveform seen here is similar to the others generated, only one is shown here for simplicity.
**As seen below, the attended-stimulus reaction will typically be stronger than for the unattended stimuli, but in some cases the reverse is true. If the ‘unattended’ curve is larger than the ‘attended’ curve then make a note of this before moving on. The waveform seen here is similar to the others generated, only one is shown here for simplicity.
**Additionally before moving on, determine the location of the response seen. The P300 response is generally observed centered on the Cz electrode, or just behind and directly in between the ears, and does not involve the frontal regions of the brain. Assuming these characteristics are present, it is proper to proceed.
**Additionally before moving on, determine the location of the response seen. The P300 response is generally observed centered on the Cz electrode, or just behind and directly in between the ears (example below), and does not involve the frontal regions of the brain. Assuming these characteristics are present, it is proper to proceed.


[[Image:Waveform.PNG|center|800px]]
[[Image:Waveform.PNG|center|800px]]


==Creating a subject-specific parameter file==
Now we will save these customizations to a subject-specific parameter file that will allow the subject to free-spell with very high accuracy.
*Start BCI2000 using <tt>batch/P3Speller_<Your_Amplifier>.bat</tt> file
*Click '''Config''', and load the configuration file you saved previously
*Under the '''Storage''' tab, set the ''SubjectSession'' parameter to "002", and the '''SubjectName''' parameter to the subject's initials.
*Under the '''Filtering''' tab, click the '''Edit Matrix''' button by ''Classifier'' near the bottom
*Change this matrix to have 4 columns and as many rows as values you are using, and click '''Set New Matrix Size'''
**In the first column, labeled ''Input Channel'', enter the channel of the first value you use
**In the second column, labeled ''Input Element (bin)'', enter the time of the best classification, immediately followed with <tt>ms</tt>, as in <tt>388.7ms</tt>
**In the third column, enter 1 as the output channel
**In the fourth column, enter 1 if the ''Attended'' line was larger than the ''Unattended'' line, -1 if the ''unattended'' line was larger than the ''attended'' line
**Repeat these steps for the remaining rows, and close the matrix when finished
* If a '''Common Average Reference''' was used in the analysis, under the '''Filtering''' tab change the '''SpatialFilterType''' parameter to '''Common Average Reference (CAR)'''; otherwise, leave it as '''None'''.
*Click '''Save Parameters''' to save this file, naming it however you deem fit
*Use this new parameter file to repeat the configuration session and data analysis a few times, adding new rows to the classifier matrix each time for new data points to be utilized.
*When accuracy is reliably above 90%, click '''Config,''' and click on the '''Application''' tab:
**Delete the contents of the ''Text to Spell'' field
**Set ''InterpretMode'' &rarr; <tt>online free mode</tt>
**Make sure the ''DisplayResults'' box is checked
**Click on '''Edit Matrix''' next to ''TargetDefinitions'' and scroll to the bottom:
***In the first column replace <tt>9</tt> with <tt>BS</tt> (for "backspace")
***In the second column replace <tt>9</tt> with <tt><BS></tt>
*Click '''Save Parameters''', and change the <tt>copy_spell</tt> portion of this parameter file name to <tt>free_spell</tt>
*This parameter file is now ready to use for that specific subject for future P300 spelling experiments


==P300Classifier==
==P300Classifier==
The use of the "Offline Analysis" program was provided to familiarize you with the characteristics of the P300 response.
The use of the "Offline Analysis" program was provided to familiarize you with the characteristics of the P300 response. The feature graph above inspects the quality of the Calibration Session. Once the results above seams reasonable, we can obtain a subject specific parameter file using the ''P300Classifier'' under the <tt>tools/P300Classifier</tt> folder. This stand-alone program determines optimal features (i.e., signal times and channels) and corresponding weights automatically, and outputs those in a classifier matrix. Use of this program streamlines the configuration process at the expense of decreased hands-on experience with BCI data and the BCI2000 program itself.
At the same time, manually selecting the best features will typically result in reduced performance compared to when the features are automatically selected. Such automatic selection is performed using the ''P300Classifier'' tool that is provided with BCI2000. This stand-alone program determines optimal features (i.e., signal times and channels) and corresponding weights automatically, and outputs those in a classifier matrix. Use of this program streamlines the configuration process at the expense of decreased hands-on experience with BCI data and the BCI2000 progra itself.


For instructions on using the P300Classifier, see [[User Reference:P300Classifier]].
For instructions on using the P300Classifier, see [[User Reference:P300Classifier]].

Latest revision as of 20:09, 23 July 2019

Obtaining P300 Parameters in the Calibration Session

Although the basic properties of the P300 evoked potential are the same for all individuals, the response's latency, width, and spatial pattern varies, and adaptation to individual parameters improves accuracy.

Thus, it is necessary to obtain these individual parameters prior to performing spelling experiments.

Design of Calibration Session

During the calibration session, the subject is asked to spell out a given word by using a P300 character matrix, pictured below. During each run, the subject is asked to focus on the next letter in the word he is spelling, as the rows and columns flash randomly and successively so that sometimes the flashing corresponds to the column or row containing the target character and sometimes it will not. As the subject counts the number of times the desired letter in the word flashes, a P300 response is generated. In our example, each letter will flash 30 times in total (15 rows and 15 columns). The purpose of the calibration session is to identify those features that discriminate between the desired and undesired rows/columns. Without that information, it is impossible to interpret the subject's brain signal. Thus, do not expect any correct letter selection during the calibration session.

P3SpellerMatrix.PNG

After the first few runs are collected, we will use the BCI2000 "Offline Analysis" tool to determine which features (in this case, signals at a particular location and time after the stimulus) correspond to the row or column of the desired character.

Performing the Calibration Session

  • Start BCI2000 by running batch/P3Speller_<Your_Amplifier>.bat
  • Press Config, and load the baseline parameters for copy spelling that you made earlier.
  • In the Storage tab:
    • Set SubjectName to the subject's initials.
    • Set SubjectSession to 001
    • Set SubjectRun to 01
  • In the Application tab:
    • Make sure that InterpretMode is set to copy mode, and DisplayResults (directly below InterpretMode) is unchecked
    • Find the TextToSpell field. This should be set to ‘THEQUICKBROWNFOX’, and you will be changing it after each run.
  • Press Set Config to apply this configuration.
  • Request that the subject sit in a relaxed position, and that the subject not move or speak during the runs.
  • Turning off or dimming the lights can improve the subject's focus and performance.
  • Showing the brain wave readouts to the subject can help understanding how artifact-generating behavior can be detrimental to the data.


RecordingEnd.PNG


  • Press Start to show the flashing character matrix, and describe what the subject is expected to do.
  • After you’ve explained the procedure, click Suspend to stop.
  • Delete that run of data (the file will be found at data\P300\<Subject Initials>001\<Subject Initials>S001R01.dat).
  • Press Start to record the run.
  • Once this recording has finished, close BCI2000 and locate the saved data files below the BCI2000 data directory.

Analyzing The Calibration Session with Offline Analysis

We will now use the BCI2000 "Offline Analysis" tool to analyze the subject's initial session.

  • Start the BCI2000 Offline Analysis tool:
    • If you have a version of Matlab installed, run tools/OfflineAnalysis/OfflineAnalysis.bat.
    • Otherwise, follow the instructions provided elsewhere.
OfflineGUI.PNG
  • In the Analysis Domain field, choose Time (P300)
  • In the Acquisition Type field, choose EEG
  • Next to Spatial Filter, choose Common Average Reference (CAR)
  • For Trial Change Condition enter auto
  • For Target Condition 1 enter (states.StimulusCode > 0) & (states.StimulusType == 1)
  • For Target Condition Label 1 enter Attended Stimuli
    • ‘Attended Stimuli’ refers to the letter or character the person is counting the flashes of, and triggers when the desired letter is flashed
  • For Target Condition 2 enter (states.StimulusCode > 0) & (states.StimulusType == 0)
  • For Target Condition Label 2 enter Unattended Stimuli
    • ‘Unattended stimulus’ refers to the letters or characters the person is not counting the flashes of, and triggers when the desired letter is not flashed
  • Click the Add button by Data Files
  • In this new dialog, select all of the data files taken during this configuration session, and click Open
  • Click Generate Plots and wait for the feature plot to appear
FeaturesPlot.PNG
  • When this is complete, you will see a feature plot similar to the one to the right. The vertical axis corresponds to the locations while the horizontal corresponds to the time delay after the stimulus. The color coding shows the r-squared value of that datapoint, with dark red colors indicating a high predictability that a response is produced by the desired letter being flashed.
  • The largest of these r-squared values between 250 and 550ms are what we are interested in. Pick 2-4 points with the largest r-squared values between these times and record their time points and channels. The plot’s Data Cursor tool (Tools Menu → Data Cursor) allows for discrete identification of time points.
  • With these points, close the feature plot, and enter the channels of the data points you found into the Waveform Channels field and the time points into the Topo Times field.
    • In the example above, three data points have r-squared values 0.032, 0.055, and 0.021, occur at times 250ms around channel Po7, Po8, and Oz. 6, 7, 8 would be entered into Waveform Channels and 250 would be entered into the Topo Times field.
  • Click Generate Plots to create the features plot again with a set of three graphs that show the correlation between the selected times after the desired stimulus is given (the red line) and the brain’s responses to when the desired stimulus is not given (the blue line). Topographies is also given at 250ms.
    • As seen below, the attended-stimulus reaction will typically be stronger than for the unattended stimuli, but in some cases the reverse is true. If the ‘unattended’ curve is larger than the ‘attended’ curve then make a note of this before moving on. The waveform seen here is similar to the others generated, only one is shown here for simplicity.
    • Additionally before moving on, determine the location of the response seen. The P300 response is generally observed centered on the Cz electrode, or just behind and directly in between the ears (example below), and does not involve the frontal regions of the brain. Assuming these characteristics are present, it is proper to proceed.
Waveform.PNG


P300Classifier

The use of the "Offline Analysis" program was provided to familiarize you with the characteristics of the P300 response. The feature graph above inspects the quality of the Calibration Session. Once the results above seams reasonable, we can obtain a subject specific parameter file using the P300Classifier under the tools/P300Classifier folder. This stand-alone program determines optimal features (i.e., signal times and channels) and corresponding weights automatically, and outputs those in a classifier matrix. Use of this program streamlines the configuration process at the expense of decreased hands-on experience with BCI data and the BCI2000 program itself.

For instructions on using the P300Classifier, see User Reference:P300Classifier.

Next Step

To continue onto performing P300 spelling experiments, continue to Performing a P300 Spelling Session.

See also

User Tutorial:P300 BCI Tutorial