then I want to concatenate ‘psds’ of all subjects and compute the average of psd between 5-30 Hz to visualize them, for example, with following plot at the end.
However, the output “psds” have different shape depending on the data because of the different number of frequencies. For instance, when computing FFT between 5 and 30 Hz, psds is sometimes (n_channels, 3200) or (n_channels, 3010).
I’m looking for a solution to this problem so that psds of each subject can be concatenated without getting lag of frequency power across subjects…
I’d like to know whether there’s a good way to deal with that.
Thank you in advance!
the reason you get a different number of frequency bins is that the multitaper method computes frequency bin values based on the length of the signal. To avoid this you could truncate all signals to the same length before estimating spectral power (if that is a reasonable thing to do, given your data / analysis).
As @mscheltienne says, for band power you can aggregate across bins even if the bin spacing is not identical for all files / subjects. When you’re dealing with 3000+ bins, I wouldn’t expect it to make much difference.