<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Don’t worry Vladimir,
<div class=""><br class="">
</div>
<div class="">Robert and I have discussed these issues at length on several occasions in the past ;) </div>
<div class="">Best wishes,</div>
<div class="">JM</div>
<div class=""><br class="">
</div>
<div class="">
<div>
<blockquote type="cite" class="">
<div class="">On 21 Sep 2017, at 12:29, Vladimir Litvak <<a href="mailto:litvak.vladimir@gmail.com" class="">litvak.vladimir@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">Hi Jan-Mathijs,
<div class=""><br class="">
</div>
<div class="">Yes, you are right about Robert's example. But if you do:</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">pad = 10;</div>
<div class=""><br class="">
</div>
<div class="">fsample = 1000;</div>
<div class="">time = (1:1000)/fsample;</div>
<div class="">dat = randn(size(time));</div>
<div class=""><br class="">
</div>
<div class="">[spectrum1,ntaper1,freqoi1] = ft_specest_mtmfft(dat, time, 'taper', 'hanning', 'pad', pad);</div>
<div class=""><br class="">
</div>
<div class="">power1 = abs(spectrum1).^2;</div>
<div class="">power1 = squeeze(power1);</div>
<div class=""><br class="">
</div>
<div class="">[spectrum2,ntaper2,freqoi2,timeoi2] = ft_specest_mtmconvol(dat, time, 'taper', 'hanning', 'timeoi', mean(time), 'timwin', 0.99, 'pad', pad);</div>
<div class=""><br class="">
</div>
<div class="">power2 = abs(spectrum2).^2;</div>
<div class="">power2 = squeeze(power2);</div>
<div class=""><br class="">
</div>
<div class="">figure</div>
<div class="">plot(freqoi1, power1);</div>
<div class="">hold on</div>
<div class="">plot(freqoi2, power2, 'r');</div>
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">You will see the problem that I'm talking about. We discussed with Robert yesterday and this is indeed 'a feature' which has to do with the fact that the outputs of mtmfft and mtmconvol have different units. The former is spectral density whereas
 the latter is spectral power.</div>
<div class=""><br class="">
</div>
Here is what Robert wrote me:<br class="">
<blockquote style="margin:0 0 0 40px;border:none;padding:0px" class=""><br class="">
the units of computations (also here) are a known and long-standing issue. I know for a long time that the two have different scaling, but did not think about it for a long time. I recall something like this: To compare TFRs over frequencies, you don't want
 the bandwidth to affect the estimate. Shorter wavelets have a larger bandwidth, hence the 1/Hz would affect those. E.g. imagine a 10Hz and a 20Hz sine wave, and do a TFR with conventional wavelets: at 20Hz the wavelet is 2x shorter, so the spectral resolution
 over which the signal(and noise) spreads is different. If you were to compute the TFR in V^2/Hz, the same V at 20Hz would have a different value, because the length of the wavelet affects the 1/Hz.<br class="">
something related (but nevertheless different) applies to the mtmfft: if you want to estimate broadband activity in a window of 1 second or a window of 2 seconds, you would get different spectral resolutions. The nyquist is the same, but the power gets distributed
 over more bins between 0 and Fnyquist/2. That would cause the values to appear smaller in the 2-s case. Hence we compute spectral density, which somehow normalizes for this. I never found a really clear explanation, but google got me this
<a href="https://dsp.stackexchange.com/questions/33957/what-is-the-difference-between-the-psd-and-the-power-spectrum" class="">
https://dsp.stackexchange.com/questions/33957/what-is-the-difference-between-the-psd-and-the-power-spectrum</a><br class="">
what confuses me is that power (or variance) is already normalized, i.e. sum of squared values divided by N. So we have energy (which increases with length), power (which does not increase with length), and power density<br class="">
<br class="">
<br class="">
</blockquote>
So one issue is that most people don't know about this including me and possibly you. I think a good solution would be to add an option to specify the output units for all the methods as there might be quite subtle considerations for choosing one over the other
 as Robert suggests.
