5 %----------default arguments for the wavelet transform-----------
6 Args=struct('Pad',1,... % pad the time series with zeroes (recommended)
7 'Dj',1/12, ... % this will do 12 sub-octaves per octave
8 'S0',2*dt,... % this says start at a scale of 2 years
10 'Mother','Morlet', ...
11 'MaxScale',[],... %a more simple way to specify J1
13 J1 = noctave * nvoice - 1
18 [X,period,scale] = wavelet(x,Args.Dj,Args.S0,Args.J1);
19 [Y,period,scale] = wavelet(y,Args.Dj,Args.S0,Args.J1);
26 ## compare Rwave and biwavelets
27 x = runif(128) #runif(100)
28 w1 = wt(cbind(1:128,x), pad = TRUE, dt = NULL, do.sig=FALSE, dj=1/12, J1=51)
29 w2 = Rwave::cwt(x, 13, 4, w0=2*pi, twoD=TRUE, plot=FALSE)
38 %Smooth X and Y before truncating! (minimize coi)
40 sX=smoothwavelet(sinv(:,ones(1,nx)).*(abs(X).^2),dt,period,Args.Dj,scale);
41 sY=smoothwavelet(sinv(:,ones(1,ny)).*(abs(Y).^2),dt,period,Args.Dj,scale);
43 % -------- Cross wavelet -------
46 % ----------------------- Wavelet coherence ---------------------------------
47 sWxy=smoothwavelet(sinv(:,ones(1,n)).*Wxy,dt,period,Args.Dj,scale);
52 %swave=zeros(size(wave));
53 twave=zeros(size(wave));
55 %zero-pad to power of 2... Speeds up fft calcs if n is large
56 npad=2.^ceil(log2(n));
59 k = k.*((2.*pi)/npad);
60 k = [0., k, -k(fix((npad-1)/2):-1:1)];
65 F=exp(-.5*(snorm(ii)^2)*k2); %Thanks to Bing Si for finding a bug here.
66 smooth=ifft(F.*fft(wave(ii,:),npad));
67 twave(ii,:)=smooth(1:n);
71 twave=real(twave); %-------hack-----------
74 %scale smoothing (boxcar with width of .6)
77 % TODO: optimize. Because this is done many times in the monte carlo run.
83 % for ii=1:size(twave,1)
85 % for l=1:size(twave,1);
86 % if ((abs(ii-l)+.5)<=dj0steps)
88 % swave(ii,:)=swave(ii,:)+twave(l,:);
89 % elseif ((abs(ii-l)+.5)<=(dj0steps+1))
90 % fraction=mod(dj0steps,1);
91 % number=number+fraction;
92 % swave(ii,:)=swave(ii,:)+twave(l,:)*fraction;
95 % swave(ii,:)=swave(ii,:)/number;
98 kernel=[mod(dj0steps,1); ones(2 * round(dj0steps)-1,1); ...
99 mod(dj0steps,1)]./(2*round(dj0steps)-1+2*mod(dj0steps,1));
100 swave=conv2(twave,kernel,'same'); %thanks for optimization by Uwe Graichen
109 Rsq=abs(sWxy).^2./(sX.*sY);
112 %varargout={Rsq,period,scale,coi,wtcsig,t};
113 %varargout=varargout(1:nargout);