g13cac calculates the smoothed sample spectrum of a univariate time series using one of four lag windows – rectangular, Bartlett, Tukey or Parzen window.
The function may be called by the names: g13cac, nag_tsa_uni_spectrum_lag or nag_tsa_spectrum_univar_cov.
3Description
The smoothed sample spectrum is defined as
where is the window width, and is calculated for frequency values
where denotes the integer part.
The autocovariances may be supplied by you, or constructed from a time series , as
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:
where and is the tapering proportion.
The smoothing window is defined by
which for the various windows is defined over by
rectangular:
Bartlett:
Tukey:
Parzen:
The sampling distribution of is approximately that of a scaled variate, whose degrees of freedom is provided by the function, together with multiplying limits , from which approximate confidence intervals for the true spectrum may be constructed as
. Alternatively, log may be returned, with additive limits.
The bandwidth of the corresponding smoothing window in the frequency domain is also provided. Spectrum estimates separated by (angular) frequencies much greater than may be assumed to be independent.
4References
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
5Arguments
1: – IntegerInput
On entry: , the length of the time series.
Constraint:
.
2: – IntegerInput
On entry: if covariances are to be calculated by the function (), mtx must specify whether the data are to be initially mean or trend corrected.
On entry: if covariances are to be calculated by the function (), 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 , 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 implies no tapering.
Constraint:
.
4: – IntegerInput
On entry: the choice of lag window.
Rectangular.
Bartlett.
Tukey.
Parzen.
Constraint:
.
5: – IntegerInput
On entry: , the ‘cut-off’ point of the lag window. Windowed covariances at lag or greater are zero.
Constraint:
.
6: – IntegerInput
On entry: indicates whether covariances are to be calculated in the function or supplied in the call to the function.
Covariances are to be calculated.
Covariances are to be supplied.
7: – IntegerInput
On entry: the number of covariances to be calculated in the function or supplied in the call to the function.
Constraint:
.
8: – doubleInput/Output
On entry: if , c must contain the nc covariances for lags from to , otherwise c need not be set.
On exit: if , c will contain the nc calculated covariances.
On entry: if , kc must specify the order of the fast Fourier transform (FFT) used to calculate the covariances.
If , that is covariances are supplied, kc is not used.
Constraint:
.
10: – IntegerInput
On entry: , the frequency division of the spectral estimates as . Therefore, it is also the order of the FFT used to construct the sample spectrum from the covariances.
Constraint:
.
11: – Nag_LoggedSpectraInput
On entry: indicates whether unlogged or logged spectral estimates and confidence limits are required.
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,
, for in to respectively (logged if ). The elements , for contain .
14: – Integer *Output
On exit: the number of spectral estimates, , in xg.
15: – doubleOutput
On exit: four associated statistics. These are the degrees of freedom in , the lower and upper confidence limit factors in and respectively (logged if ), and the bandwidth in .
16: – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
6Error Indicators and Warnings
NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument had an illegal value.
NE_CONFID_LIMITS
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.
NE_INT
On entry, and : .
On entry, and : .
On entry, .
Constraint: , , or .
On entry, .
Constraint: .
On entry, .
Constraint: .
NE_INT_2
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: if , .
NE_INT_3
On entry, , and .
Constraint: if , .
On entry, , and .
Constraint: if , .
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_REAL
On entry, .
Constraint: .
On entry, .
Constraint: .
NE_SPECTRAL_ESTIMATES
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.
7Accuracy
The FFT is a numerically stable process, and any errors introduced during the computation will normally be insignificant compared with uncertainty in the data.
8Parallelism and Performance
g13cac is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g13cac 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 function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
9Further Comments
g13cac 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 function for an FFT of length is approximately proportional to (but see Section 9 in c06pac for further details).
10Example
This example reads a time series of length . It selects the mean correction option, a tapering proportion of , the Parzen smoothing window and a cut-off point for the window at lag . It chooses to have auto-covariances calculated and unlogged spectral estimates at a frequency division of . It then calls g13cac to calculate the univariate spectrum and statistics and prints the autocovariances and the spectrum together with its confidence multiplying limits.