G13 Chapter Contents
G13 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG13CFF

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.

## 1  Purpose

For a bivariate time series, G13CFF calculates the gain and phase together with lower and upper bounds from the univariate and bivariate spectra.

## 2  Specification

 SUBROUTINE G13CFF ( XG, YG, XYRG, XYIG, NG, STATS, GN, GNLW, GNUP, PH, PHLW, PHUP, IFAIL)
 INTEGER NG, IFAIL REAL (KIND=nag_wp) XG(NG), YG(NG), XYRG(NG), XYIG(NG), STATS(4), GN(NG), GNLW(NG), GNUP(NG), PH(NG), PHLW(NG), PHUP(NG)

## 3  Description

Estimates of the gain $G\left(\omega \right)$ and phase $\varphi \left(\omega \right)$ of the dependency of series $y$ on series $x$ at frequency $\omega$ are given by
 $G^ω= Aω fxxω ϕ^ω=arccos cfω Aω , if ​qfω≥0 ϕ^ω=2π-arccos cfω Aω , if ​qfω<0.$
The quantities used in these definitions are obtained as in Section 3 in G13CEF.
Confidence limits are returned for both gain and phase, but should again be taken as very approximate when the coherency $W\left(\omega \right)$, as calculated by G13CEF, is not significant. These are based on the assumption that both $\left(\stackrel{^}{G}\left(\omega \right)/G\left(\omega \right)\right)-1$ and $\stackrel{^}{\varphi }\left(\omega \right)$ are Normal with variance
 $1d 1Wω -1 .$
Although the estimate of $\varphi \left(\omega \right)$ is always given in the range $\left[0,2\pi \right)$, no attempt is made to restrict its confidence limits to this range.

## 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:     XG(NG) – REAL (KIND=nag_wp) arrayInput
On entry: the NG univariate spectral estimates, ${f}_{xx}\left(\omega \right)$, for the $x$ series.
2:     YG(NG) – REAL (KIND=nag_wp) arrayInput
On entry: the NG univariate spectral estimates, ${f}_{yy}\left(\omega \right)$, for the $y$ series.
3:     XYRG(NG) – REAL (KIND=nag_wp) arrayInput
On entry: the real parts, $cf\left(\omega \right)$, of the NG bivariate spectral estimates for the $x$ and $y$ series. The $x$ series leads the $y$ series.
4:     XYIG(NG) – REAL (KIND=nag_wp) arrayInput
On entry: the imaginary parts, $qf\left(\omega \right)$, of the NG bivariate spectral estimates for the $x$ and $y$ series. The $x$ series leads the $y$ series.
Note:  the two univariate and the bivariate spectra must each have been calculated using the same method of smoothing. For rectangular, Bartlett, Tukey or Parzen smoothing windows, the same cut-off point of lag window and the same frequency division of the spectral estimates must be used. For the trapezium frequency smoothing window, the frequency width and the shape of the window and the frequency division of the spectral estimates must be the same. The spectral estimates and statistics must also be unlogged.
5:     NG – INTEGERInput
On entry: the number of spectral estimates in each of the arrays XG, YG, XYRG and XYIG. It is also the number of gain and phase estimates.
Constraint: ${\mathbf{NG}}\ge 1$.
6:     STATS($4$) – REAL (KIND=nag_wp) arrayInput
On entry: the four associated statistics for the univariate spectral estimates for the $x$ and $y$ series. ${\mathbf{STATS}}\left(1\right)$ contains the degrees of freedom, ${\mathbf{STATS}}\left(2\right)$ and ${\mathbf{STATS}}\left(3\right)$ contain the lower and upper bound multiplying factors respectively and ${\mathbf{STATS}}\left(4\right)$ holds the bandwidth.
Constraint: ${\mathbf{STATS}}\left(1\right)\ge 3.0$.
7:     GN(NG) – REAL (KIND=nag_wp) arrayOutput
On exit: the NG gain estimates, $\stackrel{^}{G}\left(\omega \right)$, at each frequency $\omega$.
8:     GNLW(NG) – REAL (KIND=nag_wp) arrayOutput
On exit: the NG lower bounds for the NG gain estimates.
9:     GNUP(NG) – REAL (KIND=nag_wp) arrayOutput
On exit: the NG upper bounds for the NG gain estimates.
10:   PH(NG) – REAL (KIND=nag_wp) arrayOutput
On exit: the NG phase estimates, $\stackrel{^}{\varphi }\left(\omega \right)$, at each frequency $\omega$.
11:   PHLW(NG) – REAL (KIND=nag_wp) arrayOutput
On exit: the NG lower bounds for the NG phase estimates.
12:   PHUP(NG) – REAL (KIND=nag_wp) arrayOutput
On exit: the NG upper bounds for the NG phase estimates.
13:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ 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\text{​ 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 $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{NG}}<1$, or ${\mathbf{STATS}}\left(1\right)<3.0$.
${\mathbf{IFAIL}}=2$
A bivariate spectral estimate is zero. For this frequency the gain and the phase and their bounds are set to zero.
${\mathbf{IFAIL}}=3$
A univariate spectral estimate is negative. For this frequency the gain and the phase and their bounds are set to zero.
${\mathbf{IFAIL}}=4$
A univariate spectral estimate is zero. For this frequency the gain and the phase and their bounds are set to zero.
${\mathbf{IFAIL}}=5$
A calculated value of the squared coherency exceeds $1.0$. For this frequency the squared coherency is reset to $1.0$ in the formulae for the gain and phase bounds.
If more than one failure of types $2$, $3$, $4$ and $5$ occurs then the failure type which occurred at lowest frequency is returned in IFAIL. However the actions indicated above are also carried out for failures at higher frequencies.

## 7  Accuracy

All computations are very stable and yield good accuracy.

The time taken by G13CFF is approximately proportional to NG.

## 9  Example

This example reads the set of univariate spectrum statistics, the two univariate spectra and the cross spectrum at a frequency division of $\frac{2\pi }{20}$ for a pair of time series. It calls G13CFF to calculate the gain and the phase and their bounds and prints the results.

### 9.1  Program Text

Program Text (g13cffe.f90)

### 9.2  Program Data

Program Data (g13cffe.d)

### 9.3  Program Results

Program Results (g13cffe.r)