Difference between revisions of "BCI Projects"

From ESE497 Wiki
Jump to navigationJump to search
(Created page with '* Project3: BCI Offline Analysis - Signal Detection **Plot R^2 for all Channels/Frequency Pairs **Analyzing BCI2000 dat Files **Start with …')
 
 
(32 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
 +
{{#widget:Iframe
 +
|url=https://wustl.app.box.com/embed/s/z19vh33836lx5skt4aag8nrz5wfbuoy6
 +
|width=800
 +
|height=550
 +
|border=0
 +
}}
 +
 +
 
* Project3: BCI Offline Analysis - Signal Detection
 
* Project3: BCI Offline Analysis - Signal Detection
 
**Plot R^2 for all Channels/Frequency Pairs
 
**Plot R^2 for all Channels/Frequency Pairs
**[[media:AnalyzingBCI2000DatFiles.pdf|Analyzing BCI2000 dat Files]]
 
 
**Start with [[media:OfflineAnalysisSpectral.m|OfflineAnalysisSpectral.m]]. This is the file you will modify for this project.
 
**Start with [[media:OfflineAnalysisSpectral.m|OfflineAnalysisSpectral.m]]. This is the file you will modify for this project.
***Open in Matlab. Click on File-Set Path and "Add with subfolders" the Tools folder from the BCI2000 folder
+
***Open in Matlab.  
 
***Click the Run arrow. Select eeg1_1.dat, eeg1_2.dat and eeg1_3.dat. Click Open
 
***Click the Run arrow. Select eeg1_1.dat, eeg1_2.dat and eeg1_3.dat. Click Open
 
**Remove the DC (average) for all 64 channels
 
**Remove the DC (average) for all 64 channels
Line 11: Line 19:
 
**Implement CAR Spatial Filtering using the BCI2000 funtion carFile
 
**Implement CAR Spatial Filtering using the BCI2000 funtion carFile
 
     signal = carFilt(signal,2) ;
 
     signal = carFilt(signal,2) ;
**For every channel compute the power spectrum for every segment of 80 samples every 40 samples for both condition==0 and condition==2 and average them. Create two 3D array of PowerSpectra of size(NumFrequencies,NumChannels,NumTrials) for both conditions.
+
**For every channel, compute the power spectrum for every segment of 80 samples with 40 samples of overlap for both condition==0 and condition==2 and average them. Create two 3D array of PowerSpectra of size(NumFrequencies,NumChannels,NumTrials) for both conditions.
**Compute the R^2 function for all Channel/Frequency pairs
+
**Compute the R^2 function for all Channel/Frequency pairs the BCI2000 function calc_rsqu. Type "which calc_rsqu" at the matlab command prompt to locate calc_rsqu.m.
**Plot the R^2 values for all Channel/Frequency pairs using the BCI2000 function calc_rsqu. It should look similar but not identical to the graph on the tutorial.
+
**Plot the R^2 values for all Channel/Frequency pairs using the Matlab function surf. It should look similar but not identical to the graph on the tutorial.
 
**Useful Matlab Functions:
 
**Useful Matlab Functions:
 
***find
 
***find
 
***spectrogram
 
***spectrogram
 
***surf
 
***surf
 +
**** After calling surf, you should execute the following line to eliminate those pesky yellow lines
 +
    set(gcf,'Renderer','Zbuffer')
 +
**** The 64th channel is not displayed because of a problem with surf. We need to pad a column of 0s to the end of the matrix to make it work:
 +
    surf([ressq zeros(size(ressq,1),1)]') ;
 
* Project4: BCI Offline Analysis - Signal Classification
 
* Project4: BCI Offline Analysis - Signal Classification
** Combine best Channel/Frequency pairs using eeg1 (use [[media:Lda.m|lda.m]])
+
** Combine best Channel/Frequency pairs using eeg1_(1,2,3).dat (use [[media:Lda.m|lda.m]])
** Collect your own data using the Emotiv Headset
+
***Plot the power in the 4 best Channel/Frequency pairs for the action and the rest conditions using the eeg1 data vs. trial
** Combine best Channel/Frequency pairs using your own data
+
*** Plot the action and rest results of the LDA vs. trial
** Plot the power in the 4 best Channel/Frequency pairs for the action and the rest conditions using the eeg1 data vs. trial
+
*** Plot the ROC for the 4 best Channel/Frequency pairs and the LDA
** Plot the action and rest results of the LDA vs. trial
+
*** [[media:OfflineAnalysisLDASolutionResults.pdf| Results]]
** Plot the ROC for the 4 best Channel/Frequency pairs and the LDA
+
** Collect your own data using the Emotiv Headset ([http://classes.engineering.wustl.edu/ese497/images/6/68/BCIStimPresentation.pdf Instructions])
** [[media:OfflineAnalysisLDASolutionResults.pdf| Results]]
+
*** Combine best Channel/Frequency pairs using your own data
 +
**** states.StimulusCode values for stimulus presentation
 +
***** 0: Gray Screen - Relax, blink, move around, etc.
 +
***** 1: Left - Clench left hand
 +
***** 2: Pause - Unclench
 +
***** 3: Right - Clench right hand
 
**Useful Matlab Functions:
 
**Useful Matlab Functions:
 
*** subplot
 
*** subplot
 
*** save, load
 
*** save, load
 
*** squeeze
 
*** squeeze
* Project 5: Move sbRIO robots based on BCI algorithm using EEG1 data
+
* Project 5: Move sbRIO robots based on BCI algorithm using Emotiv data
** Re-Package your Matlab code into 2 functions that
+
** Re-Package your Matlab code into 2 scripts that
*** 1) Read the trials from the .dat files and return 1 trial every time it is called.
+
*** 1) Acquire the trials: Read the trials from the .dat file that you created in Project 4 with the Emotiv headset. Return 1 trial every time this script is executed in the LabVIEW while loop.
*** 3) Computes the LDA measure from the current trial.
+
*** 2) Process the trials: Compute the LDA measure from the current trial. This will also execute for every iteration of the LabVIEW while loop.
** Test these new functions in a for loop in Matlab and make sure you LDA results match the results from before
+
*** The reason why you want to separate the processing of the trials from the acquisition of the trials is because in project 6, the trials will be acquired from the Emotiv headset.
 