<div class=""><br class="">
</div>
<div class="">Vladimir</div>
</div>
<div class="gmail_extra"><br class="">
<div class="gmail_quote">On Thu, Sep 21, 2017 at 10:53 AM, Schoffelen, J.M. (Jan Mathijs)
<span dir="ltr" class=""><<a href="mailto:jan.schoffelen@donders.ru.nl" target="_blank" class="">jan.schoffelen@donders.ru.nl</a>></span> wrote:<br class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word" class="">Hi to all who’s reading along,
<div class=""><br class="">
</div>
<div class="">Perhaps the two cases will become more similar once the ‘timwin’ is increased in length for the mtmconvol case….</div>
<div class=""><br class="">
</div>
<div class="">Best wishes,</div>
<div class=""><br class="">
</div>
<div class="">JM</div>
<div class="">
<div class="h5">
<div class=""><br class="">
<div class="">
<blockquote type="cite" class="">
<div class="">On 20 Sep 2017, at 16:26, Robert Oostenveld <<a href="mailto:r.oostenveld@donders.ru.nl" target="_blank" class="">r.oostenveld@donders.ru.nl</a>> wrote:</div>
<br class="m_-7398392055170583879Apple-interchange-newline">
<div class="">
<div style="word-wrap:break-word" class="">Hi Vladimir,
<div class=""><br class="">
</div>
<div class="">I suggest that you first start with a simpler case, like this</div>
<div class=""><br class="">
</div>
<div class="">
<div class=""><font face="Courier" class="">fsample = 1000;</font></div>
<div class=""><font face="Courier" class="">time = (1:1000)/fsample;</font></div>
<div class=""><font face="Courier" class="">dat = randn(size(time));</font></div>
<div class=""><font face="Courier" class=""><br class="">
</font></div>
<div class=""><font face="Courier" class="">[spectrum1,ntaper1,freqoi1] = ft_specest_mtmfft(dat, time, 'taper', 'hanning');</font></div>
<div class=""><font face="Courier" class=""><br class="">
</font></div>
<div class=""><font face="Courier" class="">power1 = abs(spectrum1).^2;</font></div>
<div class=""><font face="Courier" class="">power1 = squeeze(power1);</font></div>
<div class=""><font face="Courier" class=""><br class="">
</font></div>
<div class=""><font face="Courier" class="">[spectrum2,ntaper2,freqoi2,<wbr class="">timeoi2] = ft_specest_mtmconvol(dat, time, 'taper', 'hanning', 'timeoi', mean(time), 'timwin', 0.5);</font></div>
<div class=""><font face="Courier" class=""><br class="">
</font></div>
<div class=""><font face="Courier" class="">power2 = abs(spectrum2).^2;</font></div>
<div class=""><font face="Courier" class="">power2 = squeeze(power2);</font></div>
<div class=""><font face="Courier" class=""><br class="">
</font></div>
<div class=""><font face="Courier" class="">figure</font></div>
<div class=""><font face="Courier" class="">plot(freqoi1, power1);</font></div>
<div class=""><font face="Courier" class="">hold on</font></div>
<div class=""><font face="Courier" class="">plot(freqoi2, power2, 'r');</font></div>
</div>
<div class=""><br class="">
</div>
<div class="">Note that these are not the same (albeit similar), which I had expected…</div>
<div class=""><br class="">
</div>
<div class="">best</div>
<div class="">Robert</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
<div class="">
<blockquote type="cite" class="">
<div class="">On 20 Sep 2017, at 12:56, Vladimir Litvak <<a href="mailto:litvak.vladimir@gmail.com" target="_blank" class="">litvak.vladimir@gmail.com</a>> wrote:</div>
<br class="m_-7398392055170583879Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">Dear Fieldtrippers,
<div class=""><br class="">
</div>
<div class="">I'm looking into an issue of one of SPM users who gets different results when doing TF decomposition compared to computing a spectrum for the same time window. I'm not sure I got to the bottom of it yet but one thing I found is that ft_specest_mtmfft
 and ft_specest_mtmconvol are affected differently by increasing padding. For short padding the results are similar but with increasing padding there are differences both in offset of the spectrum and its overall shape. See attached images where the top one
 shows original spectra and the bottom one aligns the lowermost bin to zero. </div>
