Code covered by the BSD License  

Highlights from
Regularized Common Spatial Pattern with Aggregation (R-CSP-A) for EEG Classification

Regularized Common Spatial Pattern with Aggregation (R-CSP-A) for EEG Classification

by

 

The codes implement the Regularized Common Spatial Pattern with Aggregation (R-CSP-A) algorithm.

FDA.m
function FDAU=FDA(ftrs,gnd)
%Fishers discriminant analysis (FDA) 

[ftrDim,numSpl]=size(ftrs);
ftrmean=mean(ftrs,2);
numCls=length(unique(gnd));

SB = zeros(ftrDim);
for i = 1:numCls
    idxs=find(gnd==i);
    clsFtrs=ftrs(:,idxs);
    clsMean=mean(clsFtrs,2)-ftrmean;
    SB = SB + length(idxs)*clsMean*clsMean';
end   
SW = ftrs*ftrs' - SB;
if rank(SW)<ftrDim %regularization for singular SW
    SW=SW+1e-6*eye(ftrDim); 
end
option=struct('disp',0);
[FDAU, FDAV] = eigs(inv(SW)*SB,numCls-1,'lm',option);


Contact us