NAG Library Routine Document
G13CBF
1 Purpose
G13CBF calculates the smoothed sample spectrum of a univariate time series using spectral smoothing by the trapezium frequency (Daniell) window.
2 Specification
SUBROUTINE G13CBF ( |
NX, MTX, PX, MW, PW, L, KC, LG, XG, NG, STATS, IFAIL) |
INTEGER |
NX, MTX, MW, L, KC, LG, NG, IFAIL |
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:
where
and
is the tapering proportion.
The unsmoothed sample spectrum
is then calculated for frequency values
where [ ] denotes the integer part.
The smoothed spectrum is returned as a subset of these frequencies for which
is a multiple of a chosen value
, i.e.,
where
. You will normally fix
first, then choose
so that
is sufficiently large to provide an adequate representation for the unsmoothed spectrum, i.e.,
. It is possible to take
, i.e.,
.
The smoothing is defined by a trapezium window whose shape is supplied by the function
the proportion
being supplied by you.
The width of the window is fixed as
by you supplying
. A set of averaging weights are constructed:
where
is a normalizing constant, and the smoothed spectrum obtained is
If no smoothing is required
should be set to
, in which case the values returned are
. Otherwise, in order that the smoothing approximates well to an integration, it is essential that
, and preferable, but not essential, that
be a multiple of
. A choice of
would normally be required to supply an adequate description of the smoothed spectrum. Typical choices of
and
should be adequate for usual smoothing situations when
.
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 95% 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: NX – INTEGERInput
On entry: , the length of the time series.
Constraint:
.
- 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:
.
- 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 implies no tapering.)
Constraint:
.
- 4: MW – INTEGERInput
On entry: the value of which determines the frequency width of the smoothing window as . A value of implies no smoothing is to be carried out.
Constraint:
.
- 5: PW – REAL (KIND=nag_wp)Input
On entry:
, the shape parameter of the trapezium frequency window.
A value of gives a triangular window, and a value of a rectangular window.
If
(i.e., no smoothing is carried out),
PW is not used.
Constraint:
.
- 6: L – INTEGERInput
On entry: , the frequency division of smoothed spectral estimates as .
Constraints:
- ;
- L must be a factor of KC.
- 7: KC – INTEGERInput
On entry:
, the order of the fast Fourier transform (FFT) used to calculate the spectral estimates.
KC should be a multiple of small primes such as
where
is the smallest integer such that
, provided
.
Constraints:
- ;
- KC must be a multiple of L. 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.
- 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 data points.
On exit: contains the
NG spectral estimates
, for
, in
to
(logged if
). The elements
, for
, contain
.
- 10: NG – INTEGEROutput
On exit: the number of spectral estimates,
, in
XG.
- 11: STATS() – 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 .
- 12: IFAIL – 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, because for this routine the values of the output parameters may be useful even if
on exit, 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).
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, | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | and , |
or | and , |
or | . |
On entry, | , |
or | KC is not a multiple of L, |
or | KC has a prime factor exceeding , |
or | KC has more than 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.
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
(but see
Section 8 in C06PAF for further details).
9 Example
This example reads a time series of length . It then calls G13CBF to calculate the univariate spectrum and prints the logged spectrum together with 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)