nag_tsa_spectrum_bivar_cov (g13ccc) (PDF version)
g13 Chapter Contents
g13 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_tsa_spectrum_bivar_cov (g13ccc)

 Contents

    1  Purpose
    7  Accuracy

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 ω, fxyω=cfω+iqfω, defined by its real part or co-spectrum
cfω=12π k=-M+1 M-1wkCxyk+Scosωk  
and imaginary part or quadrature spectrum
qfω=12π k=-M+ 1 M- 1wkCxyk+Ssinω k  
where wk=w-k, for k=0,1,,M-1, is the smoothing lag window as defined in the description of nag_tsa_spectrum_univar_cov (g13cac). The alignment shift S is recommended to be chosen as the lag k at which the cross-covariances cxyk peak, so as to minimize bias.
The results are calculated for frequency values
ωj=2πjL,  j=0,1,,L/2,  
where  denotes the integer part.
The cross-covariances cxyk may be supplied by you, or constructed from supplied series x1,x2,,xn; y1,y2,,yn as
cxyk=t=1 n-kxtyt+kn,  k0  
cxyk=t= 1-knxtyt+kn=cyx-k,   k< 0  
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 yt and xt.

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: n, the length of the time series x and y.
Constraint: nxy1.
2:     mtxy_correction NagMeanOrTrendInput
On entry: if cross-covariances are to be calculated by the function (ic=0), mtxy_correction must specify whether the data is to be initially mean or trend corrected.
mtxy_correction=Nag_NoCorrection
For no correction.
mtxy_correction=Nag_Mean
For mean correction.
mtxy_correction=Nag_Trend
For trend correction.
If cross-covariances are supplied ic0, mtxy_correction should be set to mtxy_correction=Nag_NoCorrection
Constraint: if ic=0, mtxy_correction=Nag_NoCorrection, Nag_Mean or Nag_Trend.
3:     pxy doubleInput
On entry: if cross-covariances are to be calculated by the function (ic=0), 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 0.0 implies no tapering.
If cross-covariances are supplied ic0, pxy is not used.
Constraint: if ic=0, 0.0pxy1.0.
4:     iw IntegerInput
On entry: the choice of lag window.
iw=1
Rectangular.
iw=2
Bartlett.
iw=3
Tukey.
iw=4
Parzen.
Constraint: 1iw4.
5:     mw IntegerInput
On entry: M, the ‘cut-off’ point of the lag window, relative to any alignment shift that has been applied. Windowed cross-covariances at lags -mw+ish or less, and at lags mw+ish or greater are zero.
Constraints:
  • mw1;
  • mw+ishnxy.
6:     ish IntegerInput
On entry: S, the alignment shift between the x and y series. If x leads y, the shift is positive.
Constraint: -mw<ish<mw.
7:     ic IntegerInput
On entry: indicates whether cross-covariances are to be calculated in the function or supplied in the call to the function.
ic=0
Cross-covariances are to be calculated.
ic0
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: mw+ishncnxy.
9:     cxy[nc] doubleInput/Output
On entry: if ic0, cxy must contain the nc cross-covariances between values in the y series and earlier values in time in the x series, for lags from 0 to nc-1.
If ic=0, cxy need not be set.
On exit: if ic=0, cxy will contain the nc calculated cross-covariances.
If ic0, the contents of cxy will be unchanged.
10:   cyx[nc] doubleInput/Output
On entry: if ic0, cyx must contain the nc cross-covariances between values in the y series and later values in time in the x series, for lags from 0 to nc-1.
If ic=0, cyx need not be set.
On exit: if ic=0, cyx will contain the nc calculated cross-covariances.
If ic0, the contents of cyx will be unchanged.
11:   kc IntegerInput
On entry: if ic=0, 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 2m where m is the smallest integer such that 2mn+nc.
If ic0, that is if covariances are supplied, kc is not used.
Constraint: kcnxy+nc. The largest prime factor of kc must not exceed 19, and the total number of prime factors of kc, counting repetitions, must not exceed 20. These two restrictions are imposed by the internal FFT algorithm used.
12:   l IntegerInput
On entry: L, the frequency division of the spectral estimates as 2πL . 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 2m where m is the smallest integer such that 2m2M-1.
Constraint: l2×mw-1. The largest prime factor of l must not exceed 19, and the total number of prime factors of l, counting repetitions, must not exceed 20. These two restrictions are imposed by the internal FFT algorithm used.
13:   xg[dim] doubleInput/Output
Note: the dimension, dim, of the array xg must be at least
  • maxkc,l, when ic=0;
  • .
