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

# Syntax

C#
```public static void g13cf(
double[] xg,
double[] yg,
double[] xyrg,
double[] xyig,
int ng,
double[] stats,
double[] gn,
double[] gnlw,
double[] gnup,
double[] ph,
double[] phlw,
double[] phup,
out int ifail
)```
Visual Basic
```Public Shared Sub g13cf ( _
xg As Double(), _
yg As Double(), _
xyrg As Double(), _
xyig As Double(), _
ng As Integer, _
stats As Double(), _
gn As Double(), _
gnlw As Double(), _
gnup As Double(), _
ph As Double(), _
phlw As Double(), _
phup As Double(), _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g13cf(
array<double>^ xg,
array<double>^ yg,
array<double>^ xyrg,
array<double>^ xyig,
int ng,
array<double>^ stats,
array<double>^ gn,
array<double>^ gnlw,
array<double>^ gnup,
array<double>^ ph,
array<double>^ phlw,
array<double>^ phup,
[OutAttribute] int% ifail
)```
F#
```static member g13cf :
xg : float[] *
yg : float[] *
xyrg : float[] *
xyig : float[] *
ng : int *
stats : float[] *
gn : float[] *
gnlw : float[] *
gnup : float[] *
ph : float[] *
phlw : float[] *
phup : float[] *
ifail : int byref -> unit
```

#### Parameters

xg
Type: array<System..::..Double>[]()[][]
An array of size [ng]
On entry: the ng univariate spectral estimates, ${f}_{xx}\left(\omega \right)$, for the $x$ series.
yg
Type: array<System..::..Double>[]()[][]
An array of size [ng]
On entry: the ng univariate spectral estimates, ${f}_{yy}\left(\omega \right)$, for the $y$ series.
xyrg
Type: array<System..::..Double>[]()[][]
An array of size [ng]
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.
xyig
Type: array<System..::..Double>[]()[][]
An array of size [ng]
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.
ng
Type: System..::..Int32
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$.
stats
Type: array<System..::..Double>[]()[][]
An array of size [$4$]
On entry: the four associated statistics for the univariate spectral estimates for the $x$ and $y$ series. ${\mathbf{stats}}\left[0\right]$ contains the degrees of freedom, ${\mathbf{stats}}\left[1\right]$ and ${\mathbf{stats}}\left[2\right]$ contain the lower and upper bound multiplying factors respectively and ${\mathbf{stats}}\left[3\right]$ holds the bandwidth.
Constraint: ${\mathbf{stats}}\left[0\right]\ge 3.0$.
gn
Type: array<System..::..Double>[]()[][]
An array of size [ng]
On exit: the ng gain estimates, $\stackrel{^}{G}\left(\omega \right)$, at each frequency $\omega$.
gnlw
Type: array<System..::..Double>[]()[][]
An array of size [ng]
On exit: the ng lower bounds for the ng gain estimates.
gnup
Type: array<System..::..Double>[]()[][]
An array of size [ng]
On exit: the ng upper bounds for the ng gain estimates.
ph
Type: array<System..::..Double>[]()[][]
An array of size [ng]
On exit: the ng phase estimates, $\stackrel{^}{\varphi }\left(\omega \right)$, at each frequency $\omega$.
phlw
Type: array<System..::..Double>[]()[][]
An array of size [ng]
On exit: the ng lower bounds for the ng phase estimates.
phup
Type: array<System..::..Double>[]()[][]
An array of size [ng]
On exit: the ng upper bounds for the ng phase estimates.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# 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ωϕ^ω=arccoscfωAω,if ​qfω≥0ϕ^ω=2π-arccoscfωAω,if ​qfω<0.$
The quantities used in these definitions are obtained as in [Description] in g13ce.
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 g13ce, 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
 $1d1Wω-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.

# 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

# Error Indicators and Warnings

Errors or warnings detected by the method:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{ng}}<1$, or ${\mathbf{stats}}\left[0\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.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
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.

# Accuracy

All computations are very stable and yield good accuracy.

# Parallelism and Performance

None.

The time taken by g13cf is approximately proportional to ng.

# 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 g13cf to calculate the gain and the phase and their bounds and prints the results.

Example program (C#): g13cfe.cs

Example program data: g13cfe.d

Example program results: g13cfe.r