# NAG FL Interfaceg13cff (multi_​gain_​bivar)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine g13cff ( xg, yg, xyrg, xyig, ng, gn, gnlw, gnup, ph, phlw, phup,
 Integer, Intent (In) :: ng Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: xg(ng), yg(ng), xyrg(ng), xyig(ng), stats(4) Real (Kind=nag_wp), Intent (Out) :: gn(ng), gnlw(ng), gnup(ng), ph(ng), phlw(ng), phup(ng)
#include <nag.h>
 void g13cff_ (const double xg[], const double yg[], const double xyrg[], const double xyig[], const Integer *ng, const double stats[], double gn[], double gnlw[], double gnup[], double ph[], double phlw[], double phup[], Integer *ifail)
The routine may be called by the names g13cff or nagf_tsa_multi_gain_bivar.

## 3Description

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

## 5Arguments

1: $\mathbf{xg}\left({\mathbf{ng}}\right)$Real (Kind=nag_wp) array Input
On entry: the ng univariate spectral estimates, ${f}_{xx}\left(\omega \right)$, for the $x$ series.
2: $\mathbf{yg}\left({\mathbf{ng}}\right)$Real (Kind=nag_wp) array Input
On entry: the ng univariate spectral estimates, ${f}_{yy}\left(\omega \right)$, for the $y$ series.
3: $\mathbf{xyrg}\left({\mathbf{ng}}\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{xyig}\left({\mathbf{ng}}\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{ng}$Integer Input
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: $\mathbf{stats}\left(4\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{gn}\left({\mathbf{ng}}\right)$Real (Kind=nag_wp) array Output
On exit: the ng gain estimates, $\stackrel{^}{G}\left(\omega \right)$, at each frequency $\omega$.
8: $\mathbf{gnlw}\left({\mathbf{ng}}\right)$Real (Kind=nag_wp) array Output
On exit: the ng lower bounds for the ng gain estimates.
9: $\mathbf{gnup}\left({\mathbf{ng}}\right)$Real (Kind=nag_wp) array Output
On exit: the ng upper bounds for the ng gain estimates.
10: $\mathbf{ph}\left({\mathbf{ng}}\right)$Real (Kind=nag_wp) array Output
On exit: the ng phase estimates, $\stackrel{^}{\varphi }\left(\omega \right)$, at each frequency $\omega$.
11: $\mathbf{phlw}\left({\mathbf{ng}}\right)$Real (Kind=nag_wp) array Output
On exit: the ng lower bounds for the ng phase estimates.
12: $\mathbf{phup}\left({\mathbf{ng}}\right)$Real (Kind=nag_wp) array Output
On exit: the ng upper bounds for the ng phase estimates.
13: $\mathbf{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 $-\mathbf{1}$ 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{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:
Note: 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.
${\mathbf{ifail}}=1$
On entry, ${\mathbf{ng}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ng}}\ge 1$.
On entry, ${\mathbf{stats}}\left(1\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{stats}}\left(1\right)\ge 3.0$.
${\mathbf{ifail}}=2$
A bivariate spectral estimate is zero. For this frequency the cross amplitude spectrum and shared coherency and their bounds are set to zero.
${\mathbf{ifail}}=3$
A univariate spectral estimate is negative. For this frequency the cross amplitude spectrum and shared coherency and their bounds are set to zero.
${\mathbf{ifail}}=4$
A univariate spectral estimate is zero. For this frequency the cross amplitude spectrum and shared coherency 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.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{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.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

All computations are very stable and yield good accuracy.

## 8Parallelism and Performance

g13cff is not threaded in any implementation.

The time taken by g13cff is approximately proportional to ng.

## 10Example

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.

### 10.1Program Text

Program Text (g13cffe.f90)

### 10.2Program Data

Program Data (g13cffe.d)

### 10.3Program Results

Program Results (g13cffe.r)