On entry: if the cross-covariances are to be calculated (ic=0) xg must contain the nxy data points of the x series. If covariances are supplied (ic0) xg may contain any values.
On exit: contains the real parts of the ng complex spectral estimates in elements xg[0] to xg[ng-1], and xg[ng] to xg[dim-1] contain 0.0. The y series leads the x series.
14:   yg[dim] doubleInput/Output
Note: the dimension, dim, of the array yg must be at least
  • maxkc,l, when ic=0;
  • .
On entry: if the cross-covariances are to be calculated (ic=0) yg must contain the nxy data points of the y series. If covariances are supplied (ic0) yg may contain any values.
On exit: contains the imaginary parts of the ng complex spectral estimates in elements yg[0] to yg[ng-1], and yg[ng] to yg[dim-1] contain 0.0. The y series leads the x series.
15:   g[l/2+1] ComplexOutput
On exit: the complex vector that contains the ng cross spectral estimates in elements g[0] to g[ng-1]. The y series leads the x series.
16:   ng Integer *Output
On exit: the number, l/2+1, 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_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.2.1.2 in the Essential Introduction for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT
On entry, ic=0 and mtxy_correctionNag_NoCorrection, Nag_Mean or Nag_Trend: mtxy_correction=value.
On entry, iw=value.
Constraint: iw=1, 2, 3 or 4.
On entry, mw=value.
Constraint: mw1.
On entry, nxy=value.
Constraint: nxy1.
NE_INT_2
On entry, ish=value and mw=value.
Constraint: ishmw.
On entry, l=value and mw=value.
Constraint: l2×mw-1.
On entry, nc=value and nxy=value.
Constraint: ncnxy.
NE_INT_3
On entry, kc=value, nxy=value and nc=value.
Constraint: if ic=0, kcnxy+nc.
On entry, mw=value, ish=value and nxy=value.
Constraint: mw+ishnxy.
On entry, nc=value, mw=value and ish=value.
Constraint: ncmw+ish.
NE_INT_REAL
On entry, pxy=value.
Constraint: if ic=0, pxy1.0.
On entry, pxy=value.
Constraint: if ic=0, pxy0.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.
An unexpected error has been triggered by this function. Please contact NAG.
See Section 3.6.6 in the Essential Introduction for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 3.6.5 in the Essential Introduction for further information.
NE_PRIME_FACTOR
kc has a prime factor exceeding 19, or more than 20 prime factors (counting repetitions): kc=value.
l has a prime factor exceeding 19, or more than 20 prime factors (counting repetitions): l=value.

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.

9  Further Comments

nag_tsa_spectrum_bivar_cov (g13ccc) carries out two FFTs of length kc to calculate the sample cross-covariances and one FFT of length L 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 n is approximately proportional to nlogn (but see Section 9 in nag_sum_fft_realherm_1d (c06pac) for further details).

10  Example

This example reads two time series of length 296. It then selects mean correction, a 10% tapering proportion, the Parzen smoothing window and a cut-off point of 35 for the lag window. The alignment shift is set to 3 and 50 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)


nag_tsa_spectrum_bivar_cov (g13ccc) (PDF version)
g13 Chapter Contents
g13 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2015