hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_tsa_uni_spectrum_daniell (g13cb)

Purpose

nag_tsa_uni_spectrum_daniell (g13cb) calculates the smoothed sample spectrum of a univariate time series using spectral smoothing by the trapezium frequency (Daniell) window.

Syntax

[xg, ng, stats, ifail] = g13cb(nx, mtx, px, mw, pw, l, lg, xg, 'kc', kc)
[xg, ng, stats, ifail] = nag_tsa_uni_spectrum_daniell(nx, mtx, px, mw, pw, l, lg, xg, 'kc', kc)

Description

The supplied time series may be mean or trend corrected (by least squares), and tapered, the tapering factors being those of the split cosine bell:
(1/2) (1cos(π(t(1/2)) / T)) , 1tT
(1/2) (1cos(π(nt + (1/2)) / T)) , n + 1Ttn
1, otherwise,
12 (1-cos(π (t-12) /T)) , 1tT 12 (1-cos(π (n-t+12) /T)) , n+1-Ttn 1, otherwise,
where T = [(np)/2]T=[ np2] and pp is the tapering proportion.
The unsmoothed sample spectrum
f*(ω) = 1/(2π)
(n ) ∑ xtexp(iωt)t = 1 2
f*(ω)=12π |t=1nxtexp(iω t)| 2
is then calculated for frequency values
ωk = (2 π k)/K,   k = 0,1,,[K / 2],
ωk=2 π kK,   k= 0,1,,[K/2],
where [ ] denotes the integer part.
The smoothed spectrum is returned as a subset of these frequencies for which kk is a multiple of a chosen value rr, i.e.,
ωrl = νl = (2πl)/L,  l = 0,1,,[L / 2],
ωrl=νl=2πlL,  l=0,1,,[L/2],
where K = r × LK=r×L. You will normally fix LL first, then choose rr so that KK is sufficiently large to provide an adequate representation for the unsmoothed spectrum, i.e., K2 × nK2×n. It is possible to take L = KL=K, i.e., r = 1r=1.
The smoothing is defined by a trapezium window whose shape is supplied by the function
W(α) = 1, |α|p
W(α) = (1|α|)/(1p), p < |α|1
W(α)=1, |α|p W(α)=1-|α| 1-p , p<|α|1
the proportion pp being supplied by you.
The width of the window is fixed as 2π / M2π/M by you supplying MM. A set of averaging weights are constructed:
Wk = g × W ((ωkM)/π) ,  0ωkπ/M,
Wk=g×W (ωkM π ) ,  0ωkπM,
where gg is a normalizing constant, and the smoothed spectrum obtained is
(νl) = |ωk| < π/MWkf*(νl + ωk).
f^(νl)=|ωk|< πMWkf*(νl+ωk).
If no smoothing is required MM should be set to nn, in which case the values returned are (νl) = f*(νl)f^(νl)=f*(νl). Otherwise, in order that the smoothing approximates well to an integration, it is essential that KMKM, and preferable, but not essential, that KK be a multiple of MM. A choice of L > ML>M would normally be required to supply an adequate description of the smoothed spectrum. Typical choices of LnLn and K4nK4n should be adequate for usual smoothing situations when M < n / 5M<n/5.
The sampling distribution of (ω)f^(ω) is approximately that of a scaled χd2χd2 variate, whose degrees of freedom dd is provided by the function, together with multiplying limits mumu, mlml from which approximate 95% confidence intervals for the true spectrum f(ω)f(ω) may be constructed as [ ml × (ω) mu × (ω) ] [ ml × f ^ ( ω ) mu × f ^ ( ω ) ] . Alternatively, log (ω)f^(ω) may be returned, with additive limits.
The bandwidth bb of the corresponding smoothing window in the frequency domain is also provided. Spectrum estimates separated by (angular) frequencies much greater than bb may be assumed to be independent.

References

Bloomfield P (1976) Fourier Analysis of Time Series: An Introduction Wiley
Jenkins G M and Watts D G (1968) Spectral Analysis and its Applications Holden–Day

Parameters

Compulsory Input Parameters

1:     nx – int64int32nag_int scalar
nn, the length of the time series.
Constraint: nx1nx1.
2:     mtx – int64int32nag_int scalar
Whether the data are to be initially mean or trend corrected.
mtx = 0mtx=0
For no correction.
mtx = 1mtx=1
For mean correction.
mtx = 2mtx=2
For trend correction.
Constraint: 0mtx20mtx2.
3:     px – double scalar
The proportion of the data (totalled over both ends) to be initially tapered by the split cosine bell taper. (A value of 0.00.0 implies no tapering.)
Constraint: 0.0px1.00.0px1.0.
4:     mw – int64int32nag_int scalar
The value of MM which determines the frequency width of the smoothing window as 2π / M2π/M. A value of nn implies no smoothing is to be carried out.
Constraint: 1mwnx1mwnx.
5:     pw – double scalar
pp, the shape parameter of the trapezium frequency window.
A value of 0.00.0 gives a triangular window, and a value of 1.01.0 a rectangular window.
If mw = nxmw=nx (i.e., no smoothing is carried out), pw is not used.
Constraint: 0.0pw1.00.0pw1.0.
6:     l – int64int32nag_int scalar
LL, the frequency division of smoothed spectral estimates as 2π / L2π/L.
Constraints:
  • l1l1;
  • l must be a factor of kc.
