## problems about CSP Spatial Filter Trianer BOX

Concerning processing components: filters, file load/save, visualizations, communication ...
yanli
Posts: 16
Joined: Wed Oct 14, 2020 11:43 am

### problems about CSP Spatial Filter Trianer BOX

Hello,

I have some problem about the CSP Spatial Filter Trianer BOX. I use it on our own data in OpenViBE, which is really convenient, and get a configuration XML finally. The spatial filter coeffcients results we get are like this (after reshape it)↓： Then I try to compute spatial filter coeffcients not in OpenViBE, but in Matlab/Python using our own codes. The problem is that we get a different result. ↓(in matlab) We don’t know why it is like this. We use the same data before inputting CSP filter trainer.

Our codes used in matlab and python are as follows↓. Any help would be appreciate.

Code: Select all

``````%BcspProjection.m
function  W = BcspProjection(dataIn)
% dataIn: raw EEG data (Ns,Nc,Nt)
%                Ns :  the number of samples per channel
%                Nc: the number of channels
%                Nt: the number of trials
[Ns,Nc,Nt]=size(dataIn.x);
ClassLabel=unique(dataIn.y);
nbClasses=length(ClassLabel);

%The covariance of each trial was calculated
for i=1:Nt
E=dataIn.x(:,:,i)';
EE=E*E';
C(:,:,i)=EE./trace(EE);
end

%The mean covariance of all trials was calculated
for i=1:nbClasses
tmpCc(:,:,i)=mean(C(:,:,dataIn.y==ClassLabel(i)),3);
end

%The composite spatial covariance
Cc=tmpCc(:,:,1)+tmpCc(:,:,2);

%
[Uc Dc]=eig(Cc);
eigenvalue=diag(Dc);
[eigenvalue,eigIndex]=sort(eigenvalue,'descend');
Uc=Uc(:,eigIndex);

%The whitening transformation
P=diag(sqrt(1./eigenvalue))*Uc';

%
SL=P*tmpCc(:,:,1)*P';
%
[UB DL]=eig(SL);
eigenvalueS=diag(DL);
[eigenvalueS,eigIndexS]=sort(eigenvalueS,'descend');
UB=UB(:,eigIndexS);

%the projection matrix
W=UB'*P;
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%main.m
W = BcspProjection(EEGSignals);
Wp=W([1:3 (end-3+1):end],:);``````
Thanks
ZY
Last edited by yanli on Tue Jun 08, 2021 8:16 am, edited 3 times in total.

Thibaut
Posts: 226
Joined: Wed Oct 31, 2018 9:14 am

### Re: problems about CSP Spatial Filter Trianer BOX

Hi,
Thibaut
PS : I don't know if the all the value is completly different or just in different order. The compute of eigen value can be multiply by -1 between matlab and Eigen (our C++ Library) and order if it's in ascend or descend order can be changed but the application in final Use is the same. And an other thing take car of your trial cut in your data when i develop some algorithm and compare with matlab sometimes the cut is not exactly the same (one trial more or less for example).

yanli
Posts: 16
Joined: Wed Oct 14, 2020 11:43 am

### Re: problems about CSP Spatial Filter Trianer BOX

Hi,  As in the images, all the value is completly different We actually save the data into csv format after [Temporal Filter] and [Stimulation based epoching] in openvibe, then load it in matlab and use CSP algorithm. So I think the cut maybe the same.However we get different results as above and are really confused about it 