Home > brain, matlab, nirs > Extracting wavelet coherence values

Extracting wavelet coherence values

June 11th, 2013

In my previous blog (http://www.alivelearn.net/?p=1426) and in our paper titled “NIRS-based hyperscanning reveals increased interpersonal coherence in superior frontal cortex during cooperation” (full text pdf available ), we have shown how wavelet coherence plot can show more useful information. People often asked, how did you extract the values from the plot?

Here is the code:

[Rsq,period,scale,coi,sig95] = wtc(signal1,signal2,'mcc',0, 'ms',128);
period32 = find(period>32);
period32 = period32(1);
b1 = mean(mean(Rsq(period32:end, marktime(1):marktime(2))));
bi = mean(mean(Rsq(period32:end, marktime(2):marktime(3))));
b2 = mean(mean(Rsq(period32:end, marktime(3):marktime(4))));

To download the “Cross Wavelet and Wavelet Coherence Toolbox”, please enter

Author: Xu Cui Categories: brain, matlab, nirs Tags:
Try Stork, a research tool we developed

Stork is a publication alert app developed by us at Stanford. As a researcher we often forget to follow up important publications - and it's practically impossible to search many keywords or researchers' names everyday. Stork can help us to search everyday and notifies us when there are new publications/grants. How Stork helped me?

About the author:

Xu Cui is a human brain research scientist in Stanford University. He lives in the Bay Area in the United States. He is also the founder of Stork (smart publication alert app), PaperBox and BizGenius.


He was born in He'nan province, China. He received education in Beijing University(BS), University of Tennessee (Knoxville) (MS), Baylor College of Medicine (PhD) and Stanford University (PostDoc). Read more ...
  1. tHonghong Tang
    July 9th, 2013 at 20:16 | #1

    Thanks for your code and explanation.I’m a student learning to analysis the coherence between NIRS-based two time series.And I got some negative ‘increase coherence’,which was calculated as the way in your paper “NIRS-based hyperscanning reveals increased interpersonal coherence in superior frontal cortex during cooperation”. I used the average coherence value in the block(8min)minus average coherence in an prior independent rest(3min),some channels’ value were negative.What’s the meaning of the negative coherence?
    Hope for your reply.

  2. July 9th, 2013 at 21:34 | #2

    @tHonghong Tang
    Negative change means that, the coherence during rest is actually higher than the coherence during task.

  3. Honghong Tang
    October 8th, 2013 at 19:33 | #3

    @Xu Cui
    Dear Dr.Xu,
    Thanks a lot for your explanation very much!
    I have another question about the coherence value.
    Since my data was composed of 3blocks, each with several trails,if I want to get the cohrence of certain stage in each trial(which could be separated by the marktime),how would I deal with the data?
    Should I calculate the whole blcok coherence first,then extract those values in that stage through the timepoint mark, and average them?
    Or just extract those time series to calculate the coherence independently,then average them?

    BTW,I’m a student of Dr.Liu now~~~and I’m learning to analysis the hyperscanning NIRS data.And now we’ve found some interesting results,but have no good idea about how to explian the coherence.So we want to try to extract the coherence in certain stage of each trial.
    Hope for your replay sincerely~~~

  4. October 8th, 2013 at 19:46 | #4

    @Honghong Tang
    In general, you should get the coherence for all time courses, then calculate the coherence for each block or stage.

    btw, which Dr Liu you are referring to?

  5. Honghong Tang
    October 9th, 2013 at 05:28 | #5

    @Xu Cui
    Thanks for your reply.
    “then calculate the coherence for each block or stage.”
    You mean that extrcating the coherence in certain stage and averaging them?

    I referred to Dr. Liuchao~~~ha~~

  6. October 9th, 2013 at 13:09 | #6

    @Honghong Tang
    Yes, I mean that.

    Good to hear you are working with Dr Liu.

  7. Honghong Tang
    October 9th, 2013 at 23:45 | #7

    @Xu Cui
    Thanks ~~
    And I‘ve learned a lot from your blog about the nirs data analysis~~~
    When I used NIRS_SPM to calculate the activation of my task, most of my 22channels showed negative beta,is that normal or may I did something wrong?

  8. October 10th, 2013 at 10:11 | #8

    Honghong, I have not used NIRS_SPM for a long time so I am not sure if it’s normal to get a lot of negative betas. Presumably it’s related to your tasks.

  9. Honghong Tang
    October 17th, 2013 at 06:08 | #9

    Thank you all the same~~~

  10. junpu hu
    February 18th, 2014 at 19:45 | #10

    你好,我是一名中国大学生,我想问一下http://noc.ac.uk/using-science/crosswavelet-wavelet-coherence 这个小波相干工具包是不是绘制的图比形经过蒙娜卡罗算法,所以绘制的图像比较粗糙,就像网页上FAQ里面讲Y轴转换的例子一样,只有5Hz地方有相干,但是图上面显示的是个区域,如此在只需要相干数值的情况下,对相干数值矩阵进行时间频率段上的求和能不能得到比较准确的数据呢? 希望能得到你的帮助

  11. junpu hu
    February 18th, 2014 at 20:55 | #11


  12. Sarah
    November 5th, 2014 at 13:31 | #12

    I am trying to extract the coefficients for two time-series variables and the code works up until this line:
    b1 = mean(mean(Rsq(period32:end, marktime(1):marktime(2))));
    I get an error message that reads: “Undefined function ‘marktime’ for input arguments of type ‘double’.”

    I am not sure what I am doing wrong; if you have any feedback or help that would be greatly appreciated. Thank you so much!

  13. November 5th, 2014 at 13:45 | #13

    marktime is a variable name. You don’t need to worry about it.

  14. Jason
    March 22nd, 2015 at 08:28 | #14

    @Honghong Tang
    T_T I’m encountered with this problem, too….