<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 Walter,
<div class=""><br class="">
</div>
<div class="">Here are some thoughts:</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">The zigzag is a well-known convergence issue that may be caused by too large collinearity between your signals. This may occur if:</div>
<div class="">- the multivariate signal is too multi, (i.e. there are many channels that go into the non-parametric spectral factorization at once) -> possible solution use cfg.sfmethod = ‘bivariate’;</div>
<div class="">- there is a large common (instantaneous) component underlying your signals. -> not much to do about this, apart perhaps in your case use local bipolar rereference, rather than a common reference</div>
<div class=""><br class="">
</div>
<div class="">Also, zigzags are more likely to occur if the factorization is applied to time-frequency data, as computed with mtmconvol, which probably has to do with spectral leakage -> if you want time resolved GC, run the shifting time window in an outer
 loop, and use mtmfft for the spectral transformation. One possible reason is that users might be a bit too creative in their specification of the options for mtmconvol which are suboptimal for the spectral factorization algorithm.</div>
<div class=""><br class="">
</div>
<div class="">Moreover, the spectra should ideally contain all frequencies from DC up to (close to Nyquist) with a sufficiently high sampling -> use cfg.pad that is relatively large, e.g. 4</div>
<div class="">Moreover, the spectra should be relatively smooth, without ’spikes’ -> ensure that your spectra don’t contain spikes, and use a sufficiently large number of trials + ideally some multitapering.<br class="">
<div><br class="">
</div>
<div>Finally, there's an option cfg.granger.stabilityfix (in ft_connectivity_csd2transfer) which might alleviate the zigzags a bit, although I would only use this if the zigzag is minor.</div>
<div><br class="">
</div>
<div>I quickly browsed the archive of this discussion list, and I noticed that optimal analysis strategies for spectrally resolved GC have been discussed before, however they don’t seem to have made it into documentation  on the fieldtrip website. If you feel
 like it, it would be great if you could make a suggestion for a FAQ that collects the above mentioned (and other tips and tricks), for future reference.</div>
<div><br class="">
</div>
<div>Best wishes,</div>
<div>Jan-Mathijs</div>
<div><br class="">
</div>
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 18 Jul 2023, at 11:16, Canedo Riedel, Walter 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 id="divtagdefaultwrapper" dir="ltr" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-size: 12pt; font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" class="">
<p style="margin-top: 0px; margin-bottom: 0px;" class=""></p>
<div style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;" class="">
<p style="margin-top: 0px; margin-bottom: 1rem; text-align: justify; color: rgb(12, 84, 96);" class="">
<span style="" class="">Dear community,</span></p>
<span style="" class=""></span>
<p style="margin-top: 0px; margin-bottom: 1rem; text-align: justify; color: rgb(12, 84, 96);" class="">
<span style="" class="">My name is Walter Cañedo Riedel and I am working at Kelschlab (Mainz University). I am currently analyzing LFP data; there are several channels and I am trying to obtain their Granger causality spectra (by pairs of channels) with the
 non-parametric approach starting with a wavelet transform. My LFP data is at a resolution of 1000Hz.</span><span style="" class=""></span></p>
<div style="margin-top: 0px; margin-bottom: 1rem; text-align: justify; color: rgb(12, 84, 96);" class="">
<span style="" class=""></span><br class="webkit-block-placeholder">
</div>
<p style="margin-top: 0px; margin-bottom: 1rem; font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px; text-align: justify; color: rgb(12, 84, 96);" class="">
<span style="" class=""><b class="">I would appreciate if you help me understand how to run the non-parametric Granger causality correctly.  </b></span><span style="" class="">The GC spectra that I obtain have all the following artifact: every second frequency
 is exalted with respect to its immediate neighbor frequencies, forming a zebra-stripe pattern (image:<span class="Apple-converted-space"> </span></span><i style="" class="">GC from a channel to another</i><span style="" class="">).</span></p>
<p style="margin-top: 0px; margin-bottom: 0px;" class=""></p>
<p style="margin-top: 0px; margin-bottom: 1rem; text-align: justify; color: rgb(12, 84, 96);" class="">
<span style="" class="">I made a<span class="Apple-converted-space"> </span></span><span style="" class="">simple simulation to look into it. Channel 1 and channel 2 are modulated by different frequencies plus noise. Ch1 from time t-3 to t-1 influences Ch2
 linearly at time t.</span><br class="">
<span style="" class="">If Ch1 is modulated by a frequency below 10 Hz, then I get the stripe artifact for its Granger causality to Ch2. (Image:<span class="Apple-converted-space"> </span><i class="">GC has an artifact...</i>)  The script for the simulation
 is found below after my signature. </span></p>