7:     lg – int64int32nag_int scalar
Indicates whether unlogged or logged spectral estimates and confidence limits are required.
lg = 0lg=0
For unlogged.
lg0lg0
For logged.
8:     xg(kc) – double array
kc, the dimension of the array, must satisfy the constraint
  • kc2 × nxkc2×nx
  • kc must be a multiple of l. The largest prime factor of kc must not exceed 1919, and the total number of prime factors of kc, counting repetitions, must not exceed 2020. These two restrictions are imposed by the internal FFT algorithm used
  • .
    The nn data points.

    Optional Input Parameters

    1:     kc – int64int32nag_int scalar
    Default: The dimension of the array xg.
    KK, the order of the fast Fourier transform (FFT) used to calculate the spectral estimates. kc should be a multiple of small primes such as 2m2m where mm is the smallest integer such that 2m2n2m2n, provided m20m20.
    Constraints:
    • kc2 × nxkc2×nx;
    • kc must be a multiple of l. The largest prime factor of kc must not exceed 1919, and the total number of prime factors of kc, counting repetitions, must not exceed 2020. These two restrictions are imposed by the internal FFT algorithm used.

    Input Parameters Omitted from the MATLAB Interface

    None.

    Output Parameters

    1:     xg(kc) – double array
    Contains the ng spectral estimates (ωi)f^(ωi), for i = 0,1,,[L / 2]i=0,1,,[L/2], in xg(1)xg1 to xg(ng)xgng (logged if lg0lg0). The elements xg(i)xgi, for i = ng + 1,,kci=ng+1,,kc, contain 0.00.0.
    2:     ng – int64int32nag_int scalar
    The number of spectral estimates, [L / 2] + 1[L/2]+1, in xg.
    3:     stats(44) – double array
    Four associated statistics. These are the degrees of freedom in stats(1)stats1, the lower and upper 95%95% confidence limit factors in stats(2)stats2 and stats(3)stats3 respectively (logged if lg0lg0), and the bandwidth in stats(4)stats4.
    4:     ifail – int64int32nag_int scalar
    ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

    Error Indicators and Warnings

    Note: nag_tsa_uni_spectrum_daniell (g13cb) may return useful information for one or more of the following detected errors or warnings.
    Errors or warnings detected by the function:

    Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

      ifail = 1ifail=1
    On entry,nx < 1nx<1,
    ormtx < 0mtx<0,
    ormtx > 2mtx>2,
    orpx < 0.0px<0.0,
    orpx > 1.0px>1.0,
    ormw < 1mw<1,
    ormw > nxmw>nx,
    orpw < 0.0pw<0.0 and mwnxmwnx,
    orpw > 1.0pw>1.0 and mwnxmwnx,
    orl < 1l<1.
      ifail = 2ifail=2
    On entry,kc < 2 × nxkc<2×nx,
    orkc is not a multiple of l,
    orkc has a prime factor exceeding 1919,
    orkc has more than 2020 prime factors, counting repetitions.
      ifail = 3ifail=3
    This indicates that a serious error has occurred. Check all array subscripts and function parameter lists in calls to nag_tsa_uni_spectrum_daniell (g13cb). Seek expert help.
    W ifail = 4ifail=4
    One or more spectral estimates are negative. Unlogged spectral estimates are returned in xg, and the degrees of freedom, unlogged confidence limit factors and bandwidth in stats.
    W ifail = 5ifail=5
    The calculation of confidence limit factors has failed. This error will not normally occur. Spectral estimates (logged if requested) are returned in xg, and degrees of freedom and bandwidth in stats.

    Accuracy

    The FFT is a numerically stable process, and any errors introduced during the computation will normally be insignificant compared with uncertainty in the data.

    Further Comments

    nag_tsa_uni_spectrum_daniell (g13cb) carries out a FFT of length kc to calculate the sample spectrum. The time taken by the function for this is approximately proportional to kc × log(kc)kc×log(kc) (but see Section [Further Comments] in (c06pa) for further details).

    Example

    function nag_tsa_uni_spectrum_daniell_example
    nx = int64(131);
    mtx = int64(1);
    px = 0.2;
    mw = int64(131);
    pw = 0.5;
    l = int64(100);
    lg = int64(1);
    xg = zeros(400, 1);
    xg(1:131) = [11.5;
         9.89;
         8.728;
         8.4;
         8.23;
         8.365;
         8.383;
         8.243;
         8.08;
         8.244;
         8.49;
         8.867;
         9.469;
         9.786;
         10.1;
         10.714;
         11.32;
         11.9;
         12.39;
         12.095;
         11.8;
         12.4;
         11.833;
         12.2;
         12.242;
         11.687;
         10.883;
         10.138;
         8.952;
         8.443;
         8.231;
         8.067;
         7.871;
         7.962;
         8.217;
         8.689;
         8.989;
         9.45;
         9.883;
         10.15;
         10.787;
         11;
         11.133;
         11.1;
         11.8;
         12.25;
         11.35;
         11.575;
         11.8;
         11.1;
         10.3;
         9.725;
         9.025;
         8.048;
         7.294;
         7.07;
         6.933;
         7.208;
         7.617;
         7.867;
         8.309;
         8.64;
         9.179;
         9.57;
         10.063;
         10.803;
         11.547;
         11.55;
         11.8;
         12.2;
         12.4;
         12.367;
         12.35;
         12.4;
         12.27;
         12.3;
         11.8;
         10.794;
         9.675;
         8.9;
         8.208;
         8.087;
         7.763;
         7.917;
         8.03;
         8.212;
         8.669;
         9.175;
         9.683;
         10.29;
         10.4;
         10.85;
         11.7;
         11.9;
         12.5;
         12.5;
         12.8;
         12.95;
         13.05;
         12.8;
         12.8;
         12.8;
         12.6;
         11.917;
         10.805;
         9.24;
         8.777;
         8.683;
         8.649;
         8.547;
         8.625;
         8.75;
         9.11;
         9.392;
         9.787;
         10.34;
         10.5;
         11.233;
         12.033;
         12.2;
         12.3;
         12.6;
         12.8;
         12.65;
         12.733;
         12.7;
         12.259;
         11.817;
         10.767;
         9.825;
         9.15];
    [xgOut, ng, stats, ifail] = nag_tsa_uni_spectrum_daniell(nx, mtx, px, mw, pw, l, lg, xg);
     ng, stats, ifail
    
     
    
    ng =
    
                       51
    
    
    stats =
    
        2.0000
       -1.3053
        3.6762
        0.0480
    
    
    ifail =
    
                        0
    
    
    
    function g13cb_example
    nx = int64(131);
    mtx = int64(1);
    px = 0.2;
    mw = int64(131);
    pw = 0.5;
    l = int64(100);
    lg = int64(1);
    xg = zeros(400, 1);
    xg(1:131) = [11.5;
         9.89;
         8.728;
         8.4;
         8.23;
         8.365;
         8.383;
         8.243;
         8.08;
         8.244;
         8.49;
         8.867;
         9.469;
         9.786;
         10.1;
         10.714;
         11.32;
         11.9;
         12.39;
         12.095;
         11.8;
         12.4;
         11.833;
         12.2;
         12.242;
         11.687;
         10.883;
         10.138;
         8.952;
         8.443;
         8.231;
         8.067;
         7.871;
         7.962;
         8.217;
         8.689;
         8.989;
         9.45;
         9.883;
         10.15;
         10.787;
         11;
         11.133;
         11.1;
         11.8;
         12.25;
         11.35;
         11.575;
         11.8;
         11.1;
         10.3;
         9.725;
         9.025;
         8.048;
         7.294;
         7.07;
         6.933;
         7.208;
         7.617;
         7.867;
         8.309;
         8.64;
         9.179;
         9.57;
         10.063;
         10.803;
         11.547;
         11.55;
         11.8;
         12.2;
         12.4;
         12.367;
         12.35;
         12.4;
         12.27;
         12.3;
         11.8;
         10.794;
         9.675;
         8.9;
         8.208;
         8.087;
         7.763;
         7.917;
         8.03;
         8.212;
         8.669;
         9.175;
         9.683;
         10.29;
         10.4;
         10.85;
         11.7;
         11.9;
         12.5;
         12.5;
         12.8;
         12.95;
         13.05;
         12.8;
         12.8;
         12.8;
         12.6;
         11.917;
         10.805;
         9.24;
         8.777;
         8.683;
         8.649;
         8.547;
         8.625;
         8.75;
         9.11;
         9.392;
         9.787;
         10.34;
         10.5;
         11.233;
         12.033;
         12.2;
         12.3;
         12.6;
         12.8;
         12.65;
         12.733;
         12.7;
         12.259;
         11.817;
         10.767;
         9.825;
         9.15];
    [xgOut, ng, stats, ifail] = g13cb(nx, mtx, px, mw, pw, l, lg, xg);
     ng, stats, ifail
    
     
    
    ng =
    
                       51
    
    
    stats =
    
        2.0000
       -1.3053
        3.6762
        0.0480
    
    
    ifail =
    
                        0
    
    
    

    PDF version (NAG web site, 64-bit version, 64-bit version)
    Chapter Contents
    Chapter Introduction
    NAG Toolbox

    © The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013