<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none"><!-- p { margin-top: 0px; margin-bottom: 0px; }--></style>
</head>
<body dir="ltr">
<div id="OWAFontStyleDivID" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<style type="text/css" style="">
<!--
p
        {margin-top:0px;
        margin-bottom:0px}
-->
</style>
<div id="OWAFontStyleDivID" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<p style="">Hello fieldtrip,<br>
</p>
<p style=""><br>
</p>
<p style="">As mentioned in my previous email, I had success at calculating beamformer with one dataset but not with another.<br>
</p>
<p style=""><br>
</p>
<p style="">The dropbox link to dataset1 is:<br>
</p>
<p style=""><a href="https://www.dropbox.com/s/2nyps8pph7xszf0/Dataset1.mat" id="NoLP">https://www.dropbox.com/s/2nyps8pph7xszf0/Dataset1.mat</a><br>
</p>
<p style=""><br>
</p>
<p style="">The dropbox link to dataset2 is:<br>
</p>
<p style=""><a href="https://www.dropbox.com/s/pkmkdv871y4w67z/Dataset2.mat" id="NoLP">https://www.dropbox.com/s/pkmkdv871y4w67z/Dataset2.mat</a><br>
</p>
<p style=""><br>
</p>
<p style=""><br>
</p>
<div style="">
<p style="">In the datasets are structured in the following way:<br>
</p>
<p style="">datasetx.data<br>
</p>
<p style="">datasetx.timelock<br>
</p>
<p style="">datasetx.vol<br>
</p>
<p style="">datasetx.sourcemodel<br>
</p>
<p style="">datasetx.grid<br>
</p>
<p style="">datasetx.virtualchans<br>
</p>
<p style="">datasetx.sourcemodel2<br>
</p>
<p style=""><br>
</p>
<p style="">source wasnt included as it will make the file too big.<br>
</p>
<p style=""><br>
</p>
<p style="">The following code was used:<br>
</p>
<p style=""><br>
</p>
<p style="">-------------------------------------------------------------<br>
</p>
<div style="">%% timelock data<br>
</div>
<div style="">cfg = [];<br>
</div>
<div style="">cfg.channel = 'EEG'; <br>
</div>
<div style="">cfg.vartrllength = 2; <br>
</div>
<div>cfg.covariance = 'yes';</div>
<div>cfg.covariancewindow = 'all';</div>
<div>cfg.keeptrials = 'yes';</div>
<div style="">timelock = ft_timelockanalysis(cfg, data);<br>
</div>
<p style=""><br>
</p>
<p style=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">-------------------------------------------------------------</span><br>
</p>
<div>%% create headmodel</div>
<div>% segment MRI (return probabilistic tissue maps of gray/white/csf</div>
<div>% compartments</div>
<div>cfg = [];</div>
<div>cfg.write = 'no';</div>
<div>cfg.coordsys = 'spm';</div>
<div>cfg.output = { 'scalp', 'skull', 'brain'};</div>
<div>segmentedmri = ft_volumesegment(cfg, mri);</div>
<div><br>
</div>
<div>cfg = [];</div>
<div>cfg.method = 'iso2mesh';</div>
<div>cfg.numvertices = 10000;</div>
<div>bnd = ft_prepare_mesh( cfg, segmentedmri);</div>
<div><br>
</div>
<div>% fix mesh</div>
<div>[ bnd( 1).pnt, bnd( 1).tri] = meshresample( bnd( 1).pnt, bnd( 1).tri, 1000/size( bnd( 1).pnt, 1));</div>
<div>[ bnd( 2).pnt, bnd( 2).tri] = meshresample( bnd( 2).pnt, bnd( 2).tri, 2000/size( bnd( 2).pnt, 1));</div>
<div>[ bnd( 3).pnt, bnd( 3).tri] = meshresample( bnd( 3).pnt, bnd( 3).tri, 3000/size( bnd( 3).pnt, 1));</div>
<div>for ii = 1:size( bnd),</div>
<div>    [ bnd( ii).pnt, bnd( ii).tri] = meshcheckrepair( bnd( ii).pnt, bnd( ii).tri, 'dup');</div>
<div>    [ bnd( ii).pnt, bnd( ii).tri] = meshcheckrepair( bnd( ii).pnt, bnd( ii).tri, 'isolated');</div>
<div>    [ bnd( ii).pnt, bnd( ii).tri] = meshcheckrepair( bnd( ii).pnt, bnd( ii).tri, 'deep');</div>
<div>    [ bnd( ii).pnt, bnd( ii).tri] = meshcheckrepair( bnd( ii).pnt, bnd( ii).tri, 'meshfix');</div>
<div>end</div>
<div><br>
</div>
<div>% calculate headmodel % reordered to brain skull scalp</div>
<div>cfg = [];</div>
<div>cfg.method = 'bemcp'; %openmeeg doesnt work with multiple output from ft_volumesegment</div>
<div>vol = ft_prepare_headmodel(cfg, bnd);</div>
<div style="">clear bnd<br>
</div>
<div style=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);"><br>
</span></div>
<div style=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">-------------------------------------------------------------</span><br>
</div>
<div style="">
<div style="">%% calculate sourcemodel</div>
<div>cfg = [];</div>
<div>cfg.mri = mri;</div>
<div>cfg.vol = vol;</div>
<div>cfg.grid.warpmni = 'yes';</div>
<div>cfg.grid.template = template.sourcemodel;</div>
<div>cfg.grid.nonlinear = 'yes';</div>
<div>cfg.moveinward = 1; % actually uses vol mesh</div>
<div style="">cfg.inwardshift = 0; % needs to be expressed to work with moveinward</div>
<div style=""><span style="font-size: 12pt;">​cfg.elec = timelock.elec;</span><br>
</div>
<div style="">sourcemodel = ft_prepare_sourcemodel( cfg);<br>
</div>
<br>
</div>
<div style=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">-------------------------------------------------------------</span><br>
</div>
<div style="">%% beamformer calculation<br>
</div>
<div><br>
</div>
<div>% compute lead field</div>
<div>cfg = [];</div>
<div style="">cfg.elec = timelock.elec;<br>
</div>
<div>cfg.vol = vol;</div>
<div>cfg.grid = sourcemodel;</div>
<div>cfg.reducerank = 3; % 3 for EEG, 2 for MEG</div>
<div>cfg.backproject = 'yes';</div>
<div>cfg.normalize = 'yes'; % if you are not contrasting the activity of interest again another condition or baseline time-window</div>
<div>grid = ft_prepare_leadfield( cfg, timelock);</div>
<div><br>
</div>
<div>% Source Analysis: without contrasting condition</div>
<div>cfg = [];</div>
<div>cfg.channel = 'EEG';</div>
<div>cfg.method = 'lcmv';</div>
<div>cfg.grid = grid;</div>
<div>cfg.vol = vol;</div>
<div>cfg.keepfilter = 'yes';</div>
<div>cfg.lcmv.fixedori = 'yes'; % project on axis of most variance using SVD</div>
<div>source = ft_sourceanalysis( cfg, timelock);</div>
<div style=""><br>
</div>
<div style=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">-------------------------------------------------------------</span><br>
<div style="">%% map beamformer source locations onto an anatomical label in an atlas<br>
</div>
<div>cfg = [];</div>
<div>cfg.interpmethod = 'nearest';</div>
<div>cfg.parameter = 'tissue';</div>
<div style="">sourcemodel2 = ft_sourceinterpolate( cfg, atlas, sourcemodel);<br>
</div>
<br>
</div>
<div style=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">-------------------------------------------------------------</span><br>
</div>
<div style="">%% compute virtual channels<br>
</div>
<div>% start building vchan</div>
<div>vchan = [];</div>
<div>label = lower( atlas.tissuelabel);</div>
<div>label = label( 1:90);</div>
<div>vchan.time = data.time;</div>
<div>vchan.fsample = data.fsample;</div>
<div>Ntr = numel( data.trial);</div>
<div>vchan.trial = cell( 1, Ntr);</div>
<div><br>
</div>
<div>% find sensor names and indices</div>
<div>chans = ft_channelselection( 'EEG', data.label);</div>
<div>chans = match_str( data.label, chans);</div>
<div><br>
</div>
<div>count = 1;</div>
<div style=""><span style="font-size: 12pt;">tic</span><br>
</div>
<div style="">for i = 1:numel( label),<br>
</div>
<div>    atlas_sources = find( sourcemodel2.tissue == i);</div>
<div>    ai = ismember( atlas_sources, find( sourcemodel.inside));</div>
<div>    bregion_sources = atlas_sources( ai); clear atlas_sources</div>
<div>    if isempty( bregion_sources), </div>
<div>        continue; </div>
<div style="">    end<br>
</div>
<div>    for f = 1:numel( bregion_sources),</div>
<div>        source_inx = bregion_sources( f);</div>
<div>        dipole_data = cell( 1, Ntr);</div>
<div>        </div>
<div>        % multiply spatial filter (3,Nchan) by the original data</div>
<div>        if isempty( source.avg.filter{ source_inx}), continue; end</div>
<div>        for tr = 1:Ntr,</div>
<div>            dipole_data{ tr} = source.avg.filter{ source_inx} * data.trial{ tr}(chans,:);</div>
<div>        end</div>
<div>        </div>
<div>        % concatenate data, run svd on data, multiple data by the</div>
<div>        % orientation of the dipole in which it is strongest</div>
<div>        time_series = cat( 2, dipole_data{ :});</div>
<div style="">        [ U1, ~, ~] = svd( time_series, 'econ'); % u is the spatial decomposition, v the temporal and s the eigenvalues         along diagonal</div>
<div>        for tr = 1:Ntr,</div>
<div>            %             tt.trial{ tr}( f, :) = U1( :, 1)' * dipole_data{ tr};</div>
<div>            tt.trial{ tr}( f, :) = dipole_data{ tr};</div>
<div>        end</div>
<div>        clear source_inx dipole_data U1 timeseries</div>
<div style="">    end<br>
</div>
<div>    </div>
<div>    % mean channels with brain region</div>
<div>    for tr = 1:Ntr,</div>
<div>        vchan.trial{ tr}( i, :) = mean( tt.trial{ tr});</div>
<div>    end</div>
<div>    </div>
<div>    % include position and power for each source</div>
<div>    vchan.label( count) = label( i);</div>
<div style=""><span style="font-size: 12pt;">    fprintf( 'created virtual channel %d\n', count);</span><br>
</div>
<div>    count = count + 1;</div>
<div>    clear tt U S sv si temp_data bregion_sources bregion_source</div>
<div>end</div>
<div><br>
</div>
<div>cfg = [];</div>
<div style="">vchan = ft_preprocessing( cfg, vchan);<br>
</div>
<p style=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">-------------------------------------------------------------</span>​<br>
</p>
<p style=""><br>
</p>
<p style="">I will greatly appreciate the help once again. As beamformer is the basically the key element of my Phd I really want it to get it working.<br>
</p>
<p style=""><br>
</p>
<p style="">Kind regards,<br>
</p>
<p style=""><br>
</p>
<p style="">Tyler<br>
</p>
<p style=""><br>
</p>
<div name="divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-size:13px">*************************
<div style="font-family:Tahoma"><br>
</div>
<div><font face="Arial"><i>Tyler Grummett ( BBSc, BSc(Hons I))</i></font></div>
<div><font face="Arial"><i>PhD Candidate</i></font></div>
<div><font face="Arial"><i>Brain Signals Laboratory</i></font></div>
<div><font face="Arial"><i>Flinders University</i></font></div>
<div><font face="Arial"><i>Rm 5A301</i></font></div>
<div><font face="Arial"><i>Ext 66124</i></font></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>