Home > brain, matlab > Wavelet Coherence

## Wavelet Coherence

August 31st, 2010

Wavelet transform coherence (WTC) is a method for analyzing the coherence and phase lag between two time series as a function of both time and frequency (Chang and Glover 2010). Here I played with it using the MatLab toolbox provided by Grinsted et al.

In the following examples, I created two time series, x (blue) and y (red) with different properties (phase shift, frequency and amplitude) and run wtc(x,y,’mcc’,0) command. Small white noise was added to the time series.

1. Phase shift and angle. A rightward arrow indicates 0 lag; a bottom-right arrow indicates a small lead of x; a leftward arrow indicates x and y is anti-correlated.

Phase

2. Frequency. At what frequency (or period) are x and y correlated?

frequency

3. Amplitude. It seems amplitude doesn’t matter much.

amplitude

Toolbox can be found:
http://www.pol.ac.uk/home/research/waveletcoherence/
http://www.alivelearn.net/?p=1561

Source code:

```t =[1:1000]/10;

%% effect of phase
x = sin(t) + randn(size(t))/5;
y = [sin(t(1:250)) sin(t(251:500)-pi/4) sin(t(501:750)-pi/2) sin(t(751:end)-pi)] + randn(size(t))/5;

figure('color','w');
subplot(2,1,1);
wtc(x,y,'mcc',0)
subplot(2,1,2);
plot(x);
hold on;
plot(y,'r')

%% effect of frequency
x = [sin(2*t(1:250)) sin(2*t(251:500)) sin(4*t(501:750)) sin(8*t(751:end))] + randn(size(t))/5;
y = [sin(2*t(1:250)) sin(2*t(251:500)) sin(4*t(501:750)) sin(8*t(751:end))] + randn(size(t))/5;

figure('color','w');
subplot(2,1,1);
wtc(x,y,'mcc',0)
subplot(2,1,2);
plot(x);
hold on;
plot(y,'r')

%% effect of amplitude
x = [sin(2*t(1:250)) sin(2*t(251:500)) sin(4*t(501:750)) sin(8*t(751:end))] + randn(size(t))/5;
y = [sin(2*t(1:250)) sin(2*t(251:500))/2 sin(4*t(501:750))/3 sin(8*t(751:end))/4] + randn(size(t))/5;

figure('color','w');
subplot(2,1,1);
wtc(x,y,'mcc',0)
subplot(2,1,2);
plot(x);
hold on;
plot(y,'r')```
Xu Cui Categories: 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. September 29th, 2013 at 22:23 | #1

2. October 2nd, 2014 at 05:03 | #2

I have updated the toolbox, put it on github, and it is now hosted at: http://www.glaciology.net/wavelet-coherence

3. January 7th, 2015 at 15:17 | #3

Dear Xu Cui,
Can we have wavelet coherence Matrix in Matlab?

4. February 22nd, 2015 at 08:43 | #4

Respected Sir,
I need an help from you.I have a doubt in wavelet coherence using matlab.i have two series of length 80.how should i write the code in matlab so that i will get the wavelet coherence of two time series is a single value?

5. August 20th, 2016 at 23:50 | #5

HOW I UPDATED THE WAVELET TOOL BOX FOR PERFORMING THE CROSSWAVELET AND WAVELET COHERENCE

6. October 20th, 2016 at 19:19 | #6

7. April 10th, 2017 at 07:46 | #7

respected sir
I see that the arrows pointed up indicated the second series lag the first series 1/4 cycle on the site https://www.mathworks.com&gt;examples

8. November 1st, 2017 at 02:09 | #8

The ‘v6′ argument to COLORBAR is
deprecated, and will no longer be supported in a
future release.

9. November 1st, 2017 at 08:27 | #9

@Liuxiaoyun
Thanks for the warning.

10. November 2nd, 2017 at 01:15 | #10

how do i solve the problem?

11. November 2nd, 2017 at 08:55 | #11

@Liiuxiaoyun
No need to solve for now. If future matlab does not support it, you might need to modify the source code.

12. November 7th, 2017 at 03:17 | #12

Dr. Cui, many thanks for your great information,

How can I limit the period in y axis to 64 or 32?

13. January 22nd, 2018 at 03:55 | #13

How to compute cross wavelet or wavelet coherence for time series having same sampling rate but different lengths?

14. January 22nd, 2018 at 09:37 | #14