G13CBF (PDF version)
G13 Chapter Contents
G13 Chapter Introduction
NAG Library Manual

NAG Library Routine Document


Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

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

2  Specification

REAL (KIND=nag_wp)  PX, PW, XG(KC), STATS(4)

3  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:
12 1-cosπ t-12 /T , 1tT 12 1-cosπ n-t+12 /T , n+1-Ttn 1, otherwise,
where T= np2 and p is the tapering proportion.
The unsmoothed sample spectrum
f*ω=12π t=1nxtexpiω t 2
is then calculated for frequency values
ω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 k is a multiple of a chosen value r, i.e.,
ωrl=νl=2πlL,  l=0,1,,L/2,
where K=r×L. You will normally fix L first, then choose r so that K is sufficiently large to provide an adequate representation for the unsmoothed spectrum, i.e., K2×n. It is possible to take L=K, i.e., r=1.
The smoothing is defined by a trapezium window whose shape is supplied by the function
Wα=1, αp Wα=1-α 1-p , p<α1
the proportion p being supplied by you.
The width of the window is fixed as 2π/M by you supplying M. A set of averaging weights are constructed:
Wk=g×W ωkM π ,  0ωkπM,
where g is a normalizing constant, and the smoothed spectrum obtained is
f^νl=ωk< πMWkf*νl+ωk.
If no smoothing is required M should be set to n, in which case the values returned are f^νl=f*νl. Otherwise, in order that the smoothing approximates well to an integration, it is essential that KM, and preferable, but not essential, that K be a multiple of M. A choice of L>M would normally be required to supply an adequate description of the smoothed spectrum. Typical choices of Ln and K4n should be adequate for usual smoothing situations when M<n/5.
The sampling distribution of f^ω is approximately that of a scaled χd2 variate, whose degrees of freedom d is provided by the routine, together with multiplying limits mu, ml from which approximate 95% confidence intervals for the true spectrum fω may be constructed as ml × f ^ ω mu × f ^ ω . Alternatively, log f^ω may be returned, with additive limits.
The bandwidth b of the corresponding smoothing window in the frequency domain is also provided. Spectrum estimates separated by (angular) frequencies much greater than b may be assumed to be independent.

4  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

5  Parameters

1:     NX – INTEGERInput
On entry: n, the length of the time series.
Constraint: NX1.
2:     MTX – INTEGERInput
On entry: whether the data are to be initially mean or trend corrected.
For no correction.
For mean correction.
For trend correction.
Constraint: 0MTX2.
3:     PX – REAL (KIND=nag_wp)Input
On entry: the proportion of the data (totalled over both ends) to be initially tapered by the split cosine bell taper. (A value of 0.0 implies no tapering.)
Constraint: 0.0PX1.0.
4:     MW – INTEGERInput
On entry: the value of M which determines the frequency width of the smoothing window as 2π/M. A value of n implies no smoothing is to be carried out.
Constraint: 1MWNX.
5:     PW – REAL (KIND=nag_wp)Input
On entry: p, the shape parameter of the trapezium frequency window.
A value of 0.0 gives a triangular window, and a value of 1.0 a rectangular window.
If MW=NX (i.e., no smoothing is carried out), PW is not used.
Constraint: 0.0PW1.0.
6:     L – INTEGERInput
On entry: L, the frequency division of smoothed spectral estimates as 2π/L.
  • L1;
  • L must be a factor of KC.
7:     KC – INTEGERInput
On entry: K, the order of the fast Fourier transform (FFT) used to calculate the spectral estimates. KC should be a multiple of small primes such as 2m where m is the smallest integer such that 2m2n, provided m20.
  • KC2×NX;
  • KC must be a multiple of L. The largest prime factor of KC must not exceed 19, and the total number of prime factors of KC, counting repetitions, must not exceed 20. These two restrictions are imposed by the internal FFT algorithm used.
8:     LG – INTEGERInput
On entry: indicates whether unlogged or logged spectral estimates and confidence limits are required.
For unlogged.
For logged.
9:     XG(KC) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the n data points.
On exit: contains the NG spectral estimates f^ωi, for i=0,1,,L/2, in XG1 to XGNG (logged if LG0). The elements XGi, for i=NG+1,,KC, contain 0.0.
10:   NG – INTEGEROutput
On exit: the number of spectral estimates, L/2+1, in XG.
11:   STATS(4) – REAL (KIND=nag_wp) arrayOutput
On exit: four associated statistics. These are the degrees of freedom in STATS1, the lower and upper 95% confidence limit factors in STATS2 and STATS3 respectively (logged if LG0), and the bandwidth in STATS4.
12:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if IFAIL0 on exit, the recommended value is -1. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Note: G13CBF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
On entry,NX<1,
orPW<0.0 and MWNX,
orPW>1.0 and MWNX,
On entry,KC<2×NX,
orKC is not a multiple of L,
orKC has a prime factor exceeding 19,
orKC has more than 20 prime factors, counting repetitions.
This indicates that a serious error has occurred. Check all array subscripts and subroutine parameter lists in calls to G13CBF. Seek expert help.
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.
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.

7  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.

8  Further Comments

G13CBF carries out a FFT of length KC to calculate the sample spectrum. The time taken by the routine for this is approximately proportional to KC×logKC (but see Section 8 in C06PAF for further details).

9  Example

This example reads a time series of length 131. It then calls G13CBF to calculate the univariate spectrum and prints the logged spectrum together with 95% confidence limits.

9.1  Program Text

Program Text (g13cbfe.f90)

9.2  Program Data

Program Data (g13cbfe.d)

9.3  Program Results

Program Results (g13cbfe.r)

G13CBF (PDF version)
G13 Chapter Contents
G13 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012