G13CCF (PDF version)
G13 Chapter Contents
G13 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G13CCF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

G13CCF calculates the smoothed sample cross spectrum of a bivariate time series using one of four lag windows: rectangular, Bartlett, Tukey or Parzen.

2  Specification

SUBROUTINE G13CCF ( NXY, MTXY, PXY, IW, MW, ISH, IC, NC, CXY, CYX, KC, L, NXYG, XG, YG, NG, IFAIL)
INTEGER  NXY, MTXY, IW, MW, ISH, IC, NC, KC, L, NXYG, NG, IFAIL
REAL (KIND=nag_wp)  PXY, CXY(NC), CYX(NC), XG(NXYG), YG(NXYG)

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 G13CAF. 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 G13CAF 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 G13CAF 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  Parameters

1:     NXY – INTEGERInput
On entry: n, the length of the time series x and y.
Constraint: NXY1.
2:     MTXY – INTEGERInput
On entry: if cross-covariances are to be calculated by the routine (IC=0), MTXY must specify whether the data is to be initially mean or trend corrected.
MTXY=0
For no correction.
MTXY=1
For mean correction.
MTXY=2
For trend correction.
If cross-covariances are supplied IC0, MTXY is not used.
Constraint: if IC=0, MTXY=0, 1 or 2.
3:     PXY – REAL (KIND=nag_wp)Input
On entry: if cross-covariances are to be calculated by the routine (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 routine or supplied in the call to the routine.
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 routine or supplied in the call to the routine.
Constraint: MW+ISHNCNXY.
9:     CXY(NC) – REAL (KIND=nag_wp) arrayInput/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) – REAL (KIND=nag_wp) arrayInput/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:   NXYG – INTEGERInput
On entry: the dimension of the arrays XG and YG as declared in the (sub)program from which G13CCF is called.
Constraints:
  • if IC=0, NXYGmaxKC,L;
  • if IC0, NXYGL.
14:   XG(NXYG) – REAL (KIND=nag_wp) arrayInput/Output
On entry: if the cross-covariances are to be calculated, then XG must contain the NXY data points of the x series. If covariances are supplied, XG need not be set.
On exit: contains the real parts of the NG complex spectral estimates in elements XG1 to XGNG, and XGNG+1 to XGNXYG contain 0.0. The y series leads the x series.
15:   YG(NXYG) – REAL (KIND=nag_wp) arrayInput/Output
On entry: if cross-covariances are to be calculated, YG must contain the NXY data points of the y series. If covariances are supplied, YG need not be set.
On exit: contains the imaginary parts of the NG complex spectral estimates in elements YG1 to YGNG, and YGNG+1 to YGNXYG contain 0.0. The y series leads the x series.
16:   NG – INTEGEROutput
On exit: the number, L/2+1, of complex spectral estimates, whose separate parts are held in XG and YG.
17:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
IFAIL=1
On entry,NXY<1,
orMTXY<0 and IC=0,
orMTXY>2 and IC=0,
orPXY<0.0 and IC=0,
orPXY>1.0 and IC=0,
orIW0,
orIW>4,
orMW<1,
orMW+ISH>NXY,
orISHMW,
orNC<MW+ISH,
orNC>NXY,
orNXYG<maxKC,L and IC=0,
orNXYG<L and IC0.
IFAIL=2
On entry,KC<NXY+NC,
orKC has a prime factor exceeding 19,
orKC has more than 20 prime factors, counting repetitions.
This error only occurs when IC=0.
IFAIL=3
On entry,L<2×MW-1,
orL has a prime factor exceeding 19,
orL has 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  Further Comments

G13CCF 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 G13CCF 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 8 in C06PAF for further details).

9  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 G13CCF to calculate the cross spectrum and then prints the cross-covariances and cross spectrum.

9.1  Program Text

Program Text (g13ccfe.f90)

9.2  Program Data

Program Data (g13ccfe.d)

9.3  Program Results

Program Results (g13ccfe.r)


G13CCF (PDF version)
G13 Chapter Contents
G13 Chapter Introduction
NAG Library Manual

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