NAG 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:
nxy – IntegerInput
On entry: , the length of the time series and .
Constraint:
.
- 2:
mtxy_correction – 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:
pxy – 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:
iw – IntegerInput
On entry: the choice of lag window.
- Rectangular.
- Bartlett.
- Tukey.
- Parzen.
Constraint:
.
- 5:
mw – 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:
ish – IntegerInput
On entry: , the alignment shift between the and series. If leads , the shift is positive.
Constraint:
.
- 7:
ic – 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:
nc – IntegerInput
On entry: the number of cross-covariances to be calculated in the function or supplied in the call to the function.
Constraint:
.
- 9:
cxy[nc] – 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:
cyx[nc] – 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:
kc – IntegerInput
On entry: if
,
kc must specify the order of the fast Fourier transform (FFT) used to calculate the cross-covariances.
kc should be a product of small primes such as
where
is the smallest integer such that
.
If
, that is if 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.
- 12:
l – 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.
l should be a product of small primes such as
where
is the smallest integer such that
.
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.
- 13:
xg[] – doubleInput/Output
-
Note: the dimension,
dim, of the array
xg
must be at least
- , when ;
- , when .
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:
yg[] – doubleInput/Output
-
Note: the dimension,
dim, of the array
yg
must be at least
- , when ;
- , when .
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:
g[] – ComplexOutput
On exit: the complex vector that contains the
ng cross spectral estimates in elements
to
. The
series leads the
series.
- 16:
ng – Integer *Output
On exit: the number, , of complex spectral estimates.
- 17:
fail – NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error Indicators and Warnings
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_INT
-
On entry, and , or : .
On entry, .
Constraint: , , 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.
- NE_PRIME_FACTOR
-
kc has a prime factor exceeding
, or more than 20 prime factors (counting repetitions):
.
l has a prime factor exceeding
, or more than 20 prime factors (counting repetitions):
.
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.
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)