<div dir="ltr">Dear all, this is a query regarding implementation of LCMV beamformer. <div><br></div><div>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. </div><div><br></div><div>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 : </div><div><br></div><div>----------------------------------------------------------------------</div><div><br></div><div>





<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(2,128,9)">%% compute leadfield<span class="gmail-Apple-converted-space"> </span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">cfg = [];</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">cfg.channel = <span class="gmail-s1" style="color:rgb(170,4,249)">'MEG'</span>;</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">cfg.headmodel = headmodel;</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">cfg.sourcemodel = sourcemodel;</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(2,128,9)"><span class="gmail-s2" style="color:rgb(0,0,0)">cfg.normalize = </span><span class="gmail-s1" style="color:rgb(170,4,249)">'yes'</span><span class="gmail-s2" style="color:rgb(0,0,0)">; </span>% normalisation avoids power bias towards centre of head</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">cfg.reducerank = 2;</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">leadfield = ft_prepare_leadfield(cfg, cov_matrix);</p>
<p class="gmail-p3" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;min-height:12px"><span class="gmail-Apple-converted-space"> </span></p>
<p class="gmail-p4" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(170,4,249)"><span class="gmail-s2" style="color:rgb(0,0,0)">save (</span>'leadfield'<span class="gmail-s2" style="color:rgb(0,0,0)">);<span class="gmail-Apple-converted-space"> </span></span></p>
<p class="gmail-p3" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;min-height:12px"><span class="gmail-Apple-converted-space"> </span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(2,128,9)">%% %plot svd of covariance matrix<span class="gmail-Apple-converted-space"> </span></p>
<p class="gmail-p5" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(2,128,9);min-height:12px"><span class="gmail-Apple-converted-space"> </span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">[u,s,v] = svd(cov_matrix.cov);</p>
<p class="gmail-p3" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;min-height:12px"><span class="gmail-Apple-converted-space"> </span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">figure;</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">semilogy(diag(s),<span class="gmail-s1" style="color:rgb(170,4,249)">'o-'</span>);</p>
<p class="gmail-p4" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(170,4,249)"><span class="gmail-s2" style="color:rgb(0,0,0)">savefig (gcf, </span>'svd_covariance.fig'<span class="gmail-s2" style="color:rgb(0,0,0)">, </span>'compact'<span class="gmail-s2" style="color:rgb(0,0,0)">); <span class="gmail-Apple-converted-space"> </span></span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">close <span class="gmail-s1" style="color:rgb(170,4,249)">all</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(2,128,9)">%% compute the LCMV beamformer<span class="gmail-Apple-converted-space"> </span></p>
<p class="gmail-p5" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(2,128,9);min-height:12px"><span class="gmail-Apple-converted-space"> </span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">cfg = [];</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">cfg.method = <span class="gmail-s1" style="color:rgb(170,4,249)">'lcmv'</span>;</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">cfg.sourcemodel = leadfield;</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">cfg.headmodel = headmodel;</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">cfg.lcmv.keepfilter = <span class="gmail-s1" style="color:rgb(170,4,249)">'yes'</span>;</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(2,128,9)"><span class="gmail-s2" style="color:rgb(0,0,0)">cfg.lcmv.fixedori = </span><span class="gmail-s1" style="color:rgb(170,4,249)">'yes'</span><span class="gmail-s2" style="color:rgb(0,0,0)">; </span>% project on axis of max variance using SVD</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">cfg.lcmv.lambda = <span class="gmail-s1" style="color:rgb(170,4,249)">'5%'</span>;</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">cfg.lcmv.kappa = 69;</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(2,128,9)"><span class="gmail-s2" style="color:rgb(0,0,0)">cfg.lcmv.projectmom = </span><span class="gmail-s1" style="color:rgb(170,4,249)">'yes'</span><span class="gmail-s2" style="color:rgb(0,0,0)">; </span>% project dipole time series in direction of maximal power<span class="gmail-Apple-converted-space"> </span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">cfg.lcmv.kurtosis = <span class="gmail-s1" style="color:rgb(170,4,249)">'yes'</span>;</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">cfg.lcmv.keepmom = <span class="gmail-s1" style="color:rgb(170,4,249)">'yes'</span>;</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">source = ft_sourceanalysis(cfg, cov_matrix);</p>
<p class="gmail-p3" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;min-height:12px"><span class="gmail-Apple-converted-space"> </span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">save (<span class="gmail-s1" style="color:rgb(170,4,249)">'source'</span>);<span class="gmail-Apple-converted-space"> </span></p><p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier"><span class="gmail-Apple-converted-space"><br></span></p><p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier"><span class="gmail-Apple-converted-space">-------------------------------------------------------</span></p><p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier"><span class="gmail-Apple-converted-space"><br></span></p><p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier"><span class="gmail-Apple-converted-space"><br></span></p><p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier"><span class="gmail-Apple-converted-space" style=""><br></span></p><p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><span class="gmail-Apple-converted-space" style=""><font face="arial, sans-serif" style="">Any help regarding this would be very useful since I am not able to find a solution to this problem. </font></span></p><p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><span class="gmail-Apple-converted-space" style=""><font face="arial, sans-serif" style=""><br></font></span></p><p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><span class="gmail-Apple-converted-space" style=""><font face="arial, sans-serif" style="">Kind regards, </font></span></p><p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><span class="gmail-Apple-converted-space" style=""><font face="arial, sans-serif" style=""><br></font></span></p><p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><span class="gmail-Apple-converted-space" style=""><font face="arial, sans-serif" style="">Kirandeep Kaur, </font></span></p><p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><span class="gmail-Apple-converted-space" style=""><font face="arial, sans-serif" style="">Research Fellow, Aston University, </font></span></p><p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><span class="gmail-Apple-converted-space" style=""><font face="arial, sans-serif" style="">Birmingham, UK</font></span></p></div></div>