** Call your matlab functions from inside BCI.vi and move the robots every time the action is detected. Verify that you get the number of errors you expected and that the LDA calculation matches from before.
 
** Call your matlab functions from inside BCI.vi and move the robots every time the action is detected. Verify that you get the number of errors you expected and that the LDA calculation matches from before.
 
* Project 6: Implement in real-time with Emotive headset
 
* Project 6: Implement in real-time with Emotive headset
 +
** Download [[media:EmotivReaderLV9.zip | Emotiv LabVIEW code]] and extract all files to the folder with your other LabVIEW files.
 +
** Emotiv.vi returns up to 128 samples (@ 128 Samples/sec) per channel. If your trials need to be longer than 1 second then you will need to buffer up the Emotiv.vi output.
 +
** If you call Emotiv.vi once per second as in EmoTop.vi, it returns a 128x22 matrix. Look at the column headings in Emotiv.vi to see which columns correspond to your data.
 +
** Don't forget to remove the mean and use the CAR filter on your emotiv data.
 +
** For the final demonstration, we need to re-run the training session. Collect 5 minutes of data with the BCI2000 Stimulus Presentation for 5 minutes. Keeping the headset on, re-compute the R^2 graph, pick the best channels, and run a new LDA on this new data. Implement the new channel frequency pairs, lda scaling and threshold in your LabVIEW code. Then, with the headset still on, run your project 6 code.
 
<!--
 
<!--
 
SP2010
 
SP2010

Latest revision as of 16:45, 3 August 2017

Error in widget Iframe: unable to write file /project/class-www/engineering/2017/fall/ese497/extensions/Widgets/compiled_templates/wrt672f4c7bc5d557_57326152


  • Project3: BCI Offline Analysis - Signal Detection
    • Plot R^2 for all Channels/Frequency Pairs
    • Start with OfflineAnalysisSpectral.m. This is the file you will modify for this project.
      • Open in Matlab.
      • Click the Run arrow. Select eeg1_1.dat, eeg1_2.dat and eeg1_3.dat. Click Open
    • Remove the DC (average) for all 64 channels
   for ch=1:size(signal, 2)
       signal(:, ch)=signal(:, ch)-mean(signal(:, ch));
   end
    • Implement CAR Spatial Filtering using the BCI2000 funtion carFile
   signal = carFilt(signal,2) ;
    • For every channel, compute the power spectrum for every segment of 80 samples with 40 samples of overlap for both condition==0 and condition==2 and average them. Create two 3D array of PowerSpectra of size(NumFrequencies,NumChannels,NumTrials) for both conditions.
    • Compute the R^2 function for all Channel/Frequency pairs the BCI2000 function calc_rsqu. Type "which calc_rsqu" at the matlab command prompt to locate calc_rsqu.m.
    • Plot the R^2 values for all Channel/Frequency pairs using the Matlab function surf. It should look similar but not identical to the graph on the tutorial.
    • Useful Matlab Functions:
      • find
      • spectrogram
      • surf
        • After calling surf, you should execute the following line to eliminate those pesky yellow lines
   set(gcf,'Renderer','Zbuffer')
        • The 64th channel is not displayed because of a problem with surf. We need to pad a column of 0s to the end of the matrix to make it work:
   surf([ressq zeros(size(ressq,1),1)]') ;
  • Project4: BCI Offline Analysis - Signal Classification
    • Combine best Channel/Frequency pairs using eeg1_(1,2,3).dat (use lda.m)
      • Plot the power in the 4 best Channel/Frequency pairs for the action and the rest conditions using the eeg1 data vs. trial
      • Plot the action and rest results of the LDA vs. trial
      • Plot the ROC for the 4 best Channel/Frequency pairs and the LDA
      • Results
    • Collect your own data using the Emotiv Headset (Instructions)
      • Combine best Channel/Frequency pairs using your own data
        • states.StimulusCode values for stimulus presentation
          • 0: Gray Screen - Relax, blink, move around, etc.
          • 1: Left - Clench left hand
          • 2: Pause - Unclench
          • 3: Right - Clench right hand
    • Useful Matlab Functions:
      • subplot
      • save, load
      • squeeze
  • Project 5: Move sbRIO robots based on BCI algorithm using Emotiv data
    • Re-Package your Matlab code into 2 scripts that
      • 1) Acquire the trials: Read the trials from the .dat file that you created in Project 4 with the Emotiv headset. Return 1 trial every time this script is executed in the LabVIEW while loop.
      • 2) Process the trials: Compute the LDA measure from the current trial. This will also execute for every iteration of the LabVIEW while loop.
      • The reason why you want to separate the processing of the trials from the acquisition of the trials is because in project 6, the trials will be acquired from the Emotiv headset.
    • Call your matlab functions from inside BCI.vi and move the robots every time the action is detected. Verify that you get the number of errors you expected and that the LDA calculation matches from before.
  • Project 6: Implement in real-time with Emotive headset
    • Download Emotiv LabVIEW code and extract all files to the folder with your other LabVIEW files.
    • Emotiv.vi returns up to 128 samples (@ 128 Samples/sec) per channel. If your trials need to be longer than 1 second then you will need to buffer up the Emotiv.vi output.
    • If you call Emotiv.vi once per second as in EmoTop.vi, it returns a 128x22 matrix. Look at the column headings in Emotiv.vi to see which columns correspond to your data.
    • Don't forget to remove the mean and use the CAR filter on your emotiv data.
    • For the final demonstration, we need to re-run the training session. Collect 5 minutes of data with the BCI2000 Stimulus Presentation for 5 minutes. Keeping the headset on, re-compute the R^2 graph, pick the best channels, and run a new LDA on this new data. Implement the new channel frequency pairs, lda scaling and threshold in your LabVIEW code. Then, with the headset still on, run your project 6 code.