<div style="margin-top: 0px; margin-bottom: 1rem; text-align: justify; color: rgb(12, 84, 96);" class="">
<span style="" class=""></span><br class="webkit-block-placeholder">
</div>
<div style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;" class="">
<p style="margin-top: 0px; margin-bottom: 1rem; text-align: justify; color: rgb(12, 84, 96);" class="">
<span style="" class="">Things that I've tried to no avail:</span></p>
<div style="margin-top: 0px; margin-bottom: 1rem; text-align: justify; color: rgb(12, 84, 96);" class="">
<br class="webkit-block-placeholder">
</div>
<ul style="margin-bottom: 0px; margin-top: 0px;" class="">
<li class="">Doing the analysis up to the Nyquist limit (by down-sampling the data to 200Hz and analyzing frequencies 1:100).</li><li class="">High-pass filtering my data (I still get stripes even after filtering out frequencies below 15Hz).</li><li class="">Trying out 'mtmconvol' with hanning or with dpss instead of 'wavelet' for <span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px; text-align: justify;" class="">ft_freqanalysis cfg.method.</span></li><li class="">Trying cfg.output = 'fourier' or 'powandcsd'.</li><li class="">Varying the size of the width for the wavelet or of the respective window for mtmconvol. </li></ul>
</div>
<p style="margin-top: 0px; margin-bottom: 0px;" class=""></p>
<p style="margin-top: 0px; margin-bottom: 1rem; text-align: justify; color: rgb(12, 84, 96);" class="">
<span style="" class=""><br class="">
</span></p>
<p style="margin-top: 0px; margin-bottom: 1rem; text-align: justify; color: rgb(12, 84, 96);" class="">
<span id="cid:b088c18a-8599-4446-8130-f8bf549fe488"><pastedImage.png></span><br class="">
</p>
<p style="margin-top: 0px; margin-bottom: 1rem; text-align: justify; color: rgb(12, 84, 96);" class="">
<span id="cid:7683ed51-e509-48ee-bf96-835fc2867626"><pastedImage.png></span><br class="">
</p>
<p style="margin-top: 0px; margin-bottom: 1rem; text-align: justify; color: rgb(12, 84, 96);" class="">
<br class="">
</p>
</div>
<div id="Signature" class="">
<div id="divtagdefaultwrapper" dir="ltr" style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" class="">
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 12pt;" class=""><span style="font-size: 13px; font-family: Tahoma, serif, EmojiFont; color: rgb(128, 128, 128);" class=""></span></p>
<div class="">All the best,</div>
<div class=""><span style="color: rgb(128, 128, 128); font-family: Tahoma, serif, EmojiFont; font-size: 13px;" class="">Walter Cañedo Riedel</span></div>
<p style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-size: 8pt; font-family: Tahoma, serif, EmojiFont; color: rgb(128, 128, 128);" class=""></span></p>
<div style="margin-top: 0px; margin-bottom: 0px; font-size: 12pt;" class=""><font color="808080" style="font-family: Tahoma, serif, EmojiFont; font-size: 13px;" class="">Central Institute of Mental Health (ZI)<br class="">
AG Kelsch</font><span style="font-family: Tahoma, serif, EmojiFont; font-size: 13px; color: rgb(128, 128, 128);" class=""></span></div>
<div style="margin-top: 0px; margin-bottom: 0px; font-size: 12pt;" class=""><font color="808080" style="font-family: Tahoma, serif, EmojiFont; font-size: 13px;" class="">+49 (0)621 1703 6203</font></div>
<div style="margin-top: 0px; margin-bottom: 0px; font-size: 12pt;" class=""><font color="808080" style="font-family: Tahoma, serif, EmojiFont; font-size: 13px;" class=""><br class="">
</font></div>
<div style="margin-top: 0px; margin-bottom: 0px; font-size: 12pt;" class=""><font color="808080" style="font-family: Tahoma, serif, EmojiFont; font-size: 13px;" class=""><br class="">
</font></div>
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 12pt;" class=""><font color="808080" style="font-family: Tahoma, serif, EmojiFont; font-size: 13px;" class=""></font></p>
<font color="808080" style="font-family: Tahoma, serif, EmojiFont; font-size: 13px;" class="">
<div class="">%% Simulation</div>
<div class="">clear</div>
<div class="">lfpchannels = NaN(1200000, 2); % Two channels (CH1 & CH2) with million two hundred thousand datapoints</div>
<div class="">frequency = 1000; % I have a 1000Hz resolution</div>
<div class=""><br class="">
</div>
<div class="">SaverGC = [];</div>
<div class="">SaverPW = [];</div>
<div class="">for fr = 1:10</div>
<div class="">    lfpchannels(:, :) = rand(size(lfpchannels)); % Initial noise in the channels</div>
<div class="">    </div>
<div class="">    % Modulate CH1 at (fr)Hz</div>
<div class="">    dt = 1/frequency; </div>
<div class="">    StopTime = size(lfpchannels,1)/frequency; </div>
<div class="">    t = (0:dt:StopTime-dt)'; </div>
<div class="">    F = fr; % Sine wave frequency (Hz)</div>
<div class="">    Modulator1 = sin(2*pi*F*t) / 10; </div>
<div class="">    lfpchannels(1:numel(Modulator1), 1) = lfpchannels(1:numel(Modulator1), 1) + Modulator1;</div>
<div class="">    % Modulate CH2 at 38Hz</div>
<div class="">    F = 38; % Sine wave frequency (Hz)</div>
<div class="">    Modulator = sin(2*pi*F*t) / 10;</div>
<div class="">    lfpchannels(1:numel(Modulator), 2) = lfpchannels(1:numel(Modulator), 2) + Modulator;</div>
<div class="">    </div>
<div class="">    % Random weights for CH1(t-3:t-1) influencing CH2(t).</div>
<div class="">    FRA_s = 3;</div>
<div class="">    FRA = rand(FRA_s, 1);</div>
<div class="">    % Make CH1 influence CH2</div>
<div class="">    for p = FRA_s+1:size(lfpchannels,1)</div>
<div class="">        lfpchannels(p, 2) = lfpchannels(p, 2) + mean(FRA.*lfpchannels(p-FRA_s : p-1, 1));</div>
<div class="">    end</div>
<div class="">    % z score channels to have same variance</div>
<div class="">    lfpchannels = (lfpchannels - mean(lfpchannels,1)) ./ std(lfpchannels, 0, 1);</div>
<div class="">    </div>
<div class="">    %%% Make data structure with trials</div>
<div class="">    TrialMarker = 1:numel(-1.999:0.001:14)/2:(numel(-1.999:0.001:14)/2)*150 + 1;</div>
<div class="">    data            = struct;</div>
<div class="">    data.label      = {'1';'2'};</div>
<div class="">    data.fsample    = 1000;</div>
<div class="">    data.trial      = {};</div>
<div class="">    data.time       = {};</div>
<div class="">    for tr = 1:50</div>
<div class="">        data.trial{tr} = lfpchannels(TrialMarker(tr):TrialMarker(tr+2)-1, :)';</div>
<div class="">        data.time{tr} = -1.999:0.001:14;</div>
<div class="">    end</div>
<div class="">    data.sampleinfo = [1:50;101:150];</div>
<div class="">    data.trialinfo = ones(1, 50);</div>
<div class="">    </div>
<div class="">    %%% Run wavelet transform</div>
<div class="">    cfg        = [];</div>
<div class="">    cfg.method = 'wavelet';</div>
<div class="">    cfg.output = 'powandcsd';</div>
<div class="">    cfg.foi    = 1:100;</div>
<div class="">    cfg.width  = 7;</div>
<div class="">    cfg.toi    = (3);</div>
<div class="">    cfg.pad    = 20;</div>
<div class="">    freq = ft_freqanalysis(cfg, data);</div>
<div class="">    </div>
<div class="">    cfg           = [];</div>
<div class="">    cfg.method    = 'granger';</div>
<div class="">    cfg.granger.sfmethod = 'bivariate';</div>
<div class="">    Granger = ft_connectivityanalysis(cfg, freq);</div>
<div class="">    SaverGC(fr, :) = Granger.grangerspctrm(1, :);</div>
<div class="">    SaverPW(fr, :) = freq.powspctrm(1, :);</div>
<div class="">end</div>
<div class=""><br class="">
</div>
<div class="">figure</div>
<div class="">tiledlayout(1, 2)</div>
<div class="">nexttile</div>
<div class="">imagesc(SaverPW)</div>
<div class="">xlabel("Power spectrum (Hz)")</div>
<div class="">ylabel("Modulating signal (Hz)")</div>
<div class="">nexttile</div>
<div class="">imagesc(SaverGC)</div>
<div class="">xlabel("GC spectrum (Hz)")</div>
<div class="">sgtitle("GC has an artifact for the channel modulated by a signal of less than 10Hz")</div>
<div class=""><br class="">
</div>
<br class="">
</font>
<p style="margin-top: 0px; margin-bottom: 0px;" class=""></p>
</div>
</div>
</div>
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">_______________________________________________</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">fieldtrip
 mailing list</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<a href="https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!5M0VHKF356oxF_mZnzCwH0xUkXKCJJl_TBxDQx8L83BkI8GevSMrDsHx0pYTZrZeWb-WkDYPWyup4cbGf3_X2_GuxEMFAJDeWT6ZNQ$" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!5M0VHKF356oxF_mZnzCwH0xUkXKCJJl_TBxDQx8L83BkI8GevSMrDsHx0pYTZrZeWb-WkDYPWyup4cbGf3_X2_GuxEMFAJDeWT6ZNQ$</a><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class=""></span></div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>