NAG Library Routine Document
G13CAF
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
SUBROUTINE G13CAF ( |
NX, MTX, PX, IW, MW, IC, NC, C, KC, L, LG, NXG, XG, NG, STATS, IFAIL) |
INTEGER |
NX, MTX, IW, MW, IC, NC, KC, L, LG, NXG, NG, IFAIL |
REAL (KIND=nag_wp) |
PX, C(NC), XG(NXG), STATS(4) |
|
3 Description
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 routine, 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.
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: – INTEGERInput
-
On entry: , the length of the time series.
Constraint:
.
- 2: – INTEGERInput
-
On entry: if covariances are to be calculated by the routine (
),
MTX must specify whether the data are to be initially mean or trend corrected.
- For no correction.
- For mean correction.
- For trend correction.
Constraint:
if
,
If covariances are supplied (
),
MTX is not used.
- 3: – REAL (KIND=nag_wp)Input
-
On entry: if covariances are to be calculated by the routine (
),
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 routine or supplied in the call to the routine.
- Covariances are to be calculated.
- Covariances are to be supplied.
- 7: – INTEGERInput
-
On entry: the number of covariances to be calculated in the routine or supplied in the call to the routine.
Constraint:
.
- 8: – REAL (KIND=nag_wp) arrayInput/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.
If
, the contents of
C will be unchanged.
- 9: – INTEGERInput
-
On entry: if
,
KC must specify the order of the fast Fourier transform (FFT) used to calculate the covariances.
KC should be a product of small primes such as
where
is the smallest integer such that
, provided
.
If
, that is covariances are supplied,
KC is not used.
Constraint:
. The largest prime factor of
KC must not exceed
, and the total number of prime factors of
KC, counting repetitions, must not exceed
. These two restrictions are imposed by the internal FFT algorithm used.
- 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.
L should be a product of small primes such as
where
is the smallest integer such that
, provided
.
Constraint:
. The largest prime factor of
L must not exceed
, and the total number of prime factors of
L, counting repetitions, must not exceed
. These two restrictions are imposed by the internal FFT algorithm used.
- 11: – INTEGERInput
-
On entry: indicates whether unlogged or logged spectral estimates and confidence limits are required.
- Unlogged.
- Logged.
- 12: – INTEGERInput
-
On entry: the dimension of the array
XG as declared in the (sub)program from which G13CAF is called.
Constraints:
- if , ;
- if , .
- 13: – REAL (KIND=nag_wp) arrayInput/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,
, for
in
to
respectively (logged if
). The elements
, for
contain
.
- 14: – INTEGEROutput
-
On exit: the number of spectral estimates,
, in
XG.
- 15: – REAL (KIND=nag_wp) arrayOutput
-
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: – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. 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
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
-
On entry, | , |
or | and , |
or | and , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | and , |
or | and . |
-
On entry, | , |
or | KC has a prime factor exceeding , |
or | KC has more than prime factors, counting repetitions. |
This error only occurs when .
-
On entry, | , |
or | L has a prime factor exceeding , |
or | L has more than prime factors, counting repetitions. |
-
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.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction 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
Not applicable.
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
is approximately proportional to
(but see
Section 9 in C06PAF for further details).
10 Example
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 G13CAF to calculate the univariate spectrum and statistics and prints the autocovariances and the spectrum together with its 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)