NAG FL Interface
g13caf (uni_​spectrum_​lag)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

g13caf calculates the smoothed sample spectrum of a univariate time series using one of four lag windows – rectangular, Bartlett, Tukey or Parzen window.

2 Specification

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

3 Description

The smoothed sample spectrum is defined as
f^(ω)=12π (C0+2k=1 M-1wkCkcos(ωk)) ,  
where M is the window width, and is calculated for frequency values
ωi=2πiL,  i=0,1,,[L/2],  
where [] denotes the integer part.
The autocovariances Ck may be supplied by you, or constructed from a time series x1,x2,,xn, as
Ck=1nt=1 n-kxtxt+k,  
the fast Fourier transform (FFT) being used to carry out the convolution in this formula.
The time series may be mean or trend corrected (by classical least squares), and tapered before calculation of the covariances, 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 smoothing window is defined by
wk=W (kM) ,  kM-1,  
which for the various windows is defined over 0α<1 by
rectangular:
W(α)=1  
Bartlett:
W(α)= 1-α  
Tukey:
W(α)=12(1+cos(πα))  
Parzen:
W(α)= 1- 6α2+ 6α3, 0α12 W(α)= 2 (1-α) 3, 12<α< 1.  
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: if covariances are to be calculated by the routine (ic=0), mtx must specify 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: if ic=0, 0mtx2
If covariances are supplied (ic0), mtx is not used.
3: px Real (Kind=nag_wp) Input
On entry: if covariances are to be calculated by the routine (ic=0), px must specify the proportion of the data (totalled over both ends) to be initially tapered by the split cosine bell taper.
If covariances are supplied (ic0), px must specify the proportion of data tapered before the supplied covariances were calculated and after any mean or trend correction. px is required for the calculation of output statistics. A value of 0.0 implies no tapering.
Constraint: 0.0px1.0.
4: iw Integer Input
On entry: the choice of lag window.
iw=1
Rectangular.
iw=2
Bartlett.
iw=3
Tukey.
iw=4
Parzen.
Constraint: 1iw4.
5: mw Integer Input
On entry: M, the ‘cut-off’ point of the lag window. Windowed covariances at lag M or greater are zero.
Constraint: 1mwnx.
6: ic Integer Input
On entry: indicates whether covariances are to be calculated in the routine or supplied in the call to the routine.
ic=0
Covariances are to be calculated.
ic0
Covariances are to be supplied.
7: nc Integer Input
On entry: the number of covariances to be calculated in the routine or supplied in the call to the routine.
Constraint: mwncnx.
8: c(nc) Real (Kind=nag_wp) array Input/Output
On entry: if ic0, c must contain the nc covariances for lags from 0 to (nc-1), otherwise c need not be set.
On exit: if ic=0, c will contain the nc calculated covariances.
If ic0, the contents of c will be unchanged.
9: kc Integer Input
On entry: if ic=0, kc must specify the order of the fast Fourier transform (FFT) used to calculate the covariances.
If ic0, that is covariances are supplied, kc is not used.
Constraint: kcnx+nc.
10: l Integer Input
On entry: L, the frequency division of the spectral estimates as 2πL . Therefore, it is also the order of the FFT used to construct the sample spectrum from the covariances.
Constraint: l2×mw-1.
11: lg Integer Input
On entry: indicates whether unlogged or logged spectral estimates and confidence limits are required.
lg=0
Unlogged.
lg0
Logged.
12: nxg Integer Input
On entry: the dimension of the array xg as declared in the (sub)program from which g13caf is called.
Constraints:
  • if ic=0, nxgmax(kc,l);
  • if ic0, nxgl.
13: xg(nxg) Real (Kind=nag_wp) array Input/Output
On entry: if the covariances are to be calculated, then xg must contain the nx data points. If covariances are supplied, xg may contain any values.
On exit: contains the ng spectral estimates, f^(ωi), for i=0,1,,[L/2] in xg(1) to xg(ng) respectively (logged if lg=1). The elements xg(i), for i=ng+1,,nxg contain 0.0.
14: ng Integer Output
On exit: the number of spectral estimates, [L/2]+1, in xg.
15: stats(4) Real (Kind=nag_wp) array Output
On exit: four associated statistics. These are the degrees of freedom in stats(1), the lower and upper 95% confidence limit factors in stats(2) and stats(3) respectively (logged if lg=1), and the bandwidth in stats(4).
16: ifail Integer Input/Output
On entry: ifail must be set to 0, -1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of -1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value -1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. 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:
ifail=1
On entry, ic=0 and mtx<0: mtx=value.
On entry, ic=0 and mtx>2: mtx=value.
On entry, iw=value.
Constraint: iw=1, 2, 3 or 4.
On entry, mw=value.
Constraint: mw1.
On entry, mw=value and nx=value.
Constraint: mwnx.
On entry, nc=value and mw=value.
Constraint: ncmw.
On entry, nc=value and nx=value.
Constraint: ncnx.
On entry, nx=value.
Constraint: nx1.
On entry, nxg=value, kc=value and l=value.
Constraint: if ic=0, nxgmax(kc,l).
On entry, nxg=value and l=value.
Constraint: if ic0, nxgl.
On entry, px=value.
Constraint: px1.0.
On entry, px=value.
Constraint: px0.0.
ifail=2
On entry, kc=value, nx=value and nc=value.
Constraint: if ic=0, kc(nx+nc).
ifail=3
On entry, l=value and mw=value.
Constraint: l2×mw-1.
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

g13caf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g13caf 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

g13caf carries out two FFTs of length kc to calculate the covariances and one FFT of length l to calculate the sample spectrum. The time taken by the routine for an FFT of length n is approximately proportional to nlog(n) (but see Section 9 in c06paf for further details).

10 Example

This example reads a time series of length 256. It selects the mean correction option, a tapering proportion of 0.1, the Parzen smoothing window and a cut-off point for the window at lag 100. It chooses to have 100 auto-covariances calculated and unlogged spectral estimates at a frequency division of 2π/200. It then calls g13caf to calculate the univariate spectrum and statistics and prints the autocovariances and the spectrum together with its 95% confidence multiplying limits.

10.1 Program Text

Program Text (g13cafe.f90)

10.2 Program Data

Program Data (g13cafe.d)

10.3 Program Results

Program Results (g13cafe.r)