NAG Library Function Document
nag_tsa_spectrum_univar (g13cbc)
1
Purpose
nag_tsa_spectrum_univar (g13cbc) calculates the smoothed sample spectrum of a univariate time series using spectral smoothing by the trapezium frequency (Daniell) window.
2
Specification
#include <nag.h> |
#include <nagg13.h> |
void |
nag_tsa_spectrum_univar (Integer nx,
NagMeanOrTrend mt_correction,
double px,
Integer mw,
double pw,
Integer l,
Integer kc,
Nag_LoggedSpectra lg_spect,
const double x[],
double **g,
Integer *ng,
double stats[],
NagError *fail) |
|
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 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 function, 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:
– IntegerInput
-
On entry: the length of the time series, .
Constraint:
.
- 2:
– NagMeanOrTrendInput
-
On entry: whether the data are to be initially mean or trend corrected. for no correction, for mean correction, for trend correction.
Constraint:
, or .
- 3:
– doubleInput
-
On entry: the proportion of the data (totalled over both ends) to be initially tapered by the split cosine bell taper. (A value of 0.0 implies no tapering).
Constraint:
.
- 4:
– 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:
– doubleInput
-
On entry: the shape argument,
, of the trapezium frequency window.
A value of 0.0 gives a triangular window, and a value of 1.0 a rectangular window.
If
(i.e., no smoothing is carried out), then
pw is not used.
Constraint:
. if .
- 6:
– IntegerInput
-
On entry: the frequency division, , of smoothed spectral estimates as .
Constraints:
- ;
- l must be a factor of kc (see below).
- 7:
– 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:
– Nag_LoggedSpectraInput
-
On entry: indicates whether unlogged or logged spectral estimates and confidence limits are required. for unlogged. for logged.
Constraint:
or .
- 9:
– const doubleInput
-
On entry: the data points.
- 10:
– double **Output
-
On exit: vector which contains the
ng spectral estimates
, for
, in
to
(logged if
). The memory for this vector is allocated internally. If no memory is allocated to
g (e.g., when an input error is detected) then
g will be
NULL on return. If repeated calls to this function are required then
NAG_FREE should be used to free the memory in between calls.
- 11:
– Integer *Output
-
On exit: the number of spectral estimates,
, in
g.
- 12:
– doubleOutput
-
On exit: four associated statistics. These are the degrees of freedom in , the lower and upper 95% confidence limit factors in and respectively (logged if ), and the bandwidth in .
- 13:
– NagError *Input/Output
-
The NAG error argument (see
Section 3.7 in How to Use the NAG Library and its Documentation).
6
Error Indicators and Warnings
- NE_2_INT_ARG_CONS
-
On entry,
while
. These arguments must satisfy
kc%
when
.
On entry, while . These arguments must satisfy when .
- NE_2_INT_ARG_GT
-
On entry, while . These arguments must satisfy .
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
- NE_BAD_PARAM
-
On entry, argument
lg_spect had an illegal value.
On entry, argument
mt_correction had an illegal value.
- NE_CONFID_LIMIT_FACT
-
The calculation of confidence limit factors has failed. Spectral estimates (logged if requested) are returned in
g, and degrees of freedom and bandwith in
stats.
- NE_FACTOR_GT
-
At least one of the prime factors of
kc is greater than 19.
- NE_INT_ARG_LT
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry,
pw must not be less than 0.0:
.
- 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.
- NE_REAL_ARG_GT
-
On entry,
pw must not be greater than 1.0:
.
On entry,
px must not be greater than 1.0:
.
- NE_REAL_ARG_LT
-
On entry,
px must not be less than 0.0:
.
- NE_SPECTRAL_ESTIM_NEG
-
One or more spectral estimates are negative. Unlogged spectral estimates are returned in
g and the degrees of freedom, unlogged confidence limit factors and bandwith in
stats.
- NE_TOO_MANY_FACTORS
-
kc has more than 20 prime factors.
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
nag_tsa_spectrum_univar (g13cbc) is not threaded in any implementation.
nag_tsa_spectrum_univar (g13cbc) carries out a FFT of length
kc to calculate the sample spectrum. The time taken by the function for this is approximately proportional to
(but see
Section 9 in
nag_sum_fft_realherm_1d (c06pac) for further details).
10
Example
The example program reads a time series of length 131. It selects the mean correction option, a tapering proportion of 0.2, the option of no smoothing and a frequency division for logged spectral estimates of . It then calls nag_tsa_spectrum_univar (g13cbc) to calculate the univariate spectrum and prints the logged spectrum together with 95% confidence limits. The program then selects a smoothing window with frequency width and shape argument 0.5 and recalculates and prints the logged spectrum and 95% confidence limits.
10.1
Program Text
Program Text (g13cbce.c)
10.2
Program Data
Program Data (g13cbce.d)
10.3
Program Results
Program Results (g13cbce.r)