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]

- yg
- Type: array<System..::..Double>[]()[][]An array of size [ng]

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

- gnlw
- Type: array<System..::..Double>[]()[][]An array of size [ng]

- gnup
- Type: array<System..::..Double>[]()[][]An array of size [ng]

- ph
- Type: array<System..::..Double>[]()[][]An array of size [ng]

- phlw
- Type: array<System..::..Double>[]()[][]An array of size [ng]

- phup
- Type: array<System..::..Double>[]()[][]An array of size [ng]

- 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

The quantities used in these definitions are obtained as in [Description] in g13ce.

$$\begin{array}{ll}\hat{G}\left(\omega \right)=\frac{A\left(\omega \right)}{{f}_{xx}\left(\omega \right)}& \\ & \\ \hat{\varphi}\left(\omega \right)=\mathrm{arccos}\left(\frac{cf\left(\omega \right)}{A\left(\omega \right)}\right)\text{,}& \text{if}qf\left(\omega \right)\ge 0\\ & \\ \hat{\varphi}\left(\omega \right)=2\pi -\mathrm{arccos}\left(\frac{cf\left(\omega \right)}{A\left(\omega \right)}\right)\text{,}& \text{if}qf\left(\omega \right)<0\text{.}\end{array}$$ |

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(\hat{G}\left(\omega \right)/G\left(\omega \right)\right)-1$ and $\hat{\varphi}\left(\omega \right)$ are Normal with variance

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.

$$\frac{1}{d}\left(\frac{1}{W\left(\omega \right)}-1\right)\text{.}$$ |

# References

Bloomfield P (1976)

*Fourier Analysis of Time Series: An Introduction*WileyJenkins 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 $\u2329\mathit{\text{value}}\u232a$
- ${\mathbf{ifail}}=-6000$
- Invalid Parameters $\u2329\mathit{\text{value}}\u232a$

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.

# Further Comments

# 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