Scripting issues, do not want to perform source imaging on all signals

I wanted to show the change in source power in real time (0.5 second per cycle reading. mat format EEG data, 8-12Hz bandpass filtering, and source imaging), so I wrote the following script.
But I found that as time went on, the script processing got slower and slower, and then I realized that when I did the source image, I did the source image of all the signals that had been generated before.
I don't want that. I just want to source the current signal.
I don't know what the problem is.
Can someone help me?

Here is my code:

HISTORY = 0.5
SubjectNames = {...
    'Subject03'}; 

for time_idx = 1:200
    pause(5); 
    sFiles = [];
    RawFiles = {...
        ['D:\ft\Matlab Project\SourceMapPlotOnlineFromTDTAndBs\ConfigFiles\BSTestMaterial\ChannelDataOfOnline',[num2str(time_idx),'.mat']]};
    sFilesRaw = bst_process('CallProcess', 'process_import_data_time', sFiles, [], ...
        'subjectname',  SubjectNames{1}, ...
        'condition',    'Test', ...
        'datafile',     {{RawFiles{1}}, 'EEG-MAT'}, ... % ['EEG-MAT' num2str(time_idx)]
        'timewindow',   [], ...
        'split',        0, ...
        'ignoreshort',  0, ...
        'channelalign', 0, ...
        'usectfcomp',   0, ...
        'usessp',       0, ...
        'freq',         [], ...
        'baseline',     []);

    % Process: Low-pass:30Hz
    sFilesBandpass = bst_process('CallProcess', 'process_bandpass', sFilesRaw, [], ...
        'sensortypes', 'EEG', ...
        'highpass',    8, ...
        'lowpass',     12, ...
        'attenuation', 'strict', ...  % 60dB
        'mirror',      0, ...
        'useold',      0, ...
        'overwrite',   0);

    % Process: Compute sources [2018]
    sFilesSources = bst_process('CallProcess', 'process_inverse_2018', sFilesBandpass, [], ...
        'output',  1, ...  
        'inverse', struct(...
             'Comment',        'sLORETA: EEG', ...
             'InverseMethod',  'minnorm', ...
             'InverseMeasure', 'sloreta', ...
             'SourceOrient',   {{'fixed'}}, ...
             'Loose',          0.2, ...
             'UseDepth',       0, ...
             'WeightExp',      0.5, ...
             'WeightLimit',    10, ...
             'NoiseMethod',    'reg', ...
             'NoiseReg',       0.1, ...
             'SnrMethod',      'fixed', ...
             'SnrRms',         1e-06, ...
             'SnrFixed',       3, ...
             'ComputeKernel',  1, ...
             'DataTypes',      {{'EEG'}}));
    % === DISPLAY ===
    hFigTf1 = script_view_sources(sFilesSources.FileName,'cortex'); 
    nFrame = 50;
    display_time = 2.5; 
    frame_time = display_time/nFrame;
    for i = 1:nFrame 
        pause(frame_time);
        panel_time('SetCurrentTime', i*(HISTORY/nFrame));
    end
    close([hFigTf1]); 
end

You are using output=1, which corresponds to "Kernel only: shared" in the options of the process.
Brainstorm creates one shared inversion kernel every time you call the process "Compute sources". Each shared kernel is linked to each data file in the folder.

Some recommendations:

  • Follow carefully all the introduction tutorials using the example tutorials before trying to script your analysis on your own data. This is all explained in there:
    https://neuroimage.usc.edu/brainstorm/Tutorials/SourceEstimation#Computing_sources_for_single_trials
  • Regenerate your script calls instead of using existing (and probably outdated) scripts. If you had done this, you would have had the comment 'output', 1, ... % Kernel only: shared in the script, which could have helped you understand what was going on.
  • Compute only one kernel for all your files, you have no reason to compute the inverse model multiple times.
  • Use a correct noise covariance matrix