Amplitude envelope correlation script in MATLAB

Dear Brainstorm users and developers,

I would highly appreciate your help with the following issue.

Usually, I use Brainstorm GUI to compute Amplitude envelope correlation (AEC), and it worked fine. However, now I have to compute it at the preprocessed files in MATLAB, where signals from several sensors are converted into one via PCA.

It leaves me with the data structure with a shape (1, 300000), where 1 - is the only one "channel" - signal from the particular brain area I am exploring, while 300000 - time points (i.e. 5 minutes).

I want to use the AEC script to compute a correlation between two such files (essentially, two signals from different areas), but I could not use this script in MATLAB - it keeps reporting "Not enough input arguments", even if I use transposed data structures to compute connectivity coefficient.

Could you please tell me, what adjustments should I make in code in order to use the AEC connectivity script in Matlab on such data?

Thank you.

Kind regards,
Oksana.

The function bst_connectivity is not designed to process signals, but files in the database. If you want to use it, you have first to save your signals back into the Brainstorm database in valid data structures. This is not obvious to do...

Since you're fully working outside of Brainstorm, I'd recommend you write your own Matlab script to compute the AEC. You can find some inspiration in the lines 434-477.
If you don't understand what is supposed to be in one of the variables: put a breakpoint at the line you don't understand in bst_connectivity.m, then start the AEC computation from the Brainstorm GUI. When the debugger stops, you can explorer the variables (the Matlab debugger is a fantastic tool, but you might want to watch an introduction tutorial before if you've never used it before).

Dear Francois,

Thank you a lot for your reply. I would love to continue to work with Brainstorm GUI, since it is much more convenient to use. Could you please tell me, what are the criteria of validity of data structures for Brainstorm to process it?

I tried this approach: I replaced F matrix of the original file exported from the Brainstorm to Matlab with my data arrays (so the matrix became 2x300000 instead of 60x300000), I changed the Time parameter accordingly to fit the length of F, I corrected ChannelFlag to take into account I am no longer using 60 channels, but only 2.

And still it did not work - when I imported this file back with all the corrections, I got the same error, but now in Brainstorm - "Not enough input arguments".

What could be possibly missed?

Thank you.

Kind regards,
Oksana.

The number of rows in the F matrix must match the number of elements in the channel file.
You need to edit the channel file as well.
https://neuroimage.usc.edu/brainstorm/Tutorials/ChannelFile#On_the_hard_drive
https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting#File_structures
https://neuroimage.usc.edu/brainstorm/Tutorials/Connectivity#Additional_documentation

Dear Francois,

Thank you for your help!

Kind regards,
Oksana.