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

NAG Library Routine Document


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

G13CDF calculates the smoothed sample cross spectrum of a bivariate time series using spectral smoothing by the trapezium frequency (Daniell) window.

2  Specification

REAL (KIND=nag_wp)  PXY, PW, XG(KC), YG(KC)

3  Description

The supplied time series may be mean and trend corrected and tapered as in the description of G13CBF before calculation of the unsmoothed sample cross-spectrum
fxy* ω = 12πn t=1 n yt expiωt × t=1 n xt exp-iωt
for frequency values ωj=2πjK , 0ωjπ.
A correction is made for bias due to any tapering.
As in the description of G13CBF for univariate frequency window smoothing, the smoothed spectrum is returned as a subset of these frequencies,
νl=2π lL,  l=0,1,,L/2
where [ ] denotes the integer part.
Its real part or co-spectrum cfνl, and imaginary part or quadrature spectrum qfνl are defined by
fxy νl = cf νl + iqf νl = ωk < πM w~k fxy* νl+ωk
where the weights w~k are similar to the weights wk defined for G13CBF, but allow for an implicit alignment shift S between the series:
w~k=wkexp-2π iSk/L.
It is recommended that S is chosen as the lag k at which the cross-covariances cxyk peak, so as to minimize bias.
If no smoothing is required, the integer M, which determines the frequency window width 2πM , should be set to n.
The bandwidth of the estimates will normally have been calculated in a previous call of G13CBF 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: whether the data is to be initially mean or trend corrected.
For no correction.
For mean correction.
For trend correction.
Constraint: 0MTXY2.
3:     PXY – REAL (KIND=nag_wp)Input
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: 0.0PXY1.0.
4:     MW – INTEGERInput
On entry: M, the frequency width of the smoothing window as 2πM .
A value of n implies that no smoothing is to be carried out.
Constraint: 1MWNXY.
5:     ISH – INTEGERInput
On entry: S, the alignment shift between the x and y series. If x leads y, the shift is positive.
Constraint: -L<ISH<L.
6:     PW – REAL (KIND=nag_wp)Input
On entry: p, the shape parameter of the trapezium frequency window.
A value of 0.0 gives a triangular window, and a value of 1.0 a rectangular window.
If MW=NXY (i.e., no smoothing is carried out) then PW is not used.
Constraint: if MWNXY, 0.0PW1.0.
7:     L – INTEGERInput
On entry: L, the frequency division of smoothed cross spectral estimates as 2πL .
  • L1;
  • L must be a factor of KC.
8:     KC – INTEGERInput
On entry: the dimension of the arrays XG and YG as declared in the (sub)program from which G13CDF is called. The order of the fast Fourier transform ( FFT) used to calculate the spectral estimates. KC should be a product of small primes such as 2m where m is the smallest integer such that 2m2n, provided m20.
  • KC2×NXY;
  • KC must be a multiple of L. 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.
9:     XG(KC) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the NXY data points of the x series.
On exit: the real parts of the NG cross spectral estimates in elements XG1 to XGNG, and XGNG+1 to XGKC contain 0.0. The y series leads the x series.
10:   YG(KC) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the NXY data points of the y series.
On exit: the imaginary parts of the NG cross spectral estimates in elements YG1 to YGNG, and YGNG+1 to YGKC contain 0.0. The y series leads the x series.
11:   NG – INTEGEROutput
On exit: the number of spectral estimates, L/2+1, whose separate parts are held in XG and YG.
12:   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:
On entry,NXY<1,
orPW<0.0 and MWNXY,
orPW>1.0 and MWNXY,
On entry,KC<2×NXY,
orKC is not a multiple of L,
orKC has a prime factor exceeding 19,
orKC has more than 20 prime factors, counting repetitions.
This indicates that a serious error has occurred. Check all array subscripts in calls to G13CDF. Seek expert help.

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

G13CDF carries out an FFT of length KC to calculate the sample cross spectrum. The time taken by the routine for this is approximately proportional to KC×logKC (but see routine document C06PAF for further details).

9  Example

This example reads two time series of length 296. It selects mean correction and a 10% tapering proportion. It selects a 2π/16 frequency width of smoothing window, a window shape parameter of 0.5 and an alignment shift of 3. It then calls G13CDF to calculate the smoothed sample cross spectrum and prints the results.

9.1  Program Text

Program Text (g13cdfe.f90)

9.2  Program Data

Program Data (g13cdfe.d)

9.3  Program Results

Program Results (g13cdfe.r)

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

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