# [FieldTrip] Estimate coherence between conditions?

Maité Crespo García maity_winky at yahoo.es
Mon Jul 10 19:41:39 CEST 2017

```Dear Maria,
you are right, the data from condition 2 should be contained in the channels cross-spectral-density matrix (Cf). If you would do it with the option 'dics_refchan', you could have the same situation as in the tutorial, but substituting the EMG signal by the source time-course. However, I understand you would prefer to use the option 'dics_refdip'; I am not sure whether it is programmed for your particular situation because the function uses only one Cf in this case. "Maybe" it works by providing the Cf including data from both conditions. But then, the dimension of the filters have to match this new Cf to fulfill the equation:

csd = filt1 * Cf * ctranspose(filt2); (function beamformer_dics, line 562)
And "maybe" you can extend the filters, setting to 0 the filters corresponding to the channels of the opposite condition. But here, you should get advice from somebody who knows the mathematics; I am just speculating, sorry.
Best,Maité

El Lunes 10 de julio de 2017 14:56, Maria Hakonen <maria.hakonen at gmail.com> escribió:

Hi Maité,
I have nowtried to get coherence between two conditions following the Appendix 1 (I have alsoused the same data as in Appendix 1; http://www.fieldtriptoolbox.org/tutorial/coherence).
As far as Iunderstand, I should first calculate ft_freqanalysis and ft_sourceanalysis separatelyfor condition 1 and condition 2 as follows:
Condition1:Compute thecross-spectral density matrix for 18 Hz:cfg            = [];cfg.method     = 'mtmfft';cfg.output     = 'powandcsd';cfg.foilim     = [18 18];cfg.tapsmofrq  = 5;cfg.keeptrials = 'yes';freq1           = ft_freqanalysis(cfg, data); TheAppendix 1 also defines:cfg.channelcmb= {'MEG' 'MEG';'MEG' 'EMGlft'};However, Ithink that in my case channelcmb is not needed since default = {'all' 'all'}.
Thereafter,I used ft_sourceanalysis as follows:cfg                 = [];cfg.method          = 'dics';cfg.frequency       = 18;cfg.hdmfile         = 'SubjectCMC.hdm';cfg.inwardshift     = 1;cfg.grid.resolution = 1;cfg.grid.unit       = 'cm';source1              = ft_sourceanalysis(cfg, freq); (The Appendix1 also defines: cfg.refchan         = 'EMGlft';)
Condition2:Icalculated cross-spectral density exactly in the same way as in condition 1 butused data from condition 2.
In ft_sourceanalysis, I set keepfilterand keepleadfiled as “yes”:cfg                 = [];cfg.method          = 'dics';cfg.frequency       = 18;cfg.hdmfile         = 'SubjectCMC.hdm';cfg.inwardshift     = 1;cfg.grid.resolution = 1;cfg.grid.unit       = 'cm';cfg.keepfilter = ‘yes’;  cfg.keepleadfield = ‘yes’;source2              = ft_sourceanalysis(cfg, freq2); Thereafter, I selected a source thatin inside the brain from source2 and included it’s position, leadfield andfilter in refdip:refdip =            pos: [5 -5 -1]   leadfield: {[151x3 double]}       filetr: [3x151 double] After this,I run ft_sourceanalysis:cfg                 = [];cfg.method          = 'dics';cfg.frequency       = 18;cfg.hdmfile         = 'SubjectCMC.hdm';cfg.inwardshift     = 1;cfg.grid.resolution = 1;cfg.grid.unit       = 'cm';cfg.refdip = refdip;source              = ft_sourceanalysis(cfg, freq1); Here, I used cross spectral densitymatrix computed from condition 1 (i.e. freq1). I am not sure, whether I should alsosomehow take into account the data from condition 2 when calculating freq?  Appendix 1 uses EMGlft as refchan inft_sourceanalysis and has defined  cfg.channelcmb= {'MEG' 'MEG';'MEG' 'EMGlft'}; in ft_freqanalysis. The coherence in the position of thereference dipole (i.e. 5 -5 -1) seems to be one, as would be expected since Iused the same data in both conditions.  Best,Maria
2017-07-07 9:08 GMT+03:00 Maria Hakonen <maria.hakonen at gmail.com>:

Hi Maria,
I think there is more than one solution for what you are aiming to do. Maybe a more experienced user or developer could show you the most straightforward way (?).
IMO, using LCMV is more direct for this application because with DICS you will need to provide the reference signal (i.e., the source timecourse from the other condition). Therefore, you will need to apply LCMV anyway. You could apply a band-pass filter to the channel activity before localizing the frequency band of interest with LCMV. Alternatively, you could obtain the virtual channels (without band pass) and define the frequency bands of interest when computing the coherence as in the tutorial (see ft_freqanalysis steps at http://www.fieldtriptoolbox. org/tutorial/coherence# computing_the_coherence).With DICS, in this case, I see it more intricate: 1) obtain the source timecourses of condition 2 with LCVM; 2) compute the cross spectral density between all data channels and each source timecourse (reference signal); 3) compute DICS for each reference signal. Of course, you don't need to compute the coherence for the whole brain, but only for the source of interest. For each reference signal, you could change the cfg.grid.inside value to include only the position of the voxel of interest (the same voxel of the reference signal).I hope this helps.
Best,Maité
Hi Maité,
I have been wondering whether I could calculate coherence straight from the cross spectros without reference signals or virtual channels by using beamformer_dics. In beamformer_dics, it seems to be possible to define the location of the dipole with which coherence is computed (i.e. refdip). However, I am not sure if it is possible to calculate the coherence between the same brain region in two different conditions.
Best,Maria
2017-06-29 12:57 GMT+03:00 Maria Hakonen <maria.hakonen at gmail.com>:

Hi Maria,
for obtaining the sources timecourses (aka virtual channels) you can follow the tutorials pasted below.

Best,Maité

http://www.fieldtriptoolbox.or g/tutorial/connectivity#extrac t_the_virtual_channel_time- series

http://www.fieldtriptoolbox.or g/tutorial/shared/virtual_sens ors#extract_the_virtual_channe l_time-series

Hi Maité,Thank for your answer again!However, I would need to calculate coherence within certain frequency bands and, therefore, I would like to use dics. The examples in the links seem to use lcmv. Could you please let me know how I can get coherence between conditions using dics?Best,Maria
2017-06-26 12:45 GMT+03:00 Maria Hakonen <maria.hakonen at gmail.com>:

Hi Maria,
maybe in this case it is better that you export the sources timecourses, build a data matrix with them and treat them in the same way as you did with the channels.

Best,Maité

Hi Maité,
Could you please yet let me know how to get the sources timecources? source = ft_sourceanalysis(cfg, freq); only gives  source =
freq: 18    cumtapcnt: [180x1 double]          dim: [19 15 15]       inside: [4275x1 logical]          pos: [4275x3 double]       method: 'average'          avg: [1x1 struct]          cfg: [1x1 struct]
Best,Maria
2017-06-25 13:53 GMT+03:00 Maria Hakonen <maria.hakonen at gmail.com>:

Hi Maité,Thank you for your answer!I have managed to calculate the coherence between two conditions in the sensor space in the way you suggested. However, I haven't managed to calculate the coherence between conditions in the source space (i.e. Appendix 1 in http://www.fieldtriptoolbox.or g/tutorial/coherence). ft_sourceanalysis doesn't have channelcmb. I wonder if anyone has any solutions for this?BTW. I didn't get the answer to my question in my email but found it from Fieldtrip archive. However, I have also got some other emails from fieldtrip discussion forum.Best,Maria
Hi Maria,
Here it is a possible solution. First, rename channels from one of both conditions: for example, for condition 2, {'ch01cond2', 'ch02cond2', ...}. Then, append the data from both conditions. In ft_freqanalysis introduce all the channels combinations you want:

cfg.channel    = {'MEG' 'ch01cond2' 'ch02cond2' ...};
cfg.channelcmb = {'ch01' 'ch01cond2'; 'ch02' 'ch02cond2'};
As I understand, you could use the same channelcmb later on in ft_connectivityanalysis.
I hope it helps.
Best wishes,Maité

Dear FieldTrip experts,

I have just started to use Fieldtrip and would like to estimate coherence between MEG responses measured in two different conditions from the same cortical areas. The example in Appendix 1 is close to what I would like to do:
http://www.fieldtriptoolbox.or g/tutorial/coherence

However, in the example, coherence is calculated between the reference signal (EMG) and all MEG channels. Could it be possible to calculate coherence between each MEG channel in one condition and the same MEG channels in the other condition, that is:
ch1 in cond1 vs. ch1 in cond2, ch2 in cond1 vs. ch2 in cond2, ...

As far as I understand, the example in Appendix 1 would do this:
ch1 in cond1 vs. all channels in cond2, ch2 in cond ch1 all channels in cond2, ...

Best,
Maria

_______________________________________________
fieldtrip mailing list
fieldtrip at donders.ru.nl
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20170710/d9c68975/attachment-0002.html>
```