% OfflineAnalysisSpectral script
% Add BCI2000/tools to path if this is the first time running this script
if ( ~exist('firstRun') )
    addpath(genpath('C:\Apps\bci2000\tools')) ;
    firstRun = 0 ;
end

% Load .dat files
[Filenames, BCIDatPath] = uigetfile( {'*.dat','BCI 2000 Mat Files (*.dat)'},'MultiSelect', 'on' ) ;
Filenames = strcat(BCIDatPath,Filenames) ;
files = struct( 'name', Filenames) ;
[ signal, states, parameters ] = load_bcidat( files.name );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%signal: NxM array of samples from the electrodes during the experiment. N
%is the number of samples and M is the number of electrodes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%parameters.SamplingRate.NumericValue: Sample rate for data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%states.StimulusBegin: Nx1 column vector where N is the number of samples.
%This array alternates between 0 and 1 and changes everytime 
%states.StimulusCode changes indicating a new condition has begun.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%states.StimulusCode: Nx1 column vector where N is the number of samples.
%This array indicates the condition number for every sample.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%For example, in data\samplefiles\eeg1_1.dat the subjects starts at rest 
%(condition=0) and then raises both feet (condition2) at sample 673 and
%then goes back to rest at sample 1328. Therefore:
%states.SimulusBegin(1  :672 )=0 states.SimulusCode(1  :672 )=0   Rest
%states.SimulusBegin(673:1328)=1 states.SimulusCode(673:1328)=2   Both Feet
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% Power Spectrum Constants
FSampling=parameters.SamplingRate.NumericValue;

