<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000">Hi <span class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(0,0,0)"></span>Jan-Mathijs,</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000">Thank you for your replay. I tried to describe the problem as clear as possible, but it seems I ended omitting information in the process. Here is all my code so far. I still can't find what i'm doing wrong.</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000">My data is a preprocessed continuous eeg recording. <br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><span style="color:rgb(106,168,79)">% prepare layout</span><br> cfg = [];<br><span style="color:rgb(106,168,79)">%I have to rotate the axis layout </span><br> aux_elec = chanloc.elec;<br> aux_elec.pnt(:,1) = -chanloc.elec.pnt(:,2);<br> aux_elec.pnt(:,2) = chanloc.elec.pnt(:,1);<br><span style="color:rgb(106,168,79)">%update direction</span><br> chanloc.elec.pnt = aux_elec.pnt;<br><span style="color:rgb(106,168,79)">%layout for plotting</span><br> cfg.elec = chanloc.elec;<br> layout = ft_prepare_layout(cfg);</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><span style="color:rgb(106,168,79)">% subdivide into trials of 1 seconds 10% overlap</span><br> cfg = [];<br><span style="color:rgb(106,168,79)">% single number (in unit of time, typically seconds) of the required snippets</span><br> cfg.length = 1;<br><span style="color:rgb(106,168,79)">% single number (between 0 and 1 (exclusive)) specifying the fraction of overlap between snippets (0 = no overlap)</span><br> cfg.overlap = 0.1;<br><span style="color:rgb(106,168,79)">%cut</span><br> data = ft_redefinetrial(cfg, data); </div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><span style="color:rgb(106,168,79)">%% calculate cross-spectrum</span><br> cfg = [];<br> cfg.method = 'mtmfft';<br> cfg.taper = 'hanning';</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><span style="color:rgb(106,168,79)">%For connectivity analysis we need power and phase -> 'fourier'</span><br> cfg.output = 'fourier';<br> cfg.keeptrials = 'yes';<br><span style="color:rgb(106,168,79)">%frequency of interest foilim at 10 Hz +/- 1 Hz</span><br> cfg.foi = 10;<br> cfg.tapsmofrq = 1;<br><span style="color:rgb(147,196,125)">%frequency analysis</span><br> freq1 = ft_freqanalysis(cfg, data);</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><span style="color:rgb(56,118,29)"><br></span></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><span style="color:rgb(56,118,29)">%% Calculate source model<br></span></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"> [headmodel sourcemodel] = read_custom_head_source_model(freq1); <span style="color:rgb(106,168,79)"><span style="color:rgb(56,118,29)"><b>%function at the end of the email</b></span><br></span></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><span style="color:rgb(56,118,29)">%% do the source reconstruction</span><br> cfg = [];<br> cfg.frequency = freq1.freq;<br> cfg.method = 'pcc'; % Dynamic Imaging of Coherent Sources <br> cfg.headmodel = headmodel;<br> cfg.grid = sourcemodel; % Our grid and the leadfield<br> cfg.pcc.projectnoise = 'yes'; % estimate noise<br> cfg.pcc.lambda = '10%'; % how to regularise<br> cfg.pcc.keepfilter = 'yes'; % keep the spatial filter in the output<br> cfg.pcc.realfilter = 'yes'; % retain the real values<br> cfg.keeptrials = 'yes';<br> cfg.senstype = 'eeg';<br><br> SourceData = ft_sourceanalysis(cfg, freq1);<br> [SourceData] = ft_sourcedescriptives([], SourceData);</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><span style="color:rgb(56,118,29)"><b> %% connectivity (this is the code I posted before)</b></span><br> cfg = [];<br> cfg.method = 'coh';<br> cfg.complex = 'absimag';<br> source_conn = ft_connectivityanalysis(cfg, SourceData);<br> <br><span style="color:rgb(106,168,79)"> %The conectome</span><br> figure;imagesc(source_conn.cohspctrm);<br> <br> <span style="color:rgb(106,168,79)">%Parcellation</span><br> atlas = ft_read_atlas('/fieldtrip-master/template/atlas/aal/ROI_MNI_V4.nii');<br> <br> cfg = [];<br> cfg.interpmethod='nearest';<br> cfg.parameter='tissue';<br> [int_atlas] = ft_sourceinterpolate(cfg, atlas, source_conn);<br> int_atlas.pos = source_conn.pos; % otherwise the parcellation won't work<br> <br> % and call ft_sourceparcellate:<br> cfg = [];<br> cfg.parcellation = 'tissue';<br> cfg.parameter = 'cohspctrm';<br> parc_conn = ft_sourceparcellate(cfg, source_conn, int_atlas);<br><br> figure;imagesc(parc_conn.cohspctrm);</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000">+++ continue code<br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><span style="color:rgb(11,83,148)">function</span> [hdm lf] = read_custom_head_source_model(data)</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><span style="color:rgb(147,196,125)">%% read labels and search positions in template</span><br> elec = ft_read_sens('standard_1020.elc');<br><span style="color:rgb(106,168,79)"> % Change unit for visivility</span><br> data.elec.unit = 'mm';<br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"> for labelindex = 1:length(data.label)<br><span style="color:rgb(106,168,79)"> %position of my electrodes in the template standard_1020</span><br> Index = find(strcmpi(elec.label, data.label{labelindex}));<br> <br><span style="color:rgb(106,168,79)"> %writing the real position of the electrodes in my data</span><br> data.elec.chanpos(labelindex,:) = elec.chanpos(Index,:);<br> data.elec.elecpos(labelindex,:) = elec.elecpos(Index,:); <br> end<br> <br><span style="color:rgb(106,168,79)">% Load template head model</span><br> load('/fieldtrip-master/template/headmodel/symetric_headmodel.mat')<br> headmodel = ft_convert_units(headmodel, data.elec.unit);<br> </div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><span style="color:rgb(106,168,79)">%% compute the leadfield</span><br> cfg = [];<br> cfg.elec = data.elec;<br> cfg.elec.unit = 'mm'; <br> cfg.headmodel = headmodel;<br> cfg.grid.resolution = 20; % use a 3-D grid with a 20 mm resolution<br> [lf] = ft_prepare_leadfield(cfg);<br><span style="color:rgb(11,83,148)">end</span></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:#000000"><div>I attached a figure how the source nai index looks in a sourceplot. Thanks for your help.</div><div><br></div><div>All the best,</div><div>Christian<br></div></div></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr"><br></div><div dir="ltr" class="gmail_attr"></div><div dir="ltr" class="gmail_attr">El mar., 21 may. 2019 a las 15:44, Schoffelen, J.M. (Jan Mathijs) (<<a href="mailto:jan.schoffelen@donders.ru.nl" target="_blank">jan.schoffelen@donders.ru.nl</a>>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
Hi Christian,
<div><br>
<div>I guess you need to figure out why the dimension of the coherence matrix does not match the expectations.</div>
<div>Based on the information you provide (i.e. the lack thereof: it’s not clear how you compute SourceData, and how you spectrally transformed your sensor data that goes into the source reconstruction step) there is lottle to go on.</div>
<div><br>
</div>
<div>Best wishes,</div>
<div><span class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(0,0,0)"></span>Jan-Mathijs</div>
<div><br>
</div>
<div><br>
</div>
<div> <br>
<div>
<blockquote type="cite">
<div>On 21 May 2019, at 19:27, Christian Mista <<a href="mailto:cmista@ingenieria.uner.edu.ar" target="_blank">cmista@ingenieria.uner.edu.ar</a>> wrote:</div>
<br class="m_3586701746260788978gmail-m_53341994689760994Apple-interchange-newline">
<div>
<div dir="ltr">
<div style="font-family:tahoma,sans-serif;font-size:small">
<div style="font-family:tahoma,sans-serif;font-size:small">
Hi FieldTrip community,</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
<br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
I've been trying to perform a connectivity analysis using a 66 eeg recording database. So far, I've being able to solve the sourceanalysis (following the tutorial
<a href="http://www.fieldtriptoolbox.org/tutorial/networkanalysis/" target="_blank">
http://www.fieldtriptoolbox.org/tutorial/networkanalysis/</a>) and plot the source activity. However, the problem starts when I'm trying the connectivity analysis. Any grid dimension lower than 20 mm in the sourcemodel calculation results in a matlab error
(Out of memory) in the connectivity analysis. I guess that a grid dimension lower than 20 mm conveys to huge matrix sizes, not manageable by my OS (linux + Matlab).
<br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
<br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
%% This is how I compute the sourcemodel (run ok)<br>
cfg = [];<br>
cfg.elec = data.elec;<br>
cfg.elec.unit = 'mm'; % unit in cm<br>
cfg.headmodel = headmodel;<br>
cfg.grid.resolution = 20; % use a 3-D grid with a 20 mm resolution<br>
[lf] = ft_prepare_leadfield(cfg);</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
<br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
<br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
After computing the sourcemodel using the 20 mm grid, I have issues to parcellate my data. My main concern is about the mismatch size between the connectivity matrix and the atlas.
<br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
<br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
source_conn =<br>
dim: [7 9 8]<br>
inside: [504×1 logical]<br>
pos: [504×3 double]<br>
cohspctrm: [5544×5544 double]<br>
dimord: 'pos_pos_freq'<br>
freq: 10<br>
cfg: [1×1 struct]</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
<br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
<br>
atlas = <br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
dim: [91 109 91]<br>
hdr: [1×1 struct]<br>
transform: [4×4 double]<br>
unit: 'mm'<br>
tissue: [91×109×91 double]<br>
tissuelabel: {1×116 cell}<br>
coordsys: 'mni'</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
<br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
I'd tried to interpolate and parcellate the matrix, but I must be missing or confusing something... Below is the code to calculate the connectivity and the parcellation.
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
<br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
%% connectivity<br>
cfg = [];<br>
cfg.method = 'coh';<br>
cfg.complex = 'absimag';<br>
source_conn = ft_connectivityanalysis(cfg, SourceData);<br>
<br>
%The conectome<br>
figure;imagesc(source_conn.cohspctrm); %5544x5544 double<br>
<br>
%Parcellation<br>
atlas = ft_read_atlas('/fieldtrip-master/template/atlas/aal/ROI_MNI_V4.nii');<br>
<br>
cfg = [];<br>
cfg.interpmethod='nearest';<br>
cfg.parameter='tissue';<br>
[int_atlas] = ft_sourceinterpolate(cfg, atlas, source_conn);<br>
int_atlas.pos = source_conn.pos; % otherwise the parcellation won't work<br>
<br>
% and call ft_sourceparcellate:<br>
cfg = [];<br>
cfg.parcellation = 'tissue';<br>
cfg.parameter = 'cohspctrm';<br>
parc_conn = ft_sourceparcellate(cfg, source_conn, int_atlas);<br>
<br>
figure;imagesc(parc_conn.cohspctrm);<br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
<br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
++Error in command windows matlab <br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
<br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
there are in total 504 positions, 230 positions are inside the brain, 181 positions have a label<br>
168 of the positions inside the brain have a label<br>
168 of the labeled positions are inside the brain<br>
62 of the positions inside the brain do not have a label<span style="color:rgb(255,0,0)"><span style="background-color:rgb(255,0,0)"><br>
<span style="background-color:rgb(255,255,255)">Error using ft_notification (line 340)<br>
unsupported dimord unknown_unknown_freq<br>
<br>
Error in ft_error (line 39)<br>
ft_notification(varargin{:});<br>
<br>
Error in ft_sourceparcellate (line 309)<br>
ft_error('unsupported dimord %s', dimord{i})</span></span></span></div>
<div style="font-family:tahoma,sans-serif;font-size:small">
<br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
Two questions <br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
-Is 20 mm the min grid size to calculate connectivity?</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
-What I'm missing in the parcellation process?</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
<br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
I would really appreciate any advice, I've been scratching my head for a while on this one.</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
<br>
</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
Best,</div>
<div style="font-family:tahoma,sans-serif;font-size:small">
Christian </div>
</div>
</div>
_______________________________________________<br>
fieldtrip mailing list<br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
<a href="https://doi.org/10.1371/journal.pcbi.1002202" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a><br>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
_______________________________________________<br>
fieldtrip mailing list<br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
<a href="https://doi.org/10.1371/journal.pcbi.1002202" rel="noreferrer" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a><br>
</blockquote></div></div>