12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/webplot-do-not-use/util.h:
--------------------------------------------------------------------------------
1 |
2 | void getword(char *word, char *line, char stop);
3 | char *makeword(char *line, char stop);
4 | char *fmakeword(FILE *f, char stop, int *cl);
5 | char x2c(char *what);
6 | void unescape_url(char *url);
7 | void plustospace(char *str);
8 | int rind(char *s, char c);
9 | int getline(char *s, int n, FILE *f);
10 | void send_fd(FILE *f, FILE *fd);
11 | int ind(char *s, char c);
12 | void escape_shell_cmd(char *cmd);
13 |
--------------------------------------------------------------------------------
/wave_matlab/chisquare_solve.m:
--------------------------------------------------------------------------------
1 | function PDIFF = chisquare_solve(XGUESS,P,V);
2 | %CHISQUARE_SOLVE Internal function used by CHISQUARE_INV
3 | %
4 | % PDIFF=chisquare_solve(XGUESS,P,V) Given XGUESS, a percentile P,
5 | % and degrees-of-freedom V, return the difference between
6 | % calculated percentile and P.
7 |
8 | % Uses GAMMAINC
9 | %
10 | % Written January 1998 by C. Torrence
11 |
12 | % extra factor of V is necessary because X is Normalized
13 | PGUESS = gammainc(V*XGUESS/2,V/2); % incomplete Gamma function
14 |
15 | PDIFF = abs(PGUESS - P); % error in calculated P
16 |
17 | TOL = 1E-4;
18 | if (PGUESS >= 1-TOL) % if P is very close to 1 (i.e. a bad guess)
19 | PDIFF = XGUESS; % then just assign some big number like XGUESS
20 | end
21 |
22 | return
23 |
24 | % end of code
25 |
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 1998-2018 Christopher Torrence and Gilbert P. Compo
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/images/morlet.pro:
--------------------------------------------------------------------------------
1 |
2 |
3 | FUNCTION psi,k,t,WAVE_PART=wave_part,AMP_PART=amp_part
4 |
5 | wave_part = COMPLEX(COS(k*t),SIN(k*t)) ; exp(ikt) = cos(kt) + i*sin(kt)
6 | amp_part = EXP( -ABS(t)^2/2.) ; exp(-|t|^2/2)
7 | RETURN,wave_part*amp_part ; morlet
8 |
9 | END
10 |
11 |
12 | k0 = 6.0
13 | time = FINDGEN(401)/20. - 10.
14 |
15 | a = 2
16 | b = 0
17 |
18 | morlet = (1./SQRT(a))*PSI(k0,(time - b)/a,WAVE=wave,AMP=amp)
19 |
20 | WINDOW,0,COLOR=256,XSIZE=512,YSIZE=128
21 | LOADCT,42
22 | !P.BACKGROUND = 255
23 | !P.COLOR = 0
24 | !P.FONT = -1
25 | !P.CHARSIZE = 1.5
26 | !X.STYLE = 5
27 | !Y.STYLE = 5
28 | !P.MULTI = [0,2,1]
29 | !X.MARGIN = [2,2]
30 | !Y.MARGIN = [0,0]
31 | !Y.RANGE = [MIN(FLOAT(wave))*0.95, MAX(amp)*1.05]
32 | dy = (!Y.CRANGE(1) - !Y.CRANGE(0))/5.
33 |
34 | PLOT,time,FLOAT(morlet), $
35 | THICK=2,COLOR=50
36 | XYOUTS,!X.CRANGE(0),!Y.CRANGE(1) - dy,'(a)',CHARSIZE=1.2,ALIGN=0.5
37 |
38 | PLOT,time,FLOAT(wave)/SQRT(2), $
39 | COLOR=128,THICK=2
40 | OPLOT,time,amp,COLOR=208,THICK=2
41 | OPLOT,time,FLOAT(morlet),THICK=2,LINES=2,COLOR=50
42 | XYOUTS,!X.CRANGE(0),!Y.CRANGE(1) - dy,'(b)',CHARSIZE=1.2,ALIGN=0.5
43 |
44 |
45 |
46 | END
47 |
--------------------------------------------------------------------------------
/wave_python/README_python.txt:
--------------------------------------------------------------------------------
1 | ------- Forwarded Message --------
2 | Subject:
3 | Wavelet Python Software
4 | Date: Wed, 24 Dec 2014 00:54:00 +0300
5 | From: Evgeniya Predybaylo gmail.com>
6 | To: chrisrsinc.com, compocolorado.edu
7 | CC: Georgiy Stenchikov kaust.edu.sa>
8 |
9 | Dear Dr. Torrence and Dr. Compo,
10 |
11 | my name is Evgeniya and I am a PhD Student under the supevision of Prof. Georgiy Stenchikov at King Abdullah University of Science and Technology (KAUST).
12 |
13 | I am writing to say a great thank you for the wavelet paper and software you have provided on the website (http://paos.colorado.edu/research/wavelets/). I have found them very useful for my research! However, as I am mostly using Python, I have rewritten the code for Python environment. I have attached two Python files that contain all needed functions and the example, exactly as you have it for the other environments. I hope they can be somehow useful. Please let me know if you encounter any troubles running these codes.
14 |
15 | Thank you for your time and attention!
16 |
17 | Sincerely,
18 |
19 | Evgeniya Predybaylo
20 |
21 | --
22 | PhD Student, Earth Sciences and Engineering Program
23 | Chair of Graduate Student Council
24 | King Abdullah University of Science and Technology
25 |
--------------------------------------------------------------------------------
/applications.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Wave:Applications
5 |
6 |
7 |
8 |
9 |
Wavelet Applications
10 |
11 |
12 |
13 |
14 |
15 |
Image processing [Mallat (1988)]
16 |
17 |
Irregularly-spaced data (stellar activity)
18 | [Frick et al. (1997)]
19 |
Wavelet bases for partial differential equations
31 | [Farge et al. (1992), Bacry et al. (1993)]
32 |
33 |
34 |
Paleoclimate [Bolton et al. (1995), Yiou et al. (1995)]
35 |
36 |
37 |
38 |
Summary
39 |
40 |
41 |
42 |
¤
Wavelet analysis is a useful addition to methods of
43 | geophysical data analysis.
44 |
¤
Most helpful in situations of locally-coherent signals,
45 | or non-stationary time series.
46 |
¤
More research is needed on the perils & pitfalls,
47 | choice of wavelet bases, and on statistical significance.
48 |
49 |
50 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/images/wave_bias_faq.pro:
--------------------------------------------------------------------------------
1 |
2 | dt = 1
3 | n = 128
4 | t = FINDGEN(n)*dt
5 | t1 = 8
6 | t2 = 32
7 | x = SIN(2*!PI*t/t1) + SIN(2*!PI*t/t2)
8 | ; x = RANDOMN(s,n)
9 |
10 | f = SPECTRUM(x,dt,PERIOD=fperiod)
11 | w = WAVELET(x,dt,PERIOD=wperiod,DJ=0.125)
12 | gws = TOTAL(ABS(w)^2,1)/n^2
13 |
14 | WINDOW,XSIZE=240,YSIZE=350
15 | LOADCT,39
16 | !P.COLOR = 192
17 | !P.MULTI = [0,1,3]
18 | !X.STYLE = 9
19 | !Y.STYLE = 9
20 | !X.MARGIN = [8,2]
21 | !Y.MARGIN = [4,3]
22 | !Y.MINOR = 1
23 | !X.TICKLEN = -0.04
24 | !P.CHARSIZE = 1.75
25 | xticks = FIX(ALOG(n)/ALOG(2))-1
26 | xtickv = 2L^(LINDGEN(xticks+1)+1)
27 | xrange = [MAX(xtickv),MIN(xtickv)]
28 |
29 | PLOT,t,x, $
30 | XRANGE=[0,n], $
31 | XMINOR=1,XTICKS=xticks-2, $
32 | XTITLE='Time (days)', $
33 | TITLE='Time series with two sine waves'
34 | OPLOT,t,x,COLOR=254
35 |
36 | PLOT,fperiod,f,/XTYPE, $
37 | XRANGE=xrange,YRANGE=[0,0.5],YTICKS=2, $
38 | XTICKS=xticks,XTICKV=xtickv, $
39 | XTITLE='Period (days)',YTITLE='Power', $
40 | TITLE='Fourier power spectrum'
41 | OPLOT,fperiod,f,PSYM=-4,/NOCLIP,COLOR=254,SYMSIZE=0.75
42 |
43 | PLOT,wperiod,gws,/XTYPE, $
44 | XRANGE=xrange,YRANGE=[0,0.25],YTICKS=2, $
45 | XTICKS=xticks,XTICKV=xtickv, $
46 | XTITLE='Period (days)',YTITLE='Power', $
47 | TITLE='Global wavelet spectrum'
48 | OPLOT,wperiod,gws,PSYM=-4,/NOCLIP,COLOR=254,SYMSIZE=0.75
49 |
50 | TVLCT,r,g,b,/GET
51 | WRITE_GIF,'wave_bias_faq.gif',TVRD(),r,g,b
52 | END
53 |
--------------------------------------------------------------------------------
/wave_matlab/chisquare_inv.m:
--------------------------------------------------------------------------------
1 | function X = chisquare_inv(P,V);
2 | %CHISQUARE_INV Inverse of chi-square cumulative distribution function (cdf).
3 | %
4 | % X = chisquare_inv(P,V) returns the inverse of chi-square cdf with V
5 | % degrees of freedom at fraction P.
6 | % This means that P*100 percent of the distribution lies between 0 and X.
7 | %
8 | % To check, the answer should satisfy: P==gammainc(X/2,V/2)
9 |
10 | % Uses FMIN and CHISQUARE_SOLVE
11 | %
12 | % Written January 1998 by C. Torrence
13 |
14 | if (nargin < 2), error('Must input both P and V');, end
15 | if ((1-P) < 1E-4), error('P must be < 0.9999');, end
16 |
17 | if ((P==0.95) & (V==2)) % this is a no-brainer
18 | X = 5.9915;
19 | return
20 | end
21 |
22 | MINN = 0.01; % hopefully this is small enough
23 | MAXX = 1; % actually starts at 10 (see while loop below)
24 | X = 1;
25 | TOLERANCE = 1E-4; % this should be accurate enough
26 | vers = version;
27 | vers = str2num(vers(1));
28 |
29 | while ((X+TOLERANCE) >= MAXX) % should only need to loop thru once
30 | MAXX = MAXX*10.;
31 | % this calculates value for X, NORMALIZED by V
32 | % Note: We need two different versions, depending upon the version of Matlab.
33 | if (vers >= 6)
34 | X = fminbnd('chisquare_solve',MINN,MAXX,optimset('TolX',TOLERANCE),P,V);
35 | else
36 | X = fmin('chisquare_solve',MINN,MAXX,[0,TOLERANCE],P,V);
37 | end
38 | MINN = MAXX;
39 | end
40 |
41 | X = X*V; % put back in the goofy V factor
42 |
43 | return
44 |
45 | % end of code
46 |
47 |
--------------------------------------------------------------------------------
/errata.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Torrence and Compo (1998): Errata
5 |
6 |
7 |
8 |
9 | Bulletin of the American Meteorological Society:
10 | Vol. 79, No. 1, pp. 6178.
11 |
12 |
13 |
A Practical Guide to Wavelet Analysis
14 |
15 | Christopher Torrence and Gilbert P. Compo Program in
16 | Atmospheric and Oceanic Sciences, University of Colorado,
17 | Boulder, Colorado
18 |
19 | Errata
20 |
21 |
22 |
23 |
24 |
25 |
Figure 3: N/(2 sigma2) should just be N/sigma2.
26 |
Equation (17), left-hand side: Factor of 1/2
27 | should be removed.
28 |
Table 1, DOG, Psi-hat (third column, bottom row):
29 | Should be a minus sign in front of the equation.
30 |
Sec 3f, last paragraph: Plugging N=506, dt=1/4yr, s0=2dt, and dj=0.125
31 | into Eqn (10) actually gives J=64, not J=56 as stated in the text.
32 | However, in Figure 1b, the scales are only plotted
33 | out to J=56 since the power is so low at larger scales.
34 |
35 |
36 |
37 |
38 |
39 | Additional information
40 |
41 | Table 3: Cross-wavelet significance levels, from Eqn.(30)-(31).
42 | (DOF = degrees of freedom)
43 |
46 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Torrence & Compo Wavelet Analysis Software
2 |
3 | http://atoc.colorado.edu/research/wavelets/
4 |
5 | # Papers
6 |
7 | ### [Torrence & Compo 1998](bams_79_01_0061.pdf)
8 | A practical step-by-step guide to wavelet analysis is given, with examples taken from time series of the El Niño-Southern Oscillation (ENSO). The guide includes a comparison to the windowed Fourier transform, the choice of an appropriate wavelet basis function, edge effects due to finite-length time series, and the relationship between wavelet scale and Fourier frequency. New statistical significance tests for wavelet power spectra are developed by deriving theoretical wavelet spectra for white and red noise processes and using these to establish significance levels and confidence intervals. Extensions to wavelet analysis such as filtering, the power Hovmöller, cross-wavelet spectra, and coherence are described.
9 |
10 | ### [Torrence & Webster 1999](interdecadal.pdf)
11 | The method of wavelet coherency is applied to the ENSO and monsoon indexes.
12 |
13 | # IDL, Matlab, Fortran Code
14 |
15 | Please acknowledge the use of this software in any publications:
16 | ```
17 | "Wavelet software was provided by C. Torrence and G. Compo, and is available at URL: http://atoc.colorado.edu/research/wavelets/".
18 | ```
19 | Please send a copy of such publications to:
20 | ```
21 | chris.torrence[AT]l3harris[DOT]com
22 | compo[AT]colorado[DOT]edu
23 | ```
24 |
25 | # Python Code
26 | Wavelet analysis code translated to Python and provided here courtesy of:
27 | ```
28 | Evgeniya Predybaylo
29 | predybaylo[DOT]evgenia[AT]gmail[DOT]com
30 | Earth Sciences and Engineering Program
31 | King Abdullah University of Science and Technology
32 | Kingdom of Saudi Arabia
33 | ```
34 | Please include the following acknowledgement in any publication:
35 | ```
36 | "Python wavelet software provided by Evgeniya Predybaylo based on Torrence and Compo (1998) and is available at URL: "http://atoc.colorado.edu/research/wavelets/"
37 | ```
38 |
39 | # Datasets
40 | * NINO3 sea surface temperature 1871-1996 (in °C; from the UKMO GISST2.3)
41 | - Seasonally-averaged, minus the annual cycle
42 | - Monthly-averaged, raw data and anomalies
43 | * Southern Oscillation Index
44 | * All-India Monsoon Rainfall
45 | * Mauna Loa CO2
46 | * Wolf Sunspot Number
47 |
--------------------------------------------------------------------------------
/analysis.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Wave:Data Analysis
5 |
6 |
7 |
8 |
9 |
Geophysical Data Analysis
10 |
11 |
12 |
13 |
14 | ¤ To reduce a set of time series to a few parameters that
15 | capture a large variance percentage, and,
16 | ¤ To use these dominant parameters to explain the
17 | behavior of the time series.
18 |
73 |
77 |
78 | * Permission to place a copy of this work on this
79 | server has been provided by the
80 | American Meteorological Society.
81 | The AMS does not guarantee that the copy provided
82 | here is an accurate copy of the published work.
83 |
84 |
85 |
--------------------------------------------------------------------------------
/wave_matlab/wave_bases.m:
--------------------------------------------------------------------------------
1 | %WAVE_BASES 1D Wavelet functions Morlet, Paul, or DOG
2 | %
3 | % [DAUGHTER,FOURIER_FACTOR,COI,DOFMIN] = ...
4 | % wave_bases(MOTHER,K,SCALE,PARAM);
5 | %
6 | % Computes the wavelet function as a function of Fourier frequency,
7 | % used for the wavelet transform in Fourier space.
8 | % (This program is called automatically by WAVELET)
9 | %
10 | % INPUTS:
11 | %
12 | % MOTHER = a string, equal to 'MORLET' or 'PAUL' or 'DOG'
13 | % K = a vector, the Fourier frequencies at which to calculate the wavelet
14 | % SCALE = a number, the wavelet scale
15 | % PARAM = the nondimensional parameter for the wavelet function
16 | %
17 | % OUTPUTS:
18 | %
19 | % DAUGHTER = a vector, the wavelet function
20 | % FOURIER_FACTOR = the ratio of Fourier period to scale
21 | % COI = a number, the cone-of-influence size at the scale
22 | % DOFMIN = a number, degrees of freedom for each point in the wavelet power
23 | % (either 2 for Morlet and Paul, or 1 for the DOG)
24 | %
25 | %----------------------------------------------------------------------------
26 | % Copyright (C) 1995-1998, Christopher Torrence and Gilbert P. Compo
27 | % University of Colorado, Program in Atmospheric and Oceanic Sciences.
28 | % This software may be used, copied, or redistributed as long as it is not
29 | % sold and this copyright notice is reproduced on each copy made. This
30 | % routine is provided as is without any express or implied warranties
31 | % whatsoever.
32 | %----------------------------------------------------------------------------
33 | function [daughter,fourier_factor,coi,dofmin] = ...
34 | wave_bases(mother,k,scale,param);
35 |
36 | mother = upper(mother);
37 | n = length(k);
38 |
39 | if (strcmp(mother,'MORLET')) %----------------------------------- Morlet
40 | if (param == -1), param = 6.;, end
41 | k0 = param;
42 | expnt = -(scale.*k - k0).^2/2.*(k > 0.);
43 | norm = sqrt(scale*k(2))*(pi^(-0.25))*sqrt(n); % total energy=N [Eqn(7)]
44 | daughter = norm*exp(expnt);
45 | daughter = daughter.*(k > 0.); % Heaviside step function
46 | fourier_factor = (4*pi)/(k0 + sqrt(2 + k0^2)); % Scale-->Fourier [Sec.3h]
47 | coi = fourier_factor/sqrt(2); % Cone-of-influence [Sec.3g]
48 | dofmin = 2; % Degrees of freedom
49 | elseif (strcmp(mother,'PAUL')) %-------------------------------- Paul
50 | if (param == -1), param = 4.;, end
51 | m = param;
52 | expnt = -(scale.*k).*(k > 0.);
53 | norm = sqrt(scale*k(2))*(2^m/sqrt(m*prod(2:(2*m-1))))*sqrt(n);
54 | daughter = norm*((scale.*k).^m).*exp(expnt);
55 | daughter = daughter.*(k > 0.); % Heaviside step function
56 | fourier_factor = 4*pi/(2*m+1);
57 | coi = fourier_factor*sqrt(2);
58 | dofmin = 2;
59 | elseif (strcmp(mother,'DOG')) %-------------------------------- DOG
60 | if (param == -1), param = 2.;, end
61 | m = param;
62 | expnt = -(scale.*k).^2 ./ 2.0;
63 | norm = sqrt(scale*k(2)/gamma(m+0.5))*sqrt(n);
64 | daughter = -norm*(i^m)*((scale.*k).^m).*exp(expnt);
65 | fourier_factor = 2*pi*sqrt(2./(2*m+1));
66 | coi = fourier_factor/sqrt(2);
67 | dofmin = 1;
68 | else
69 | error('Mother must be one of MORLET,PAUL,DOG')
70 | end
71 |
72 | return
73 |
74 | % end of code
75 |
76 |
--------------------------------------------------------------------------------
/webplot-do-not-use/waveploteqn.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Wave:Interactive Wavelets:Choose data
5 |
6 |
7 |
8 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/references.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Wave:Wavelet: References
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
Wavelet Analysis
13 |
References:
14 |
15 | Chatfield, C., 1989: The Analysis of Time Series.
16 | Chapman & Hall, London.
17 |
18 | Farge, M., 1992: Wavelet transforms and their
19 | applications to turbulence.
20 | Ann. Rev. Fluid Mech., 24, 395-457.
21 |
22 | Gilman, D.L., F.J. Fuglister, and J.M. Mitchell, Jr.,
23 | 1963: On the power spectrum of "red noise".
24 | J. Atmos. Sci., 20, 182-184.
25 |
26 | Jenkins, G.M. and D.G. Watts, 1968: Spectral
27 | Analysis and its Applications.
28 | Holden-Day, San Francisco.
29 |
30 | Lau, K.-M. and H.-Y. Weng, 1995: Climate signal
31 | detection using wavelet transform: How to make a time series sing.
32 | Bull. Am. Meteor. Soc, 76, 2391-2402.
33 |
34 | Meyers, S.D., B.G. Kelly, and J.J. O'Brien, 1993: An
35 | introduction to wavelet analysis in oceanography and meteorology: With
36 | application to the dispersion of Yanai waves.
37 | Mon. Wea. Rev., 121, 2858-2866.
38 |
39 | Spiegel, M.R., 1975: Schaum's Outline of Theory and
40 | Problems of Probability and Statistics. McGraw-Hill, New York.
41 |
42 | Torrence, C. and G.P. Compo, 1998: A Practical Guide to Wavelet Analysis.
43 | Bull. Amer. Meteor. Soc., 79, 61-78.
44 |
45 | Weng, H. and K.-M. Lau, 1994: Wavelets, period
46 | doubling, and time-frequency localization with application to organization of
47 | convection over the tropical western Pacific.
48 | J. Atmos. Sci., 51, 2523-2541.
``On these web pages [Grinsted, Moore, and Jevrejeva] provide downloads for a MatLab package for performing Crosswavelet and Wavelet coherence analysis.''
69 |
10 | Bulletin of the American Meteorological Society:
11 | Vol. 79, No. 1, pp. 6178.
12 |
13 |
14 |
A Practical Guide to Wavelet Analysis
15 |
16 | Christopher Torrence and Gilbert P. Compo Program in Atmospheric
17 | and Oceanic Sciences, University of Colorado, Boulder, Colorado
18 |
19 |
20 |
21 | Keywords: Wavelet analysis, significance and confidence testing,
22 | red noise power spectrum, El Niño-Southern Oscillation.
23 |
24 |
25 |
26 | Abstract
27 |
28 |
29 | A practical step-by-step guide to wavelet analysis is given, with
30 | examples taken from time series of the
31 | El Niño-Southern Oscillation (ENSO). The guide includes a
32 | comparison to the windowed Fourier transform, the choice of an
33 | appropriate wavelet basis function, edge effects due to finite-length
34 | time series, and the relationship between wavelet scale and Fourier
35 | frequency. New statistical significance tests for wavelet power spectra
36 | are developed by
37 | deriving theoretical wavelet spectra for white and red noise
38 | processes and using these to establish significance levels and
39 | confidence intervals. It is shown that smoothing in time or scale
40 | can be used to increase the confidence of the wavelet spectrum.
41 | Empirical formulae are given for the effect of smoothing on significance levels
42 | and confidence intervals. Extensions to wavelet
43 | analysis such as filtering, the power
44 | Hovmöller, cross-wavelet spectra, and coherence are described.
45 |
46 | The statistical significance tests are used to give a quantitative
47 | measure of changes in ENSO variance on interdecadal time scales.
48 | Using new datasets that extend back to 1871, the Niño3 sea surface
49 | temperature and the Southern Oscillation Index show
50 | significantly higher power during 18801920 and 196090, and
51 | lower power during 192060, as well as
52 | a possible 15-yr modulation of variance. The power Hovmöller
53 | of sea level pressure shows significant variations in 28-yr
54 | wavelet power in both longitude and time.
55 |
56 |
57 |
58 |
Introduction
59 |
Data
60 |
Wavelet Analysis
61 |
62 |
Windowed Fourier Transform
63 |
Wavelet Transform
64 |
Normalization
65 |
Wavelet Power Spectrum
66 |
Wavelet Functions
67 |
Choice of Scales
68 |
Cone of Influence (COI)
69 |
Wavelet Scale and Fourier Frequency
70 |
Reconstruction
71 |
72 |
Theoretical Spectrum and Significance Levels
73 |
74 |
Python**
52 | waveletAnalysis.py
53 | waveletFunctions.py
54 | sst_nino3.dat
55 | README_python.txt
56 |
57 | ** Wavelet analysis codes
58 | translated to Python and provided
59 | here courtesy of
60 | Evgeniya Predybaylo
61 | predybaylo[DOT]evgenia[AT]gmail[DOT]com
62 | Earth Sciences and Engineering Program
63 | King Abdullah University
64 | of Science and Technology
65 | Kingdom of Saudi Arabia
66 |
67 | Please include the following
68 | acknowledgement in any publication
69 | "Python wavelet software provided by
70 | Evgeniya Predybaylo based on
71 | Torrence and Compo (1998)
72 | and is available at URL:
73 | http://atoc.colorado.edu/research/wavelets/"
74 |
75 |
97 | * Notice: Please acknowledge the use of this software in any publications:
98 |
99 | ``Wavelet software was provided by C. Torrence and G. Compo, and is available at
100 | URL: http://atoc.colorado.edu/research/wavelets/''.
101 |
102 | Please send a copy of such publications to either C. Torrence or G. Compo:
103 |
104 |
105 |
106 |
107 | Dr. Christopher Torrence
108 | Exelis
109 | 4990 Pearl East Circle
110 | Boulder, CO 80301, USA
111 | E-mail: chris.torrence[AT]exelisinc[DOT]com
112 |
113 |
114 |
115 | Dr. Gilbert P. Compo
116 | CIRES, University of Colorado & Physical Sciences Division, NOAA ESRL
117 | Campus Box 216
118 | University of Colorado
119 | Boulder CO 80309-0216, USA.
120 | E-mail: compo[AT]colorado[DOT]edu
121 |
122 |
34 | Important Note: When applying the significance
35 | and confidence tests from
36 | "A Practical Guide to Wavelet Analysis",
37 | you do not need to use a Monte Carlo simulation.
38 | Analytical formulae are given in the paper for the statistical distribution
39 | of wavelet power. These formulae are correct, assuming that
40 | the underlying distribution of the original time series is Gaussian.
41 |
42 | The following description of Monte Carlo is given for those who want
43 | more background on the method, or if your time series cannot be assumed
44 | to be Gaussian.
45 |
46 |
47 |
48 | Gaussian distribution
49 |
50 |
51 |
52 |
53 |       The Monte Carlo method (or simulation) was used
54 | in "A Practical Guide to Wavelet Analysis"
55 | to verify that the wavelet power spectrum was indeed chi-square distributed.
56 | The method was also used to determine the empirical formulae for
57 | time-averaging and scale-averaging (paper Sections 5a and 5b).
58 |
59 |       The Monte Carlo method (or simulation) is a
60 | statistical method for finding out the answer to a problem that is
61 | too difficult to solve analytically,
62 | or for verifying the analytical solution. It is called Monte Carlo because
63 | of the gambling casinos in that city, and because the Monte
64 | Carlo method is related to rolling dice.
65 |
If you roll two dice, then
75 | the chances of getting a total of "two" (a "one" on each) are 1 in
76 | 36. This is easy to figure out. But if you didn't know the answer,
77 | you could use the Monte Carlo method. You just roll two dice
78 | thousands of times, and add up how many times you got a total of
79 | "two". Eventually, your fraction of "two's" to "total rolls" will
80 | approach 1/36.
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |       In our paper, we wanted to verify that the
90 | statistical distribution for the wavelet power was chi-square.
91 | Here's the Monte Carlo method we used:
92 |
93 |
We created 100,000 random time series, each with 512 points.
94 |
95 |
Then we took the wavelet transform for each one,
96 | and computed the wavelet power.
97 |
98 |
We then took a time slice from the middle (time n=256),
99 |
100 |
At each scale, we sorted all 100,000 wavelet powers into
101 | increasing order.
102 |
103 |
You can then make a plot of wavelet power versus number.
104 |
105 |
If you then look at what the wavelet power was for
106 | number 95,000 out of 100,000, then 95% of the wavelet power
107 | is below that value, and only 5% is above.
108 |
109 |
This 95% level is the 95% confidence level
110 | (or the 5% significance level).
111 |
112 | The method can be generalized to any process where
113 | the statistical distribution is unknown, yet one needs to determine
114 | confidence or significance levels.
115 |
29 |
30 | Many time series in geophysics exhibit non-stationarity in their
31 | statistics. While the series may contain dominant periodic signals,
32 | these signals can vary in both amplitude and frequency over long
33 | periods of time.
34 |
35 | An example would be sea surface temperatures in the
36 | equatorial Pacific Ocean (Figure 1).
37 | The dominant "mode" of variability is the
38 | El Niño-Southern Oscillation (ENSO), shown by the high-frequency
39 | "spikes" on a time scale of 2-7 years.
40 | Superimposed on this signal are much longer interdecadal fluctuations.
41 | The interdecadal fluctuations have the effect of modulating the
42 | amplitude and frequency of occurance of El Niño events.
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | Fig. 1.
55 |
Sea surface temperatures averaged over the NINO3 region
56 | in the eastern Pacific (5°S-5°N, 90°W-150°W).
57 | Blue curve is low-pass filtered (>12 months) SST.
58 | Yellow background curve is running 15-year variance, plotted
59 | at mid-point of 15-year period. Curve has been reproduced upside-down
60 | to show "envelope" of variance.
61 |
62 |
63 |
64 |
65 | Ideally, one would like to separate the shorter period
66 | oscillations from the longer.
67 | [Note: the word "oscillation" is used here to indicate
68 | any repeating fluctuation in the timeseries, regardless of whether
69 | the fluctuation repeats on a regular basis or not. In our example the
70 | El Niño is definitely an aperiodic (irregular) signal.]
71 |
72 | The simplest method for analyzing non-stationarity
73 | of a timeseries would be to compute statistics such as the
74 | mean and variance
75 | for different time periods and see if they are significantly different.
76 | In Figure 1 we have also plotted the running 15-year variance, as
77 | a measure of total power inherent in the signal versus time.
78 | One can see that ENSO had more variance during 1880-1920
79 | and also since 1950,
80 | with a relatively quiet period during 1920-1950.
81 |
82 |
83 | While the running variance tells
84 | us what the overall strength of the
85 | signal was at certain times, it suffers from two major defects:
86 |
87 |
88 |
[Time Localization]
89 | The shape of the curve is highly dependent on the length of
90 | the window used. Fifteen years was chosen above as a compromise between
91 | either too-much smoothness (say using a 30-year window),
92 | or too-little (a 5-year window). An ideal method would allow different
93 | window sizes depending on the scales that one is interested in.
94 |
95 |
96 |
[Frequency Localization]
97 | The running variance contains no information on the frequency
98 | of a periodic signal,
99 | only its amplitude (and that only if the window is chosen widely).
100 |
101 |
102 | One possibility would be to do a windowed (or
103 | running) Fourier transform (WFT), using a certain window size and
104 | sliding it along in time, computing the FFT at each time using only
105 | the data within the window. This would solve the second problem
106 | (frequency localization), but would still be dependent on the window
107 | size used. The main problem with the WFT is the inconsistent treatment
108 | of different frequencies: at low frequencies there so few oscillations
109 | within the window that the frequency localization is lost, while at
110 | high frequencies there are so many oscillations that the time
111 | localization is lost. Finally, the WFT relies on the assumption that
112 | the signal can be decomposed into sinusoidal components.
113 |
114 |
115 | Wavelet analysis attempts to solve these problems by
116 | decomposing a timeseries into time/frequency space simultaneously.
117 | One gets information on both the amplitude of any "periodic" signals
118 | within the series, and how this amplitude varies with time.
119 |
29 |
30 |       In the previous section
31 | we saw how one can use a typical wavelet (the Morlet) to decompose
32 | a time series into time-frequency phase space. We now turn to the actual
33 | computation of the wavelet transform.
34 |
35 |
36 |       The first thing to consider is the shape of the wavelet.
37 | For decomposing the NINO3 SST data, we chose the Morlet wavelet because:
38 |
39 |
it is commonly used,
40 |
it's simple,
41 |
it looks like a wave.
42 |
43 | There are an infinite number of other mother wavelets that could be chosen
44 | (see Farge 1992 for examples).
45 |
46 |
47 |       For the Morlet wavelet transform, where the mother
48 | wavelet is:
49 |
50 |
51 |
52 |
53 |
54 | we must first choose the wavenumber w0, which gives
55 | the number of oscillations within the wavelet itself. One condition
56 | of the wavelet transform is that the average of the wavelet itself
57 | must be zero. In practice, if we choose w0=6, then
58 | the errors due to non-zero mean are smaller than the typical computer
59 | round-off errors (Farge 1992).
60 |
61 |
62 |       Our next choice is a set of scaling parameters s,
63 | such that we adequately sample all the frequencies present in our
64 | time series. We first choose the smallest resolvable scale,
65 | s0, as some multiple of our time resolution, dt.
66 | For the NINO3 SST data, we have seasonal data, thus dt = 0.25 years.
67 | The smallest wavelet we could possibly resolve is 2dt, thus
68 | we choose s0 = 2dt = 0.5 years.
69 |
70 | The larger scales (longer periods) are chosen as power-of-two multiples
71 | of this smallest scale,
72 |
73 |
81 |
82 | The largest scale chosen should be less than 1/2 the length of the
83 | entire time series. The choice of scales for the NINO3 SST data is
84 | shown on the right-hand axis of Figure 3.
85 | In theory, if these scales are chosen wisely, then one
86 | can construct an orthogonal complete basis set. In reality, one usually
87 | over-samples the scales so as to provide information on
88 | freqencies in between the orthogonal scales. Thus, in Figure 3, the
89 | scales have been over-sampled by choosing 10 sub-scales within each
90 | scale.
91 |
120 |
121 | To use this formula,
122 | the FT of the wavelet function should be known analytically.
123 | In addition, the wavelets must be normalized as:
124 |
125 |
126 | (3.4) . . . . . . . . . .
127 |
128 |
129 |
130 | Unlike the convolution, the FFT method allows the computation of
131 | all n points simultaneously, and can be efficiently coded using
132 | any standard FFT package.
133 |
134 |
135 |       The steps to compute the wavelet transform for a time
136 | series are thus:
137 |
138 |
Choose a mother wavelet,
139 |
Find the Fourier transform of the mother wavelet,
140 |
Find the Fourier transform of the time series,
141 |
Choose a minimum scale s0, and all other scales,
142 |
For each scale, do:
143 |
144 |
Using Eqn. 3.4 (or whatever is appropriate for your
145 | mother wavelet), compute the daughter wavelet at that scale;
146 |
Normalize the daughter wavelet by dividing by the square-root
147 | of the total wavelet variance (the total of
148 | (Psi)2 should then be one, thus preserving
149 | the variance of the time series);
150 |
Multiply by the FT of your time series;
151 |
Using Eqn. 3.2, inverse transform back to real space;
152 |
153 |
Make a contour plot.
154 |
155 |
156 |
157 |       One problem with performing the wavelet transform in
158 | Fourier space is that this assumes the time series is periodic. The
159 | result is that signals in the wavelet transform at one end of the
160 | time series will get wrapped around to the other end. This effect
161 | is more pronouced at larger scales as the influence of each wavelet
162 | extends further in time. One way to avoid this is to pad one end of the
163 | time series with zeroes. A clever method is to pad with enough zeroes
164 | to make the length of the time series equal to a power of two, and
165 | thereby speed up the FFT as well.
166 |
'
17 | # IF (N_ELEMENTS(errors) GT 1) THEN FOR i=0,N_ELEMENTS(errors)-1 DO PRINTF,outf,errors(i)
18 | # IF (N_ELEMENTS(errors) LE 1) THEN IF (postscript) THEN PRINTF,outf,str2 ELSE PRINTF,outf,str1
19 |
20 | # IF (N_ELEMENTS(errors) GT 1) THEN PRINTF,outf,'
21 |
22 | Fig. 1: (a)
23 | # str1 = '.'
24 | # IF (source NE '') THEN str1 = ' (from ' + source + ')' + str1
25 | # PRINTF,outf,'Time series'
26 | # PRINTF,outf,' of ' + dataset1 + str1
27 |
28 |
29 | (b) The wavelet power spectrum.
30 |
31 | # str1 = 'The power has been scaled by the global wavelet spectrum (at right).'
32 | # str2 = 'The contour levels are chosen so that 75%, 50%, 25%, and 5% of the wavelet power is above each level, respectively.
33 | # IF (gws) THEN PRINTF,outf,str1 ELSE PRINTF,outf,str2
34 |
35 | # str1 = 'Cross-hatched region is the cone of influence, where zero padding has reduced the variance.'
36 | # IF (coi1) THEN PRINTF,outf,str1
37 |
38 | # background_str = 'using a white-noise background spectrum'
39 | # lag1_string = ' lag1=' + ROUND_ANY(lag1)
40 | # IF (lag1 GT 0.0) THEN background_str = 'using a red-noise (autoregressive' + lag1_string + ') background spectrum'
41 | # background_str = [background_str,'using the global wavelet spectrum as the background']
42 |
43 | # str1 = 'Black contour is the '+ROUND_ANY(siglvl)+'% significance level, '
44 | # IF (siglvl NE 0) THEN PRINTF,outf,str1+background_str[do_global]+'.'
45 |
46 | # str1 = '(c) The global wavelet power spectrum
47 | # str2 = ' (black line). The dashed line is the '+ROUND_ANY(siglvl)+'% significance level for the global wavelet spectrum, '
48 | # str2 = str2 + background_str[0]
49 | # IF ((siglvl NE 0) AND (N_ELEMENTS(globalsignif) GT 1)) THEN str1 = str1 + str2
50 | # PRINTF,outf,str1+'.'
51 |
52 | # IF (N_ELEMENTS(errors) GT 1) THEN PRINTF,outf,'-->' ;comment out the caption
53 |
54 |
29 |
30 |       In the previous section
31 | we saw how one measure of the stationarity
32 | of a time series was to calculate the running variance
33 | using a fixed-width window. Although we pointed out the disadvantage
34 | of using a fixed-width window, one could repeat
35 | the analysis with a variety of window widths. By smoothly varying the
36 | window width one could then build a picture of the changes in variance
37 | versus both time and window width. The obvious problem with this
38 | technique is the simple "boxcar" shape of the window function, which
39 | introduces edge effects such as ringing. As mentioned earlier, using
40 | such a black-box-car, we still have no information on what is going on
41 | within the box, but only recover the average energy.
42 |
43 |
44 |       In Figure 2a we see an example of a wave "packet", of finite duration
45 | and with a specific frequency. One could imagine using such a shape
46 | as our window function for our analysis of variance. This "wavelet"
47 | has the advantage of incorporating a wave of a certain period, as
48 | well as being finite in extent. In fact, the wavelet shown in Figure 2a
49 | (called the Morlet wavelet) is nothing more than a Sine wave
50 | (green curve in Figure 2b) multiplied by a Gaussian envelope (red curve).
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | Fig 2.
62 |
(a) Morlet wavelet of arbitrary width and amplitude,
63 | with time along the x-axis. (b) Construction of the Morlet
64 | wavelet (blue dashed) as a Sine curve (green) modulated by
65 | a Gaussian (red).
66 |
67 |
68 |
69 |
70 |       Assuming that the total width of this wavelet is about 15 years,
71 | we can find the correlation
72 | between this curve and the first 15 years
73 | of our time series shown in
74 | Figure 1.
75 | This single number gives us a
76 | measure of the projection of this wave packet on our data during
77 | the 1876-1890 period, i.e. how much [amplitude] does our 15-year
78 | period resemble a Sine wave of this width [frequency]. By sliding this
79 | wavelet along our time series one can then construct a new time series
80 | of the projection amplitude versus time.
81 |
82 |
83 |       Finally, one can then vary the "scale" of the wavelet by changing
84 | its width. This is the real advantage of wavelet analysis over
85 | a moving Fourier spectrum.
86 | For a window of a certain width, the sliding FFT
87 | is fitting different numbers of waves, i.e. there can be many
88 | high-frequency waves within a window, while the same window can only
89 | contain a few (or less than one) low-frequency waves. The wavelet analysis
90 | always uses a wavelet of the exact same shape, only the size scales up
91 | or down with the size of the window.
92 |
117 |
118 | where s is the "dilation" parameter used to change the scale,
119 | and n is the translation parameter used to slide in time.
120 | The factor of s-1/2 is a normalization to keep the total
121 | energy of the scaled wavelet constant.
122 |
136 |
137 | where the asterisk (*) denotes complex conjugate.
138 |
139 |
140 |       The above integral can be evaluated for
141 | various values of the scale s
142 | (usually taken to be multiples of the lowest possible frequency),
143 | as well as all values of n between the start and end dates.
144 | A two-dimensional picture of the variability can then be constructed
145 | by plotting the wavelet amplitude and phase.
146 |
147 |
148 |
149 |       Figure 3 shows the power (absolute value
150 | squared) of the wavelet transform for the NINO3 SST data.
151 | The (absolute value)2 gives information on the relative
152 | power at a certain scale and a certain time.
153 | A plot of the amplitude and phase
154 | would show the actual oscillations of the individual wavelets, rather
155 | than just their magnitude.
156 |
157 |
158 |
159 |
160 |
162 |
163 |
164 |
165 |
166 |
167 | Fig 3.
168 |
(a) Time series of El Niño sea surface temperature.
169 | (b) The wavelet power spectrum, using the Morlet wavelet.
170 | The x-axis is the wavelet location in time.
171 | The y-axis is the wavelet period in years.
172 | The black contours are the 10% significance regions, using a
173 | red-noise background spectrum.
174 | The red areas indicate that high El Niño activity
175 | occurred during 1880-1920 and 1965-present, while 1920-1960
176 | was relatively calm.
177 |
178 |
179 |
180 |
181 |       Comparing Figures 1 and 3
182 | it is now much clearer that there
183 | was large power in the 2-7 year ENSO period during both the earlier
184 | and latter parts of this century.
185 | In addition we can now see hints of a 16-year
186 | oscillation as well as power at even lower frequencies.
187 |
188 |
189 |       The wavelet transform also gives information on changes in frequency
190 | that may have occured. Thus, from 1960-1990
191 | the ENSO time band (2-7 years) seems to have undergone a slow oscillation
192 | in period from a 3-year period between events back in 1965 up to
193 | about a 5-year period in the early 1980s.
194 |
201 |
202 |
203 | back to Wavelet Home Page
204 |
205 |
206 |
207 |
--------------------------------------------------------------------------------
/wave_idl/wave_signif.pro:
--------------------------------------------------------------------------------
1 | ;************************************************************** WAVE_SIGNIF
2 | ;+
3 | ; NAME: WAVE_SIGNIF
4 | ;
5 | ; PURPOSE: Compute the significance levels for a wavelet transform.
6 | ;
7 | ;
8 | ; CALLING SEQUENCE:
9 | ;
10 | ; result = WAVE_SIGNIF(y,dt,scale,sigtest)
11 | ;
12 | ;
13 | ; INPUTS:
14 | ;
15 | ; Y = the time series, or, the VARIANCE of the time series.
16 | ; (If this is a single number, it is assumed to be the variance...)
17 | ;
18 | ; DT = amount of time between each Y value, i.e. the sampling time.
19 | ;
20 | ; SCALE = the vector of scale indices, from previous call to WAVELET.
21 | ;
22 | ; SIGTEST = 0, 1, or 2. If omitted, then assume 0.
23 | ;
24 | ; If 0 (the default), then just do a regular chi-square test,
25 | ; i.e. Eqn (18) from Torrence & Compo.
26 | ; If 1, then do a "time-average" test, i.e. Eqn (23).
27 | ; In this case, DOF should be set to NA, the number
28 | ; of local wavelet spectra that were averaged together.
29 | ; For the Global Wavelet Spectrum, this would be NA=N,
30 | ; where N is the number of points in your time series.
31 | ; If 2, then do a "scale-average" test, i.e. Eqns (25)-(28).
32 | ; In this case, DOF should be set to a
33 | ; two-element vector [S1,S2], which gives the scale
34 | ; range that was averaged together.
35 | ; e.g. if one scale-averaged scales between 2 and 8,
36 | ; then DOF=[2,8].
37 | ;
38 | ;
39 | ; OUTPUTS:
40 | ;
41 | ; result = significance levels as a function of SCALE,
42 | ; or if /CONFIDENCE, then confidence intervals
43 | ;
44 | ;
45 | ; OPTIONAL KEYWORD INPUTS:
46 | ;
47 | ; MOTHER = A string giving the mother wavelet to use.
48 | ; Currently, 'Morlet','Paul','DOG' (derivative of Gaussian)
49 | ; are available. Default is 'Morlet'.
50 | ;
51 | ; PARAM = optional mother wavelet parameter.
52 | ; For 'Morlet' this is k0 (wavenumber), default is 6.
53 | ; For 'Paul' this is m (order), default is 4.
54 | ; For 'DOG' this is m (m-th derivative), default is 2.
55 | ;
56 | ; LAG1 = LAG 1 Autocorrelation, used for SIGNIF levels. Default is 0.0
57 | ;
58 | ; SIGLVL = significance level to use. Default is 0.95
59 | ;
60 | ; DOF = degrees-of-freedom for signif test.
61 | ; IF SIGTEST=0, then (automatically) DOF = 2 (or 1 for MOTHER='DOG')
62 | ; IF SIGTEST=1, then DOF = NA, the number of times averaged together.
63 | ; IF SIGTEST=2, then DOF = [S1,S2], the range of scales averaged.
64 | ;
65 | ; Note: IF SIGTEST=1, then DOF can be a vector (same length as SCALEs),
66 | ; in which case NA is assumed to vary with SCALE.
67 | ; This allows one to average different numbers of times
68 | ; together at different scales, or to take into account
69 | ; things like the Cone of Influence.
70 | ; See discussion following Eqn (23) in Torrence & Compo.
71 | ;
72 | ; GWS = global wavelet spectrum. If input then this is used
73 | ; as the theoretical background spectrum,
74 | ; rather than white or red noise.
75 | ;
76 | ; CONFIDENCE = if set, then return a Confidence INTERVAL.
77 | ; For SIGTEST=0,2 this will be two numbers, the lower & upper.
78 | ; For SIGTEST=1, this will return an array (J+1)x2,
79 | ; where J+1 is the number of scales.
80 | ;
81 | ;
82 | ; OPTIONAL KEYWORD OUTPUTS:
83 | ;
84 | ; PERIOD = the vector of "Fourier" periods (in time units) that corresponds
85 | ; to the SCALEs.
86 | ;
87 | ; FFT_THEOR = output theoretical red-noise spectrum as fn of PERIOD.
88 | ;
89 | ;
90 | ;----------------------------------------------------------------------------
91 | ;
92 | ; EXAMPLE:
93 | ;
94 | ; IDL> wave = WAVELET(y,dt,PERIOD=period,SCALE=scale)
95 | ; IDL> signif = WAVE_SIGNIF(y,dt,scale)
96 | ; IDL> signif = REBIN(TRANSPOSE(signif),ntime,nscale)
97 | ; IDL> CONTOUR,ABS(wave)^2/signif,time,period, $
98 | ; LEVEL=1.0,C_ANNOT='95%'
99 | ;
100 | ;
101 | ;----------------------------------------------------------------------------
102 | ; Copyright (C) 1995-1998, Christopher Torrence and Gilbert P. Compo,
103 | ; University of Colorado, Program in Atmospheric and Oceanic Sciences.
104 | ; This software may be used, copied, or redistributed as long as it is not
105 | ; sold and this copyright notice is reproduced on each copy made. This
106 | ; routine is provided as is without any express or implied warranties whatsoever.
107 | ;
108 | ; Notice: Please acknowledge the use of the above software in any publications:
109 | ; ``Wavelet software was provided by C. Torrence and G. Compo,
110 | ; and is available at URL: http://paos.colorado.edu/research/wavelets/''.
111 | ;
112 | ;----------------------------------------------------------------------------
113 | ;-
114 | ;************************************************************* WAVE_SIGNIF
115 | FUNCTION wave_signif,y,dt,scale,sigtest, $ ;*** required inputs
116 | MOTHER=mother,PARAM=param, $ ;*** optional inputs
117 | LAG1=lag1,SIGLVL=siglvl,DOF=dof, $ ;*** optional inputs
118 | GWS=gws,CONFIDENCE=confidence, $ ;*** optional inputs
119 | FFT_THEOR=fft_theor,PERIOD=period, $ ;*** optional outputs
120 | SAVG=Savg,SMID=Smid,CDELTA=CDelta,PSI0=psi0 ;*** optional outputs
121 |
122 | compile_opt idl2
123 |
124 | ON_ERROR,2
125 | IF (N_ELEMENTS(y) LT 1) THEN MESSAGE,'Time series Y must be input'
126 | IF (N_ELEMENTS(dt) LT 1) THEN MESSAGE,'DT must be input'
127 | IF (N_ELEMENTS(scale) LT 1) THEN MESSAGE,'Scales must be input'
128 | IF (N_PARAMS() LT 4) THEN sigtest = 0 ; the default
129 | variance = N_ELEMENTS(y) eq 1 ? y : (MOMENT(y))[1]
130 |
131 | ;....check keywords & optional inputs
132 | IF (N_ELEMENTS(mother) LT 1) THEN mother = 'MORLET'
133 | IF (N_ELEMENTS(param) LT 1) THEN param = -1
134 | IF (N_ELEMENTS(siglvl) LT 1) THEN siglvl = 0.95
135 | IF (N_ELEMENTS(lag1) LT 1) THEN lag1 = 0.0
136 | confidence = KEYWORD_SET(confidence)
137 |
138 | lag1 = lag1[0]
139 |
140 | J = N_ELEMENTS(scale) - 1
141 | s0 = MIN(scale)
142 | dj = ALOG(scale[1]/scale[0])/ALOG(2)
143 |
144 | CASE (STRUPCASE(mother)) OF
145 | 'MORLET': BEGIN
146 | IF (param EQ -1) THEN k0=6d ELSE k0=param
147 | fourier_factor = (4*!PI)/(k0 + SQRT(2+k0^2)) ; [Sec.3h]
148 | empir = [2.,-1,-1,-1]
149 | IF (k0 EQ 6) THEN empir[1:3]=[0.776,2.32,0.60]
150 | END
151 | 'PAUL': BEGIN ;****************** PAUL
152 | IF (param EQ -1) THEN m=4d ELSE m=param
153 | fourier_factor = 4*!PI/(2*m+1)
154 | empir = [2.,-1,-1,-1]
155 | IF (m EQ 4) THEN empir[1:3]=[1.132,1.17,1.5]
156 | END
157 | 'DOG': BEGIN ;******************* DOG
158 | IF (param EQ -1) THEN m=2 ELSE m=param
159 | fourier_factor = 2*!PI*SQRT(2./(2*m+1))
160 | empir = [1.,-1,-1,-1]
161 | IF (m EQ 2) THEN empir[1:3] = [3.541,1.43,1.4]
162 | IF (m EQ 6) THEN empir[1:3] = [1.966,1.37,0.97]
163 | END
164 | ENDCASE
165 |
166 | period = scale*fourier_factor
167 | dofmin = empir[0] ; Degrees of freedom with no smoothing
168 | Cdelta = empir[1] ; reconstruction factor
169 | gamma = empir[2] ; time-decorrelation factor
170 | dj0 = empir[3] ; scale-decorrelation factor
171 |
172 | ;....significance levels [Sec.4]
173 | freq = dt/period ; normalized frequency
174 | fft_theor = (1-lag1^2)/(1-2*lag1*COS(freq*2*!PI)+lag1^2) ; [Eqn(16)]
175 | fft_theor = variance*fft_theor ; include time-series variance
176 | IF (N_ELEMENTS(gws) EQ (J+1)) THEN fft_theor = gws
177 | signif = fft_theor
178 |
179 | CASE (sigtest) OF
180 |
181 | 0: BEGIN ; no smoothing, DOF=dofmin
182 | dof = dofmin
183 | signif = fft_theor*CHISQR_CVF(1. - siglvl,dof)/dof ; [Eqn(18)]
184 | IF confidence THEN BEGIN
185 | sig = (1. - siglvl)/2.
186 | chisqr = dof/[CHISQR_CVF(sig,dof),CHISQR_CVF(1.-sig,dof)]
187 | signif = fft_theor # chisqr
188 | ENDIF
189 | END
190 |
191 | 1: BEGIN ; time-averaged, DOFs depend upon scale [Sec.5a]
192 | IF (N_ELEMENTS(dof) LT 1) THEN dof = dofmin
193 | IF (gamma EQ -1) THEN MESSAGE, $
194 | 'Gamma (decorrelation factor) not defined for '+mother+ $
195 | ' with param='+STRTRIM(param,2)
196 | IF (N_ELEMENTS(dof) EQ 1) THEN dof = FLTARR(J+1) + dof
197 | dof = dof > 1
198 | dof = dofmin*SQRT( 1 + (dof*dt/gamma/scale)^2 ) ; [Eqn(23)]
199 | dof = dof > dofmin ; minimum DOF is dofmin
200 | IF (NOT confidence) THEN BEGIN
201 | FOR a1=0,J DO BEGIN
202 | chisqr = CHISQR_CVF(1. - siglvl,dof[a1])/dof[a1]
203 | signif[a1] = fft_theor[a1]*chisqr
204 | ; print,"a1=",a1,"dof=",dof[a1],"chisquare=", chisqr
205 | ENDFOR
206 | ENDIF ELSE BEGIN
207 | signif = FLTARR(J+1,2)
208 | sig = (1. - siglvl)/2.
209 | FOR a1=0,J DO BEGIN
210 | chisqr = dof(a1)/ $
211 | [CHISQR_CVF(sig,dof(a1)),CHISQR_CVF(1.-sig,dof(a1))]
212 | signif[a1,*] = fft_theor[a1]*chisqr
213 | ENDFOR
214 | ENDELSE
215 | END
216 |
217 | 2: BEGIN ; scale-averaged, DOFs depend upon scale range [Sec.5b]
218 | IF (N_ELEMENTS(dof) NE 2) THEN $
219 | MESSAGE,'DOF must be set to [S1,S2], the range of scale-averages'
220 | IF (Cdelta EQ -1) THEN MESSAGE, $
221 | 'Cdelta & dj0 not defined for '+mother+ $
222 | ' with param='+STRTRIM(param,2)
223 | s1 = dof[0]
224 | s2 = dof[1]
225 | avg = WHERE((scale GE s1) AND (scale LE s2),navg)
226 | IF (navg LT 1) THEN MESSAGE,'No valid scales between ' + $
227 | STRTRIM(s1,2) + ' and ' + STRTRIM(s2,2)
228 | s1 = MIN(scale[avg])
229 | s2 = MAX(scale[avg])
230 | Savg = 1./TOTAL(1./scale[avg]) ; [Eqn(25)]
231 | Smid = EXP((ALOG(s1)+ALOG(s2))/2.) ; power-of-two midpoint
232 | dof = (dofmin*navg*Savg/Smid)*SQRT(1 + (navg*dj/dj0)^2) ; [Eqn(28)]
233 | fft_theor = Savg*TOTAL(fft_theor[avg]/scale[avg]) ; [Eqn(27)]
234 | chisqr = CHISQR_CVF(1. - siglvl,dof)/dof
235 | IF confidence THEN BEGIN
236 | sig = (1. - siglvl)/2.
237 | chisqr = dof/[CHISQR_CVF(sig,dof),CHISQR_CVF(1.-sig,dof)]
238 | ENDIF
239 | signif = (dj*dt/Cdelta/Savg)*fft_theor*chisqr ; [Eqn(26)]
240 | END
241 |
242 | ENDCASE
243 |
244 | RETURN,signif
245 |
246 | END
247 |
--------------------------------------------------------------------------------