NAG FL Interface
g13cdf (multi_​spectrum_​daniell)

Settings help

FL Name Style:


FL Specification Language:


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

Fortran Interface
Subroutine g13cdf ( nxy, mtxy, pxy, mw, ish, pw, l, kc, xg, yg, ng, ifail)
Integer, Intent (In) :: nxy, mtxy, mw, ish, l, kc
Integer, Intent (Inout) :: ifail
Integer, Intent (Out) :: ng
Real (Kind=nag_wp), Intent (In) :: pxy, pw
Real (Kind=nag_wp), Intent (Inout) :: xg(kc), yg(kc)
C Header Interface
#include <nag.h>
void  g13cdf_ (const Integer *nxy, const Integer *mtxy, const double *pxy, const Integer *mw, const Integer *ish, const double *pw, const Integer *l, const Integer *kc, double xg[], double yg[], Integer *ng, Integer *ifail)
The routine may be called by the names g13cdf or nagf_tsa_multi_spectrum_daniell.

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 ytexp(iωt)} × { t=1 n xtexp(-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 cxy(k) 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 Arguments

1: nxy Integer Input
On entry: n, the length of the time series x and y.
Constraint: nxy1.
2: mtxy Integer Input
On entry: 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.
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 Integer Input
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 Integer Input
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 Integer Input
On entry: L, the frequency division of smoothed cross spectral estimates as 2πL .
Constraints:
  • l1;
  • l must be a factor of kc.
8: kc Integer Input
On entry: the order of the fast Fourier transform (FFT) used to calculate the spectral estimates.
Constraints:
  • kc2×nxy;
  • kc must be a multiple of l.
9: xg(kc) Real (Kind=nag_wp) array Input/Output
On entry: the nxy data points of the x series.
On exit: the real parts of the ng cross spectral estimates in elements xg(1) to xg(ng), and xg(ng+1) to xg(kc) contain 0.0. The y series leads the x series.
10: yg(kc) Real (Kind=nag_wp) array Input/Output
On entry: the nxy data points of the y series.
On exit: the imaginary parts of the ng cross spectral estimates in elements yg(1) to yg(ng), and yg(ng+1) to yg(kc) contain 0.0. The y series leads the x series.
11: ng Integer Output
On exit: the number of spectral estimates, [L/2]+1, whose separate parts are held in xg and yg.
12: ifail Integer Input/Output
On entry: ifail must be set to 0, −1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of −1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value −1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. 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, ish=value and l=value.
Constraint: |ish|<l.
On entry, l=value.
Constraint: l1.
On entry, mtxy=value.
Constraint: mtxy2.
On entry, mtxy=value.
Constraint: mtxy0.
On entry, mw=value.
Constraint: mw1.
On entry, mw=value and nxy=value.
Constraint: mwnxy.
On entry, nxy=value.
Constraint: nxy1.
On entry, pxy=value, mw=value and nxy=value.
Constraint: if pw<0.0, mw=nxy.
On entry, pxy=value, mw=value and nxy=value.
Constraint: if pw>1.0, mw=nxy.
On entry, pxy=value.
Constraint: pxy1.0.
On entry, pxy=value.
Constraint: pxy0.0.
ifail=2
On entry, kc=value and l=value.
Constraint: kc must be a multiple of l.
On entry, kc=value and nxy=value.
Constraint: kc2×nxy.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface 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

g13cdf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g13cdf 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 routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 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×log(kc) (but see routine document c06paf for further details).

10 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.

10.1 Program Text

Program Text (g13cdfe.f90)

10.2 Program Data

Program Data (g13cdfe.d)

10.3 Program Results

Program Results (g13cdfe.r)