NAG FL Interface
g13cbf (uni_​spectrum_​daniell)

1 Purpose

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

2 Specification

Fortran Interface
Subroutine g13cbf ( nx, mtx, px, mw, pw, l, kc, lg, xg, ng, stats, ifail)
Integer, Intent (In) :: nx, mtx, mw, l, kc, lg
Integer, Intent (Inout) :: ifail
Integer, Intent (Out) :: ng
Real (Kind=nag_wp), Intent (In) :: px, pw
Real (Kind=nag_wp), Intent (Inout) :: xg(kc)
Real (Kind=nag_wp), Intent (Out) :: stats(4)
C Header Interface
#include <nag.h>
void  g13cbf_ (const Integer *nx, const Integer *mtx, const double *px, const Integer *mw, const double *pw, const Integer *l, const Integer *kc, const Integer *lg, double xg[], Integer *ng, double stats[], Integer *ifail)
The routine may be called by the names g13cbf or nagf_tsa_uni_spectrum_daniell.

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 Arguments

1: nx Integer Input
On entry: n, the length of the time series.
Constraint: nx1.
2: mtx Integer Input
On entry: whether the data are to be initially mean or trend corrected.
mtx=0
For no correction.
mtx=1
For mean correction.
mtx=2
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 Integer Input
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 Integer Input
On entry: L, the frequency division of smoothed spectral estimates as 2π/L.
Constraints:
  • l1;
  • l must be a factor of kc.
7: kc Integer Input
On entry: K, the order of the fast Fourier transform (FFT) used to calculate the spectral estimates.
Constraints:
  • kc2×nx;
  • kc must be a multiple of l.
8: lg Integer Input
On entry: indicates whether unlogged or logged spectral estimates and confidence limits are required.
lg=0
For unlogged.
lg0
For logged.
9: xgkc Real (Kind=nag_wp) array Input/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 Integer Output
On exit: the number of spectral estimates, L/2+1, in xg.
11: stats4 Real (Kind=nag_wp) array Output
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 Integer Input/Output
On entry: ifail must be set to 0, -1 or 1. If you are unfamiliar with this argument you should refer to Section 4 in the Introduction to the NAG Library FL Interface 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 arguments 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).
Errors or warnings detected by the routine:
Note: in some cases g13cbf may return useful information.
ifail=1
On entry, l=value.
Constraint: l1.
On entry, mtx=value.
Constraint: mtx2.
On entry, mtx=value.
Constraint: mtx0.
On entry, mw=value.
Constraint: mw1.
On entry, mw=value and nx=value.
Constraint: mwnx.
On entry, nx=value.
Constraint: nx1.
On entry, px=value, mw=value and nx=value.
Constraint: if pw<0.0, mw=nx.
On entry, px=value, mw=value and nx=value.
Constraint: if pw>1.0, mw=nx.
On entry, px=value.
Constraint: px1.0.
On entry, px=value.
Constraint: px0.0.
ifail=2
On entry, kc=value and l=value.
Constraint: kc must be a multiple of l.
On entry, kc=value and nx=value.
Constraint: kc2×nx.
ifail=4
One or more spectral estimates are negative.
Unlogged spectral estimates are returned in xg, and the degrees of freedom, unloged confidence limit factors and bandwidth in stats.
ifail=5
The calculation of confidence limit factors has failed.
Spectral estimates (logged if requested) are returned in xg, and degrees of freedom and bandwidth in stats.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

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 Parallelism and Performance

g13cbf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g13cbf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 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 9 in c06paf for further details).

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

10.1 Program Text

Program Text (g13cbfe.f90)

10.2 Program Data

Program Data (g13cbfe.d)

10.3 Program Results

Program Results (g13cbfe.r)