NAG C Library Function Document
nag_tsa_spectrum_bivar_cov (g13ccc)
1
Purpose
nag_tsa_spectrum_bivar_cov (g13ccc) calculates the smoothed sample cross spectrum of a bivariate time series using one of four lag windows: rectangular, Bartlett, Tukey or Parzen.
2
Specification
#include <nag.h> |
#include <nagg13.h> |
void |
nag_tsa_spectrum_bivar_cov (Integer nxy,
NagMeanOrTrend mtxy_correction,
double pxy,
Integer iw,
Integer mw,
Integer ish,
Integer ic,
Integer nc,
double cxy[],
double cyx[],
Integer kc,
Integer l,
double xg[],
double yg[],
Complex g[],
Integer *ng,
NagError *fail) |
|
3
Description
The smoothed sample cross spectrum is a complex valued function of frequency
,
, defined by its real part or co-spectrum
and imaginary part or quadrature spectrum
where
, for
, is the smoothing lag window as defined in the description of
nag_tsa_spectrum_univar_cov (g13cac). The alignment shift
is recommended to be chosen as the lag
at which the cross-covariances
peak, so as to minimize bias.
The results are calculated for frequency values
where
denotes the integer part.
The cross-covariances
may be supplied by you, or constructed from supplied series
;
as
this convolution being carried out using the finite Fourier transform.
The supplied series may be mean and trend corrected and tapered before calculation of the cross-covariances, in exactly the manner described in
nag_tsa_spectrum_univar_cov (g13cac) for univariate spectrum estimation. The results are corrected for any bias due to tapering.
The bandwidth associated with the estimates is not returned. It will normally already have been calculated in previous calls of
nag_tsa_spectrum_univar_cov (g13cac) for estimating the univariate spectra of
and
.
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 and .
Constraint:
.
- 2:
– NagMeanOrTrendInput
-
On entry: if cross-covariances are to be calculated by the function (
),
mtxy_correction must specify whether the data is to be initially mean or trend corrected.
- For no correction.
- For mean correction.
- For trend correction.
If cross-covariances are supplied
,
mtxy_correction should be set to
Constraint:
if , , or .
- 3:
– doubleInput
-
On entry: if cross-covariances are to be calculated by the function (
),
pxy must specify 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.
If cross-covariances are supplied
,
pxy is not used.
Constraint:
if , .
- 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, relative to any alignment shift that has been applied. Windowed cross-covariances at lags or less, and at lags or greater are zero.
- 6:
– IntegerInput
-
On entry: , the alignment shift between the and series. If leads , the shift is positive.
Constraint:
.
- 7:
– IntegerInput
-
On entry: indicates whether cross-covariances are to be calculated in the function or supplied in the call to the function.
- Cross-covariances are to be calculated.
- Cross-covariances are to be supplied.
- 8:
– IntegerInput
-
On entry: the number of cross-covariances to be calculated in the function or supplied in the call to the function.
Constraint:
.
- 9:
– doubleInput/Output
-
On entry: if
,
cxy must contain the
nc cross-covariances between values in the
series and earlier values in time in the
series, for lags from
to
.
If
,
cxy need not be set.
On exit: if
,
cxy will contain the
nc calculated cross-covariances.
If
, the contents of
cxy will be unchanged.
- 10:
– doubleInput/Output
-
On entry: if
,
cyx must contain the
nc cross-covariances between values in the
series and later values in time in the
series, for lags from
to
.
If
,
cyx need not be set.
On exit: if
,
cyx will contain the
nc calculated cross-covariances.
If
, the contents of
cyx will be unchanged.
- 11:
– IntegerInput
-
On entry: if
,
kc must specify the order of the fast Fourier transform (FFT) used to calculate the cross-covariances.
If
, that is if covariances are supplied,
kc is not used.
Constraint:
.
- 12:
– 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 cross-covariances.
Constraint:
.
- 13:
– doubleInput/Output
-
Note: the dimension,
dim, of the array
xg
must be at least
- , when ;
- , otherwise.
On entry: if the cross-covariances are to be calculated (
)
xg must contain the
nxy data points of the
series. If covariances are supplied (
)
xg may contain any values.
On exit: contains the real parts of the
ng complex spectral estimates in elements
to
, and
to
contain
. The
series leads the
series.
- 14:
– doubleInput/Output
-
Note: the dimension,
dim, of the array
yg
must be at least
- , when ;
- , otherwise.
On entry: if the cross-covariances are to be calculated (
)
yg must contain the
nxy data points of the
series. If covariances are supplied (
)
yg may contain any values.
On exit: contains the imaginary parts of the
ng complex spectral estimates in elements
to
, and
to
contain
. The
series leads the
series.
- 15:
– ComplexOutput
-
On exit: the complex vector that contains the
ng cross spectral estimates in elements
to
. The
series leads the
series.
- 16:
– Integer *Output
-
On exit: the number, , of complex spectral estimates.
- 17:
– 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_ALLOC_FAIL
-
Dynamic memory allocation failed.
See
Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_INT
-
On entry, .
Constraint: , , or .
On entry, .
Constraint: if then , or .
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_INT_2
-
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
- NE_INT_3
-
On entry, , and .
Constraint: if , .
On entry, , and .
Constraint: .
On entry, , and .
Constraint: .
- NE_INT_REAL
-
On entry, .
Constraint: if , .
On entry, .
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 2.7.6 in How to Use the NAG Library and its Documentation for further information.
- NE_NO_LICENCE
-
Your licence key may have expired or may not have been installed correctly.
See
Section 2.7.5 in How to Use the NAG Library and its Documentation 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
nag_tsa_spectrum_bivar_cov (g13ccc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_tsa_spectrum_bivar_cov (g13ccc) 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.
nag_tsa_spectrum_bivar_cov (g13ccc) carries out two FFTs of length
kc to calculate the sample cross-covariances and one FFT of length
to calculate the sample spectrum. The timing of
nag_tsa_spectrum_bivar_cov (g13ccc) is therefore dependent on the choice of these values. The time taken for an FFT of length
is approximately proportional to
(but see
Section 9 in
nag_sum_fft_realherm_1d (c06pac) for further details).
10
Example
This example reads two time series of length . It then selects mean correction, a 10% tapering proportion, the Parzen smoothing window and a cut-off point of for the lag window. The alignment shift is set to and cross-covariances are chosen to be calculated. The program then calls nag_tsa_spectrum_bivar_cov (g13ccc) to calculate the cross spectrum and then prints the cross-covariances and cross spectrum.
10.1
Program Text
Program Text (g13ccce.c)
10.2
Program Data
Program Data (g13ccce.d)
10.3
Program Results
Program Results (g13ccce.r)