<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
 Hi Alex,
<div class=""><br class="">
</div>
<div class="">The first thing I would check, is whether the metric units of the sourcemodel/grad are as implicitly expected by you. The cfg.resolution argument before calling ft_prepare_sourcemodel is interpreted by ‘FieldTrip’ in the metric units that the
 primary geometric object is expressed in. I don’t know by heart which one of the geometric objects (in this case headmodel and grad) is primary in determing this (you need to read the code for that), but things might become strange if it actually is the grad,
 and if the grad is expressed in ‘m’. Because this would result in a 3D-grid with a 1 meter spacing between dipoles.</div>
<div class=""><br class="">
</div>
<div class="">Best wishes,</div>
<div class="">Jan-Mathijs</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 14 May 2024, at 17:15, Alex Williams via fieldtrip <<a href="mailto:fieldtrip@science.ru.nl" class="">fieldtrip@science.ru.nl</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">Hello there FieldTrip Community,
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">  I'm Alex Williams, a neuroengineering graduate student at Florida Institute of Technology. I'm relatively new to source reconstruction methods and was wondering if there may be any pointers or advice that may help guide me through the tutorials
 and documentation. I've been trying to resolve an issue with the beamformer for some time. Currently, I'm using an LCMV beamformer to source fit participant MEG data and compare those results to source results that were obtained in SPM12.  Though I'm trying
 to create a pipeline for analyzing this data set, the results I've obtained seem to have discrepancies in source variance and virtual channel signal alongside having warped sourceplots when plotting source variance.  The meeg data, D, I'm using has been converted
 from SPM to fieldtrip using the function. spm2fieldtrip(). The converted data itself has been defined, and has undergone pre-processing and time-locking in SPM. </div>
<div class=""><br class="">
</div>
<div class="">Steps I used: </div>
<div class=""><br class="">
</div>
<div class="">1. The converted meeg data, D, I'm using has been converted from SPM to fieldtrip using the function. spm2fieldtrip(). The converted data itself has been defined, and has undergone pre-processing and epoching in SPM. Since I wasn't able to find
 the covariance matrix within the D structure I was using, I applied a time-lock analysis to the D structure I had and used only the covariance matrix from those results as the cfg.cov parameter within the D matrix pre-time lock.</div>
<div class=""><br class="">
</div>
<div class="">2. ft_read_mri() used a .nifti MRI file and an empty configuration. Fiducials were taken and used in the configuration to realign the MRI using ft_volumerealign() with cfg.coordsys='neuromag'. After, segmentation was done using ft_volumesegment(),
 again with an empty configuration.</div>
