Skip to content

edwin465/Comparison-between-two-implementation-approaches-of-TRCA-in-Matlab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Comparison-between-two-implementation-approaches-of-TRCA-in-Matlab

One of the state-of-the-art algorithms used in the SSVEP recognition is the task-related component analysis (TRCA). Here I compare two implementation approaches of TRCA in Matlab. One is implemented by Masaki Nakanishi in https://github.com/mnakanishi/TRCA-SSVEP/tree/master/src. Based on this version (see trca.m), I propose a new implementation approach, which has a faster calculation speed, see trca_fast.m.

The main difference between them is that the function trca() uses the FOR-loop to calculate the covariance matrix and the trca_fast() uses the matrix computation to calculate the covariance matrix. As we know that Matlab is better to do the calculation using the matrix computation than using the FOR-loop, the trca_fast() may do the calculation faster.

Using FOR-loop:

It calculates the summation of the covariance matrices between any two trials in the FOR loops (i.e., S and Q), as shown in the following code:

%     eeg         : Input eeg data 
%                 (# of channels, Data length [sample], # of trials)
for trial_i = 1:1:num_trials-1
    x1 = squeeze(eeg(:,:,trial_i));    
    x1 = bsxfun(@minus, x1, mean(x1,2));
    for trial_j = trial_i+1:1:num_trials
        x2 = squeeze(eeg(:,:,trial_j));        
        S = S + x1*x2' + x2*x1';
    end % trial_j
end % trial_i
UX = reshape(eeg, num_chans, num_smpls*num_trials);
UX = bsxfun(@minus, UX, mean(UX,2));
Q = UX*UX';

(More details can be found in trca.m)

Using matrix computation:

It calculates S and Q based on the matrix multiplication of two matrices, as shown in the following code:

%     eeg         : Input eeg data 
%                 (# of channels, Data length [sample], # of trials)
X1 = eeg(:,:);
X2 = sum(eeg,3);
S = X2*X2';
Q = X1*X1';

(More details can be found in trca_fast.m)

In mathematics, these two calculations (in Using FOR-loop and Using matrix computation) are equivalent if each trial data has zero mean (please refer to the paper 'Spatial Filtering in SSVEP-Based BCIs: Unified Framework and New Improvements' in https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=9006809 or https://www.researchgate.net/publication/339417095_Spatial_Filtering_in_SSVEP-based_BCIs_Unified_Framework_and_New_Improvements)

Comparison study:

We count the calculate time of trca() and trca_fast(). Then we compare their calculation times and their calculated eigenvectors. Note that this simulation is performed on a desktop PC with an i7 CPU (i7-4770 @ 3.4GHz) and 24 GB Ram. The following two figures show the difference between their calculation time under different number of trials and the difference between their calculated eigenvectors, respectively. The code can be found in comparison_trca_trca_fast.m

image Clearly, their calculation times have large difference,especially when the number of trials is more than 10.

image Their eigenvectors have no difference.

In this comparison, we assume that each trial data is center. So in the trca.m, there is no action to remove the mean value.

Anyway, according to my experience, whether the trial data is centralized or not does not have much difference in the SSVEP recognition performance using the TRCA algorithm. After preprocessing, the mean of the pre-processed data may be very small or close to zero.

Summary and Discussion

Citation:

If you use this code for a publication, please cite the following paper:

@article{wong2020spatial,
title={Spatial Filtering in SSVEP-based BCIs: Unified Framework and New Improvements},
author={Wong,Chi Man and Wang, Boyu and Wang, Ze and Lao, Ka Fai and Rosa, Agostinho and Wan, Feng},
title={{S}patial {F}iltering in {SSVEP}-based {BCI}s: {U}nified {F}ramework and {N}ew {I}mprovements},
journal=IEEE Trans. Biomed. Eng.,
volume={67},
number={11},
pages={3057 --3072},
year={2020},
publisher={IEEE}
}

Contact:

Please email me (chiman465@gmail.com) if you find any mistakes and problems about it.

About

Here I compare two implementation approaches of TRCA in Matlab.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages