[FieldTrip] MATLAB crashes during ft_sourceanalysis

Schoffelen, J.M. (Jan Mathijs) janmathijs.schoffelen at donders.ru.nl
Thu Aug 4 20:18:43 CEST 2022

Hi Kirandeep,

Is there a relationship between whether or not the job crashes, and the exact length of the data (I assume a ‘resting state’) recording? If so, you might be suffering from an out-of-memory problem, which for some reason is not well handled (by means of an informative error) by matlab. If it is indeed a memory problem, a cheap answer would be: run your  jobs on a computer that has a larger RAM.

Alternatively (and more constructively), you may consider to specify cfg.projectmom = ’no’; prior to ft_sourceanalysis. I would assume that - given that you also specify cfg.kurtosis = ‘yes’ - the source projected sensor data are not really needed in memory for downstream processing. The fact that you specified projectmom to be yes, will lead to the creation of a lot of data, i.e. 500 Hz * 720 seconds * 15000 dipoles * 8 bytes per sample = 4.32e10 bytes ~ 40 GB, which is quite a lot.

Best wishes,

On 28 Jul 2022, at 16:25, Kirandeep Kaur via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:

Dear all, this is a query regarding implementation of LCMV beamformer.

I am using ft_sourceanalysis to compute the beamformer  virtual channels and kurtosis for data collected from Elekta Neuromag 306 channels MEG scanner. However, while scanning the grid (typically ranging from 12,000 - 15,000 points), my MATLAB (R2021a) simply shuts down without any error. This also typically happens after the function has scanned >11,000 grid points.

This problem is occurring for roughly 40% of my subjects. The sampling rate is downsampled to 500Hz, and the duration of continuous MEG record for which I am computing the beamformer is typically 10-12 minutes. I am using the reconstructed MRI from Freesurfer (orig.magz) for constructing the head model. A snapshot of the code I am using is given here :


%% compute leadfield
cfg = [];
cfg.channel = 'MEG';
cfg.headmodel = headmodel;
cfg.sourcemodel = sourcemodel;
cfg.normalize = 'yes'; % normalisation avoids power bias towards centre of head
cfg.reducerank = 2;
leadfield = ft_prepare_leadfield(cfg, cov_matrix);

save ('leadfield');

%% %plot svd of covariance matrix

[u,s,v] = svd(cov_matrix.cov);

savefig (gcf, 'svd_covariance.fig', 'compact');
close all
%% compute the LCMV beamformer

cfg = [];
cfg.method = 'lcmv';
cfg.sourcemodel = leadfield;
cfg.headmodel = headmodel;
cfg.lcmv.keepfilter = 'yes';
cfg.lcmv.fixedori = 'yes'; % project on axis of max variance using SVD
cfg.lcmv.lambda = '5%';
cfg.lcmv.kappa = 69;
cfg.lcmv.projectmom = 'yes'; % project dipole time series in direction of maximal power
cfg.lcmv.kurtosis = 'yes';
cfg.lcmv.keepmom = 'yes';
source = ft_sourceanalysis(cfg, cov_matrix);

save ('source');


Any help regarding this would be very useful since I am not able to find a solution to this problem.

Kind regards,

Kirandeep Kaur,
Research Fellow, Aston University,
Birmingham, UK
fieldtrip mailing list

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20220804/d71ce135/attachment.htm>

More information about the fieldtrip mailing list