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

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


During the calibration session, the volunteer is asked to spell out a given word by using a P300 character matrix, pictured below. During each run, the volunteer is asked to focus on the next letter in the word they are 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 volunteer 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, an analysis tool will be used to generate a configuration file with weights that will determine what portions of the input data correspond to selecting the desired letter. These weights are applied to the configuration session for one more run, and then the data from this run is also analyzed with the MatLab tool, and the number of flashes needed to ensure 100% accuracy is determined. The second configuration file generated and applied. This final set of parameters are saved as that volunteer’s parameter file for future spelling sessions.
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 Configuration Session==
==Performing the Calibration Session==


*Start BCI2000 by running <tt>batch/P3Speller_<Your_Amplifier>.bat</tt>
*Start BCI2000 by running <tt>batch/P3Speller_<Your_Amplifier>.bat</tt>
*Press '''Config''', and load the baseline parameters for copy spelling that you made earlier.
*Press '''Config''', and load the baseline parameters for copy spelling that you made earlier.
*In the '''Storage''' tab:
*In the '''Storage''' tab:
**Set ''SubjectName'' to the volunteer’s initials.
**Set ''SubjectName'' to the subject's initials.
**Set ''SubjectSession'' to <tt>001</tt>
**Set ''SubjectSession'' to <tt>001</tt>
**Set ''SubjectRun'' to <tt>01</tt>
**Set ''SubjectRun'' to <tt>01</tt>
*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.


*Request that the volunteer sit in a relaxed position, and that the volunteer not move or speak during the runs.
*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 volunteer focus and performance.
*Turning off or dimming the lights can improve the subject's focus and performance.
*Showing the brain wave readouts to the volunteer can drive in the message of 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.
*Press '''Start''' to show the flashing character matrix, and describe what the volunteer is expected to do.
 
*After you’ve explained the procedure, click '''Suspend''' to stop the process.
 
*Delete that run of data (The file should be named <tt>data\P300\<Volunteer's Initials>001R01.dat</tt>)
[[Image:RecordingEnd.PNG|right|500px]]
 
 
*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 <tt>data\P300\<Subject Initials>001\<Subject Initials>S001R01.dat</tt>).
 
{|
|height="200px"|
|}


*Press '''Start''' to record the run.
*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>.
*Once this recording has finished, close BCI2000 and locate the saved data files below the BCI2000 <tt>data</tt> directory.
*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.
*Once this recording has finished, close BCI2000 and locate the saved data files


==Analyzing The Calibration Session with Offline Analysis==
==Analyzing The Calibration Session with Offline Analysis==
We will now perform an ‘Offline Analysis’ with a tool provided with the BCI2000 system.
We will now use the BCI2000 "Offline Analysis" tool to analyze the subject's initial session.
[[Image:OfflineGUI.PNG|right]]
*Start the [[User Reference:BCI2000 Offline Analysis|BCI2000 Offline Analysis]] tool:
*Run <tt>tools/OfflineAnalysis/OfflineAnalysis.bat</tt>
**If you have a version of Matlab installed, run <tt>tools/OfflineAnalysis/OfflineAnalysis.bat</tt>.
*In the ''Analysis Domain'' field, choost '''Time (P300)'''
**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|500px]]
*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>
**‘Attended Stimuli’ refers to the letter or character the person is counting the flashes of, and triggers when the correct stimulus is shown
**‘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 <tt>(states.StimulusCode > 0) & (states.StimulusType == 0)</tt>
*For '''Target Condition 2''' enter <tt>(states.StimulusCode > 0) & (states.StimulusType == 0)</tt>
*For '''Target Condition Label 2''' enter <tt>Unattended Stimuli</tt>
*For '''Target Condition Label 2''' enter <tt>Unattended Stimuli</tt>
**‘Unattended stimulus’ refers to the letters or characters the person is not counting the flashes of, and triggers when an incorrect stimulus is shown
**‘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''
*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'''
*In this new dialog, select all of the data files taken during this configuration session, and click '''Open'''
Line 67: Line 72:
[[Image:FeaturesPlot.PNG|right|500px]]
[[Image:FeaturesPlot.PNG|right|500px]]


*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, the darker the color indicating a higher predictability that it 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 darkest 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 detected by 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 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>.  
*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 stimuli is given (the red line) and the brain’s responses to when the desired stimuli 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-stimuli reaction will typically be stronger than 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.
**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.


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




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


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


==Next Step==
To continue onto performing P300 spelling experiments, continue to [[User Tutorial:Performing a P300 Spelling Session|Performing a P300 Spelling Session]].


*Now we will save these customizations to a volunteer-specific parameters file that will allow the volunteer to free-spell with very high accuracy.
==See also==
*Start BCI2000 using <tt>batch/P3Speller_<Your_Amplifier>.bat</tt> file
[[User Tutorial:P300 BCI Tutorial]]
*Click '''Config''', and load the <tt>P300_copy_speller_<Your_Amplifier>.prm</tt> made previously
*Under the '''Filtering''' tab, click the '''Edit Matrix''' button by ''Classifier'' near the bottom
*Change this matrix to have 4 columns and however many rows as values as 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
*Close this matrix, and click '''Save Parameters''' to save this file, naming it however you deem fit
*Use this new parameter file to repeat the configuration session a few times, adding new rows to the classifier matrix each time for the new data points to be utilized.
*When accuracy is reliably above 90%, click '''Config,''' and click on the '''Application''' tab:
**''NumberOfSequences'' to this number as well
**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>
***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 volunteer for future P300 spelling experiments


 
[[Category:Tutorial]]
One program contributed to, and provided with, the BCI2000 system is the P300 GUI. This program utilizes MatLab R2007a to automatically sift through data files for datapoints indicative of a positive P300 reaction, and build a classifier matrix with those datapoints. The largest benefit to using this program is the obviated need for repeat configuration sessions, at the expense of decreased hands-on experience with the BCI2000 program itself. For a tutorial on how to perform the offline analysis with this GUI program, [[User Tutorial:P300 GUI for Offline Analysis Tutorial|please click here]].
 
 
To continue onto performing P300 spelling experiments, continue to [[User Tutorial:Performing a P300 Spelling Session|Performing a P300 Spelling Session]].

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