<div class=""><br class="">
</div>
<div class="">Is this a bug or a feature?</div>
<div class=""><br class="">
</div>
<div class="">Below is the script that produces these plots. I could provide the data as well but this could probably be reproduced with any data.</div>
<div class=""><br class="">
</div>
<div class="">Thanks,</div>
<div class=""><br class="">
</div>
<div class="">Vladimir</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">------------------------------<wbr class="">-------</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">pad = 0.5;%1%10</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">freqoi = 5:45;</div>
<div class="">timwin = 0.4+0*freqoi;</div>
<div class=""><br class="">
</div>
<div class="">[spectrum,ntaper,freqoi,<wbr class="">timeoi] = ft_specest_mtmconvol(data, time, 'taper', 'hanning', 'timeoi', 1.2, 'freqoi', freqoi,...</div>
<div class="">    'timwin', timwin, 'tapsmofrq', 1, 'verbose', 0, 'pad', pad);</div>
<div class=""><br class="">
</div>
<div class="">s1 = squeeze(mean(mean(abs(<wbr class="">spectrum), 4), 2));</div>
<div class=""><br class="">
</div>
<div class="">figure;</div>
<div class="">subplot(2,1,1)</div>
<div class="">plot(freqoi, s1);</div>
<div class="">subplot(2,1,2);</div>
<div class="">plot(freqoi, s1-s1(1));</div>
<div class="">%%</div>
<div class="">[spectrum,ntaper,freqoi] = ft_specest_mtmfft(data, time, 'taper', 'hanning', 'freqoi', freqoi,...</div>
<div class="">    'tapsmofrq', 1, 'verbose', 0, 'pad', pad);</div>
<div class=""><br class="">
</div>
<div class="">s2 = squeeze(mean(mean(abs(<wbr class="">spectrum), 2), 1));</div>
<div class=""><br class="">
</div>
<div class="">subplot(2,1,1)</div>
<div class="">hold on</div>
<div class="">plot(freqoi, s2, 'r');</div>
<div class="">subplot(2,1,2)</div>
<div class="">hold on</div>
<div class="">plot(freqoi, s2-s2(1), 'r');</div>
</div>
</div>
<span id="m_-7398392055170583879cid:644C10BA-EE23-4C79-817F-AED817ACCF00@ki.se" class=""><pad0_5.png></span><span id="m_-7398392055170583879cid:0A594045-C414-4F44-90FF-32D0857460C8@ki.se" class=""><pad1.png></span><span id="m_-7398392055170583879cid:6709F946-F5E8-4614-AA94-A53AEFA36EFA@ki.se" class=""><pad10.<wbr class="">png></span>__________________________<wbr class="">_____________________<br class="">
fieldtrip mailing list<br class="">
<a href="mailto:fieldtrip@donders.ru.nl" target="_blank" class="">fieldtrip@donders.ru.nl</a><br class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank" class="">https://mailman.science.ru.nl/<wbr class="">mailman/listinfo/fieldtrip</a></div>
</blockquote>
</div>
<br class="">
</div>
</div>
______________________________<wbr class="">_________________<br class="">
fieldtrip mailing list<br class="">
<a href="mailto:fieldtrip@donders.ru.nl" target="_blank" class="">fieldtrip@donders.ru.nl</a><br class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank" class="">https://mailman.science.ru.nl/<wbr class="">mailman/listinfo/fieldtrip</a></div>
</blockquote>
</div>
<br class="">
</div>
</div>
</div>
</div>
<br class="">
______________________________<wbr class="">_________________<br class="">
fieldtrip mailing list<br class="">
<a href="mailto:fieldtrip@donders.ru.nl" class="">fieldtrip@donders.ru.nl</a><br class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank" class="">https://mailman.science.ru.nl/<wbr class="">mailman/listinfo/fieldtrip</a><br class="">
</blockquote>
</div>
<br class="">
</div>
_______________________________________________<br class="">
fieldtrip mailing list<br class="">
<a href="mailto:fieldtrip@donders.ru.nl" class="">fieldtrip@donders.ru.nl</a><br class="">
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>