I am trying to select a uniform number of trials from each condition prior to a time-frequency transform (morlet). I've been adding two conditions for a single subject (each with a different total number of trials). I then use the File > "select uniform number of trials" process and then add my time-frequency process, with the option to save the average TF transforms. This ALWAYS produces a single average across the two conditions instead of an average for each condition using the uniform number of trials. Can anyone advise me about what I might be doing wrong?
I should mention that this same procedure using time-domain averaging instead of the time-frequency transform works EXACTLY as expected, selecting the maximum uniform number of trials between the two conditions and creating an average for each.
The online averager embedded in the time-frequency process allows to compute averages of TF maps on the fly, but does not include all the features of the process "Average > Average files". In particular, it does not offer the option to sort the files by trial groups or folders: everything in input will be averaged together, as you noticed.
For producing two averages with the processes in the "Frequency" category, you need to call the process twice. Depending on how your data is organized, it might not be easy to do with the interface, and you might have to write a script for handling your file selection.
To get started with scripting with Brainstorm:
Thanks for the quick response. I did manage to borrow some code from the Average files process and create a modified version of the process_timefreq.m file that allows for the grouping features I want. I originally named the file "process_timefreq_pk.m" and I got a strange "context" error when I tried to run it. It works if I keep the original process_timefreq.m filename and store the file in my own personal process directory, but then the original process no longer shows up in the usual place in the drop-down menus. I wasn't successful at tracing back the source of the error. Any ideas would be appreciated.
I figured out the problem with re-naming the process_timefreq function. When it calls panel_timefreq_options.m, Line 84 of that panel function uses the name of the calling function to determine the value of method. It looks like it is just making sure that the calling function has 'timefreq' in its name. I changed line 84 as shown below, which allows me to use my own filename for the modified process_timefreq function so that the original brainstorm menu options remain intact......just in case anyone is interested in doing the same.
%Method = strrep(strrep(func2str(sProcess.Function), 'process_', ''), 'timefreq', 'morlet');
if endsWith(func2str(sProcess.Function),'timefreq'); Method = 'morlet'; end
For anyone who's interested, I've attached the modified process_timefreq file, which requires the change to line 84 of panel_timefreq_options.m. No need to alter panel_timefeq_options.m you rename my file (and the main function name) to process_timefreq.m.process_cpl_timefreq.m (21.7 KB)
Thanks for sharing.
If you are interested, you can share your processes and document them on this github repository:
Be aware that process_timefreq.m changes regularly, and it will be difficult for you to keep on keeping up with these changes if you work with a modified version.
A solution based on a Matlab script that groups the input files and then calls process_timefreq.m for each group separately would be easier to maintain and adapt in the future.