0

I'm currently doing a project on BCI motor imagery dataset. My interest is to extract that necessary component by ICA method. I'm currently using EEGLAB for that purpose. Can you please help me as how to extract the independent component variable from the GUI to the workspace of MATLAB?

Donald Duck
  • 8,409
  • 22
  • 75
  • 99

2 Answers2

1

After running ICA on datasets in eeglab, ICA weights are saved in icaweights matrix in the EEG struct (you can see the EEG struct in workspace when your data is loaded in eeglab), in order to convert icaweights to the signals you see in plot>Component Activations, assuming this is what you want to extract, do the following:

  1. First you'll need to load your data, file>load existing dataset.
  2. Choose the components you want to extract and save them as a vector. As an example here, I'll choose components 5 and 9:

    comp_idx = [5 9]; %id of channels we extract
    
  3. Transform the channel data(here denoted Y) to ICA activations(Y_ICA) as below:

    Y = EEG.data;   % set channel data to matrix Y
    ica_weights = EEG.icaweights; % copy icaweights matrix
    Y_ICA = ica_weights*Y; % Component Activations
    
  4. Y_ICA now contains all the component activations, use Y_ICA(comp_idx,:) to extract only the components you need, you can do operations on this new matrix such as summing up both components and plot:

    %% Mix components and plot
    figure;
    S = sum( Y_ICA(comp_idx,:) );
    plot(EEG.times, S, 'r')    % EEG.times contains the time data
    title('Mix of all Channels')
    
  5. Or plot each component separately:

    %% Plot each component
    figure;
    plot( EEG.times, Y_ICA(comp_idx(1),:))
    hold on
    plot( EEG.times, Y_ICA(comp_idx(2),:))
    

A Note: if your data is made up of epochs, then the EEG.data matrix will be a three dimensional matrix, the 3rd dimension being the epoch sets, so you will have to do the above procedure for each epoch, that is, Y = EEG.data(:,:,epoch_i) and iterate for epoch_i = 1:size(EEG.data,3)

ReZzT
  • 33
  • 5
0

I'm not sure if ReZzT's answer is completely right.

Looking at the eeg_getdatact.m file

edit eeg_getdatact

it can be seen that the component activations are calculated with an additional matrix multiplication (with icasphere). Look at lines 179-180:

data = eeg_getdatact( EEG ); 
data = (EEG.icaweights(opt.component,:)*EEG.icasphere)*data(EEG.icachansind,:);

which, simplified, the last line can be written as:

data = (EEG.icaweights*EEG.icasphere)*eegdata;