Jump to content

User Reference:Matlab Tools: Difference between revisions

From BCI2000 Wiki
Jhill (talk | contribs)
No edit summary
Jhill (talk | contribs)
No edit summary
Line 1: Line 1:
In the <tt>tools/matlab</tt> directory of your BCI2000 distribution, there are several of Matlab m-files that are useful for offline analysis of recorded data-files, from the Matlab command-line or in your own custom scripts. (If you prefer clicking the mouse to writing lines of Matlab code, you will probably be happier with  
In the <tt>tools/matlab</tt> directory of your BCI2000 distribution, there are several of Matlab m-files that are useful for offline analysis of recorded data-files, from the Matlab command-line or in your own custom scripts. (If you prefer clicking the mouse to writing lines of Matlab code, you will probably be happier with the [[User_Reference:BCI2000_Offline_Analysis|Offline Analysis]] Matlab GUI or the—now non-Matlab-based— [[User_Reference:P300Classifier|P300Classifier tool]].)


Here we provide an overview of the functions
Here we provide an overview of the main Matlab functions without going into the details of their calling syntax.  As always, you can go to the Matlab prompt and type something like
>> help bci2000chain
to get documentation on a particular function.


==BCI2000PATH==
==BCI2000PATH==


This utility
This is a bootstrapping utility. Before you do anything, Matlab needs to know where the tools are.  This function allows you to:
 
* tell Matlab where your BCI2000 distribution is
* return the full absolute path to a sub-part of the BCI2000 distribution. For example,  <tt>bci2000path('tools/matlab/bci2000path.m')</tt> would return the full path to this file itself (or at least, to where it should be).
* add subdirectories of the BCI2000 distribution to the Matlab path, for the duration of the current Matlab session
* add subdirectories of the BCI2000 distribution to the system shell's path, for the duration of the current Matlab session
* remove everything BCI2000-related from the Matlab and system paths again
 
Of course, before you can call <tt>bci2000path</tt>, Matlab needs to know where <tt>bci2000path</tt> itself is. This chicken-and-egg problem is typical of Matlab path-juggling.  You could use the graphical PATHTOOL to add an absolute path to its directory "permanently" to the Matlab path,  but anyone who has made heavy use of  Matlab for some years will know that this often leads to problems sooner or later. Personally, I write the following lines either in my <tt>startup.m</tt> file, or in some other handy function in the <tt>My Documents\MATLAB</tt> directory:
 
olddir = pwd;
cd('C:\BCI2000')  % The absolute path has to be hardcoded somewhere, and here it is.  Watch out, in case this is (or becomes) incorrect
cd tools, cd matlab
bci2000path -AddToMatlabPath tools/matlab
bci2000path -AddToMatlabPath tools/mex
bci2000path -AddToSystemPath tools/cmdline  % required so that BCI2000CHAIN can call the command-line tools
cd(olddir) % change directory back to where we were before
clear olddir
 




Line 19: Line 39:
* [[User_Reference:Contents]]
* [[User_Reference:Contents]]
* [[User_Reference:BCI2000_Offline_Analysis]]
* [[User_Reference:BCI2000_Offline_Analysis]]
* [[User_Reference:Matlab_MEX_Files]]
* [[User_Reference:Command_Line_Processing]] done
* [[Programming_Reference:Filter_Chain]] (also link to [[User_Reference:Command_Line_Processing]] )
[[Category:Data Analysis Tools]][[Category:Development]]

Revision as of 23:55, 27 January 2012

In the tools/matlab directory of your BCI2000 distribution, there are several of Matlab m-files that are useful for offline analysis of recorded data-files, from the Matlab command-line or in your own custom scripts. (If you prefer clicking the mouse to writing lines of Matlab code, you will probably be happier with the Offline Analysis Matlab GUI or the—now non-Matlab-based— P300Classifier tool.)

Here we provide an overview of the main Matlab functions without going into the details of their calling syntax. As always, you can go to the Matlab prompt and type something like

>> help bci2000chain

to get documentation on a particular function.

BCI2000PATH

This is a bootstrapping utility. Before you do anything, Matlab needs to know where the tools are. This function allows you to:

  • tell Matlab where your BCI2000 distribution is
  • return the full absolute path to a sub-part of the BCI2000 distribution. For example, bci2000path('tools/matlab/bci2000path.m') would return the full path to this file itself (or at least, to where it should be).
  • add subdirectories of the BCI2000 distribution to the Matlab path, for the duration of the current Matlab session
  • add subdirectories of the BCI2000 distribution to the system shell's path, for the duration of the current Matlab session
  • remove everything BCI2000-related from the Matlab and system paths again

Of course, before you can call bci2000path, Matlab needs to know where bci2000path itself is. This chicken-and-egg problem is typical of Matlab path-juggling. You could use the graphical PATHTOOL to add an absolute path to its directory "permanently" to the Matlab path, but anyone who has made heavy use of Matlab for some years will know that this often leads to problems sooner or later. Personally, I write the following lines either in my startup.m file, or in some other handy function in the My Documents\MATLAB directory:

olddir = pwd;
cd('C:\BCI2000')   % The absolute path has to be hardcoded somewhere, and here it is.  Watch out, in case this is (or becomes) incorrect 
cd tools, cd matlab
bci2000path -AddToMatlabPath tools/matlab
bci2000path -AddToMatlabPath tools/mex
bci2000path -AddToSystemPath tools/cmdline   % required so that BCI2000CHAIN can call the command-line tools
cd(olddir) % change directory back to where we were before
clear olddir


BCI2000CHAIN

The BCI2000 command-line tools allow the online processing performed by BCI2000 to be recreated exactly offline. This is possible because online BCI2000 modules consist of a chain of filters, each filter being implemented in a self-contained source file. We can therefore take the individual filter implementations and build them singly, as separate executables that can be called from the system command-line. Recreating a preprocessing chain offline is then a question of passing a stream of data through a chain of these filter tools, connected by an operating-system "pipe". The bci2000chain function uses the command-line tools, but hides the details and presents itself to you as a single Matlab function.


TODO

Link this page from