www.gusucode.com > wavelet 源码程序 matlab案例代码 > wavelet/WaveletCoherenceUsingSamplingIntervalExample.m

    %% Effect of Sampling Interval on Wavelet Coherence
% Obtain the wavelet coherence data for two signals, specifying a sampling
% interval of 0.001 seconds. Both signals consist of two sine waves (10 Hz 
% and 50 Hz) in white noise. The sine waves have different time supports. 
%%
% Set the random number generator to its default settings for 
% reproducibility. Then, create the two signals and obtain the coherence.
rng default;
t = 0:0.001:2;
x = cos(2*pi*10*t).*(t>=0.5 & t<1.1)+ ...
cos(2*pi*50*t).*(t>= 0.2 & t< 1.4)+0.25*randn(size(t));
y = sin(2*pi*10*t).*(t>=0.6 & t<1.2)+...
sin(2*pi*50*t).*(t>= 0.4 & t<1.6)+ 0.35*randn(size(t));
[wcoh,~,period,coi] = wcoherence(x,y,seconds(0.001));
%%
% Use the |pcolor| command to plot the coherence and cone of influence. 
period = seconds(period);
coi = seconds(coi);
h = pcolor(t,log2(period),wcoh);
h.EdgeColor = 'none';
ax = gca;
ytick=round(pow2(ax.YTick),3);
ax.YTickLabel=ytick;
ax.XLabel.String='Time';
ax.YLabel.String='Period';
ax.Title.String = 'Wavelet Coherence';
hcol = colorbar;
hcol.Label.String = 'Magnitude-Squared Coherence';
hold on;
plot(ax,t,log2(coi),'w--','linewidth',2);
%%
% Use |wcoherence(x,y,seconds(0.001))| without any outputs arguments. This 
% plot includes the phase arrows and the cone of influence.
%
wcoherence(x,y,seconds(0.001));