Computing PLV (with Hilbert) for one frequency band

Hello,

I am trying to write my script to automate the process of importing the data into brainstorm, setting the channel file, and lastly find the PLV values. I remember reading somewhere that importing the data should be done in one process and have another process for PLV. Is there a way I can implement this strategy of of separate processes into my code? I mean could anyone explain why I keep getting errors for the code shown below even though it works fine for other functional connectivity metrics such as coherence and correlation.

The portion I am talking about in my current code that is giving me an error:

%% Basic processes
    % Process: Import MEG/EEG: Existing epochs
    sFiles = bst_process('CallProcess', 'process_import_data_epoch', sFiles, [], ...
        'subjectname',   SubjectNames{1}, ...
        'condition',     '', ...
        'datafile',      {data_file_to_use,'FIF'}, ...
        'iepochs',       [], ...
        'eventtypes',    '', ...
        'createcond',    0, ...
        'channelalign',  1, ...
        'usectfcomp',    1, ...
        'usessp',        1, ...
        'freq',          [], ...
        'baseline',      [], ...
        'blsensortypes', 'EEG');
    % Process: Set channel file
    sFiles = bst_process('CallProcess', 'process_import_channel', sFiles, [], ...
        'channelfile',  {RawFiles{current_length}, 'ASCII_NXYZ'}, ...
        'usedefault',   1, ...  % 
        'channelalign', 1, ...
        'fixunits',     1, ...
        'vox2ras',      1);

    % Process: Phase locking value
    sFiles = bst_process('CallProcess', 'process_plv1n', sFiles, [], ...
    'timewindow',    [0, 15], ...
    'dest_sensors',  'EEG', ...
    'includebad',    1, ...
    'plvmethod',     'plv', ...  % 'plv' %'ciplv' %'wpli'
    'plvmeasure',    2, ...  % Magnitude
    'tfmeasure',     'hilbert', ...  % Hilbert transform
    'tfedit',        struct(...
         'Comment',         'Complex', ...
         'TimeBands',       [], ...
         'Freqs',           {{ 'beta', '13, 29', 'mean'}}, ...
         'ClusterFuncTime', 'none', ...
         'Measure',         'none', ...
         'Output',          'all', ...
         'SaveKernel',      0), ...
    'timeres',       'windowed', ...  % Full (requires epochs)
    'avgwinlength',  1, ...
    'avgwinoverlap', 50, ...
    'outputmode',    'input');  % separately for each file
    num_runs=length(sFiles);
    for run=1:num_runs
        current_folder_name={sFiles(run).FileName};
        current_matrix= in_bst_matrix(current_folder_name{1});
        TF_time_avg=mean(current_matrix.TF,3);
        current_matrix.TF=TF_time_avg;
        R = bst_memory('GetConnectMatrix', current_matrix); % get full matrix
        feature_extraction_plv(R,case_index,num_runs,run);
    end   
end 

Yes, it must be done with two different processes. The idea is that a pipeline is comprised by process elements that can be chained.

The main reference for writing scripts is in:
https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting

  • What are the errors that you are getting?
  • Is there any problem at computing PLV with same parameters in the GUI?

Thanks for the reply...

  • What are the errors that you are getting? After I run the code from the script and go to the GUI to open the graph, I get the following error:
    image

  • Is there any problem at computing PLV with same parameters in the GUI? No, everything runs fine in the GUI, as long as I import the data first, then create another process for PLV

I found the mistake. I had a single rhythm (Beta) in the script, so when I replaced that with (Beta and Alpha), it ran just fine.

The was a bug for the specific case of one frequency band.
This is now solved at commit: 1b19f1d
Update your Brainstorm instance to get the fix.

That avoids the bug, but it is now solved.
It is possible to use only one band.

All good. Thank you very much for the reply.