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) |
|
C++ Header Interface
#include <nag.h> extern "C" {
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:
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
Arguments
-
1:
– Integer
Input
-
On entry: , the length of the time series.
Constraint:
.
-
2:
– Integer
Input
-
On entry: whether the data are to be initially mean or trend corrected.
- For no correction.
- For mean correction.
- For trend correction.
Constraint:
.
-
3:
– 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:
– Integer
Input
-
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:
– 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:
– Integer
Input
-
On entry: , the frequency division of smoothed spectral estimates as .
Constraints:
- ;
- l must be a factor of kc.
-
7:
– Integer
Input
-
On entry: , the order of the fast Fourier transform (FFT) used to calculate the spectral estimates.
Constraints:
- ;
- kc must be a multiple of l.
-
8:
– Integer
Input
-
On entry: indicates whether unlogged or logged spectral estimates and confidence limits are required.
- For unlogged.
- For logged.
-
9:
– Real (Kind=nag_wp) array
Input/Output
-
On entry: the data points.
On exit: contains the
ng spectral estimates
, for
, in
to
(logged if
). The elements
, for
, contain
.
-
10:
– Integer
Output
-
On exit: the number of spectral estimates,
, in
xg.
-
11:
– Real (Kind=nag_wp) array
Output
-
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:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
or
to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value
or
is recommended. If message printing is undesirable, then the value
is recommended. Otherwise, the value
is recommended since useful values can be provided in some output arguments even when
on exit.
When the value or 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:
Note: in some cases g13cbf may return useful information.
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, and .
Constraint: .
On entry, .
Constraint: .
On entry, , and .
Constraint: if , .
On entry, , and .
Constraint: if , .
On entry, .
Constraint: .
On entry, .
Constraint: .
-
On entry,
and
.
Constraint:
kc must be a multiple of
l.
On entry, and .
Constraint: .
-
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.
-
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.
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.
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.
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.
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 9 in
c06paf for further details).
10
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.
10.1
Program Text
10.2
Program Data
10.3
Program Results