NAG Library Routine Document
G13CCF
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
,
, 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
G13CAF. 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
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
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 Parameters
- 1: NXY – INTEGERInput
On entry: , the length of the time series and .
Constraint:
.
- 2: MTXY – INTEGERInput
On entry: if cross-covariances are to be calculated by the routine (
),
MTXY 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 is not used.
Constraint:
if , , or .
- 3: PXY – REAL (KIND=nag_wp)Input
On entry: if cross-covariances are to be calculated by the routine (
),
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 routine or supplied in the call to the routine.
- 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 routine or supplied in the call to the routine.
Constraint:
.
- 9: CXY(NC) – REAL (KIND=nag_wp) arrayInput/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) – REAL (KIND=nag_wp) arrayInput/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: 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 , ;
- if , .
- 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
series. If covariances are supplied,
XG need not be set.
On exit: contains the real parts of the
NG complex spectral estimates in elements
to
, and
to
contain
. The
series leads the
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
series. If covariances are supplied,
YG need not be set.
On exit: contains the imaginary parts of the
NG complex spectral estimates in elements
to
, and
to
contain
. The
series leads the
series.
- 16: NG – INTEGEROutput
On exit: the number,
, of complex spectral estimates, whose separate parts are held in
XG and
YG.
- 17: IFAIL – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. 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
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
On entry, | , |
or | and , |
or | and , |
or | and , |
or | and , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | and , |
or | and . |
On entry, | , |
or | KC has a prime factor exceeding , |
or | KC has more than prime factors, counting repetitions. |
This error only occurs when .
-
On entry, | , |
or | L has a prime factor exceeding , |
or | L has more than 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.
G13CCF 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 G13CCF is therefore dependent on the choice of these values. The time taken for an FFT of length
is approximately proportional to
(but see
Section 8 in C06PAF for further details).
9 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 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)