Assistance Needed for Batch Export of Time-Frequency Processed Data

Dear all,
I am currently working on a project that involves processing a large number of samples using Brainstorm's time-frequency analysis. For each sample, after the time-frequency processing, I need to export the results for five different frequency ranges (delta / 2-4 Hz / mean, theta / 5-7 Hz / mean, alpha / 8-12 Hz / mean, beta / 15-29 Hz / mean, gamma1 / 30-59 Hz / mean).

The problem I am facing is that I have to manually export each .mat file for each frequency range through the GUI. Specifically, the process I follow is:
Files to process: time-freq - run - export - export to files - export - select frequency range(click through each file and frequency manually)

Given the large number of files I am dealing with, the manual processing for each file and frequency range becomes extremely time-consuming and impractical.
I have attempted to include commands in the export script (for instance, freqRange = [8, 12]; % Alpha frequency range), but this method has not yielded the desired results.

sFiles = {};
RawFiles = {};

% Attempt to define frequency range in the script
freqRange = [8, 12]; % Alpha frequency range
% Further commands to process and export

% Start a new report
bst_report('Start', sFiles);

% Process: Export to file: Timefreq
sFiles = bst_process('CallProcess', 'process_export_file', sFiles, [], ...
    'exporttimefreq', {RawFiles{1}, 'ASCII-CSV-HDR'});

% Save and display report
ReportFile = bst_report('Save', sFiles);
bst_report('Open', ReportFile);

Unfortunately, my attempts have not been successful. Therefore, I am reaching out to see if anyone in the community has any suggestions or knows of an alternative method to simplify this process. Ideally, I am looking for a way to batch select the frequency ranges and export the files, rather than having to click through each file and frequency manually.

Any help or advice you could offer would be greatly appreciated. Thank you for your time and assistance.

Thanks a lot,

Hi @yangyanghe,

Thanks for proving us all the details about what you are aiming.

The original TF file has 3 dimensions, while the output (CSV) can only represent 2 dimensions and this why you are asked to select a band if you try to export it directly. Do not worry, it is possible to automat it, but in a slightly different way, this is to say:

  1. Extract the TF for the desired N bands (or frequency) in temporary N files (there are 2D)
  2. Save the temporary TF files as a CVS files
  3. Delete the temporary TF

See this script as adjust to your data:
[Brainstorm] Export frequency bands as CSV files · GitHub

1 Like

Hi Raymundo.Cassani,

Sorry for the delayed reply!

Thanks a lot for your detailed response and guidance! I followed your instructions to extract the TF for the desired bands into temporary files and then saved these temporary TF files as CSV files.

It worked perfectly, and I was able to automate the process as needed:)