<div class=""><br class="">
</div>
<div class="">3. Headmodel computed using following parameters:</div>
<div class="">
<div style="padding:30px" class="">
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg = [];</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.method = <span style="color:rgb(167,9,245)" class="">
'singleshell'</span>;</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.siunits = <span style="color:rgb(167,9,245)" class="">
'yes'</span>;</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.feedback = <span style="color:rgb(167,9,245)" class="">
'yes'</span>;</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">headmodel = ft_prepare_headmodel(cfg, seg);</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">headmodel = ft_convert_units(headmodel,
<span style="color:rgb(167,9,245)" class="">'mm'</span>); </span></div>
</div>
</div>
<div class=""><br class="">
</div>
<div class="">3. Gradiometer array was defined with ft_read_sens using the path of the meeg file. These were the parameters of the source model. </div>
<div class=""><br class="">
</div>
<div class="">
<div style="padding:30px" class="">
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg = [];</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.grad = grad;</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.headmodel = headmodel;</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.resolution = 1; </span>
</div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.inwardshift = 0; </span>
</div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">sourcemodel = ft_prepare_sourcemodel(cfg);</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<br class="">
</div>
</div>
</div>
<div class="">
<div class="">Plotting leads to this segmented mri figure (segmented mri) and headmodel-sensor model (headmodel, sourcemodel mesh and sensor array)</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<span id="cid:ii_lw4bp42b1"><image.png></span></div>
<div class=""><br class="">
</div>
<div class=""><span id="cid:ii_lw4bs7iv2"><Screenshot 2024-05-12 at 10.08.53 PM.png></span><br class="">
<div class="">4. After the forward model was run with prepare_leadmatrix () with following parameters:<br class="">
</div>
<div class="">
<div style="padding:30px" class="">
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg = [];</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.grad = grad; </span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.headmodel = headmodel;
</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.sourcemodel = sourcemodel;</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.channel = {<span style="color:rgb(167,9,245)" class="">'MEG'</span>};</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.singleshell.batchsize = 2000;</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">lf = ft_prepare_leadfield(cfg,D);</span></div>
</div>
</div>
<div class="">5. And then the source model was run using an LCMV beamformer:</div>
<div class="">
<div style="padding:30px" class="">
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<div style="padding:30px" class="">
<div class=""><span style="white-space-collapse: preserve;" class=""><span style="color:rgb(14,0,255)" class="">if
</span>isfield(D,<span style="color:rgb(167,9,245)" class="">'cov'</span>)</span></div>
<div class=""><span style="white-space-collapse: preserve;" class="">[~, sr, ~]=svd(D.cov);</span></div>
<div class=""><span style="white-space-collapse: preserve;" class="">clif=-diff(log10(diag(sr)));</span></div>
<div class=""><span style="white-space-collapse: preserve;" class="">kappa=find(clif==max(clif));</span></div>
<div class=""><span style="white-space-collapse: preserve;" class=""><span style="color:rgb(14,0,255)" class="">end</span></span></div>
</div>
</div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg = [];</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.method = <span style="color:rgb(167,9,245)" class="">
'lcmv'</span>;</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.headmodel = headmodel;
<span style="color:rgb(0,128,19)" class="">% volume conduction model (headmodel)</span></span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.sourcemodel = lf; <span style="color:rgb(0,128,19)" class="">
% leadfield</span></span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.lcmv.keepfilter = <span style="color:rgb(167,9,245)" class="">
'yes'</span>;</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.grad=D.grad;</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.keepleadfield = <span style="color:rgb(167,9,245)" class="">
'yes'</span>;</span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
<span style="white-space-collapse: preserve;" class="">cfg.lcmv.fixedori = <span style="color:rgb(167,9,245)" class="">
'yes'</span>; <span style="color:rgb(0,128,19)" class="">% project on axis of most variance using SVD</span></span></div>
<div style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace" class="">
cfg.lcmv.kappa.      =kappa<span style="white-space-collapse: preserve;" class="">;</span></div>
</div>
</div>
<div class="">Which returns a source structure that seems to produce warped source variance plots and blown-up source variance values after iusing source interpolation using:                 <span style="font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px" class="">ft_sourceinterpolate(cfg,
 source, segmentedmri): </span></div>
<div class=""><span style="font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px" class=""><br class="">
</span></div>
<div class=""><span id="cid:ii_lw4csqcw3"><Screenshot 2024-05-12 at 10.37.15 PM.png></span><br class="">
</div>
<div class=""><br class="">
</div>
<span id="cid:ii_lw4d8ujl4"><Screenshot 2024-05-12 at 10.49.16 PM.png></span><br class="">
<div class="">I'm currently trying different parameters within the beamformer including using different weight normalization parameters to compensate for possible depth bias alongside using different lambda values. However, based on the final source plots,
 I wasn't too sure if there may have also been an issue with the coregistration of the mri or perhaps with the final source model. <font color="#888888" class=""><br class="">
</font></div>
<font color="#888888" class="">
<div class=""><br class="">
</div>
<div class="">-Alex Williams</div>
</font></div>
</div>
_______________________________________________<br class="">
fieldtrip mailing list<br class="">
<a href="https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmailman.science.ru.nl%2Fmailman%2Flistinfo%2Ffieldtrip&data=05%7C02%7Cfieldtrip%40science.ru.nl%7C723d34ec28124c47add008dc76477258%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638515296429761701%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=j%2BqJFlpxJ08UEYDuPmuvguUyb1pyytDI5ZLwB5oghbI%3D&reserved=0" originalsrc="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" shash="ojS3XUtXXkSRWlcxPMfFovGLt9wUDgFyRH8wVb8/7Wkx1JOwl0cwiHvswQCK8/XwET00IazEsJ46qGmCn1LyAVSwfzyty9376smQnrH2K14DPQn3Q6x4Gcdwgsc4V6VM2g8DVUmU88vAiz4lKvwwNrdZVTiNVJiD68zszfZOOFQ=" class="">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br class="">
https://doi.org/10.1371/journal.pcbi.1002202<br class="">
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>