# NAG CL Interfaceg13cfc (multi_​gain_​bivar)

## 1Purpose

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

## 2Specification

 #include
 void g13cfc (const double xg[], const double yg[], const Complex xyg[], Integer ng, const double stats[], double gn[], double gnlw[], double gnup[], double ph[], double phlw[], double phup[], NagError *fail)
The function may be called by the names: g13cfc, nag_tsa_multi_gain_bivar or nag_tsa_gain_phase_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 ω f xx ω ϕ ^ ω = 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 g13cec.
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 g13cfc, 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
 $1 d 1 W ω - 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]$const double Input
On entry: the ng univariate spectral estimates, ${f}_{xx}\left(\omega \right)$, for the $x$ series.
2: $\mathbf{yg}\left[{\mathbf{ng}}\right]$const double Input
On entry: the ng univariate spectral estimates, ${f}_{yy}\left(\omega \right)$, for the $y$ series.
3: $\mathbf{xyg}\left[{\mathbf{ng}}\right]$const Complex Input
On entry: ${f}_{xy}\left(\omega \right)$ 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 amount of smoothing. 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.
4: $\mathbf{ng}$Integer Input
On entry: the number of spectral estimates in each of the arrays xg, yg and xyg. It is also the number of gain and phase estimates.
Constraint: ${\mathbf{ng}}\ge 1$.
5: $\mathbf{stats}\left[4\right]$const double Input
On entry: the 4 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$.
6: $\mathbf{gn}\left[{\mathbf{ng}}\right]$double Output
On exit: the ng gain estimates, $\stackrel{^}{G}\left(\omega \right)$, at each frequency $\omega$.
7: $\mathbf{gnlw}\left[{\mathbf{ng}}\right]$double Output
On exit: the ng lower bounds for the ng gain estimates.
8: $\mathbf{gnup}\left[{\mathbf{ng}}\right]$double Output
On exit: the ng upper bounds for the ng gain estimates.
9: $\mathbf{ph}\left[{\mathbf{ng}}\right]$double Output
On exit: the ng phase estimates, $\stackrel{^}{\varphi }\left(\omega \right)$, at each frequency $\omega$.
10: $\mathbf{phlw}\left[{\mathbf{ng}}\right]$double Output
On exit: the ng lower bounds for the ng phase estimates.
11: $\mathbf{phup}\left[{\mathbf{ng}}\right]$double Output
On exit: the ng upper bounds for the ng phase estimates.
12: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_BIVAR_SPECTRAL_ESTIM_ZERO
A bivariate spectral estimate is zero.
For this frequency the gain and the phase and their bounds are set to zero.
NE_INT_ARG_LT
On entry, ${\mathbf{ng}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ng}}\ge 1$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_REAL_ARG_LT
On entry, ${\mathbf{stats}}\left[0\right]$ must not be less than 3.0: ${\mathbf{stats}}\left[0\right]=〈\mathit{\text{value}}〉$.
NE_SQUARED_FREQ_GT_ONE
A calculated value of the squared coherency exceeds one.
For this frequency the squared coherency is reset to $1.0$ in the formulae for the gain and phase bounds.
NE_UNIVAR_SPECTRAL_ESTIM_NEG
A bivariate spectral estimate is negative.
For this frequency the gain and the phase and their bounds are set to zero.
NE_UNIVAR_SPECTRAL_ESTIM_ZERO
A bivariate spectral estimate is zero.
For this frequency the gain and the phase and their bounds are set to zero.

## 7Accuracy

All computations are very stable and yield good accuracy.

## 8Parallelism and Performance

g13cfc is not threaded in any implementation.

The time taken by g13cfc is approximately proportional to ng.

## 10Example

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

### 10.1Program Text

Program Text (g13cfce.c)

### 10.2Program Data

Program Data (g13cfce.d)

### 10.3Program Results

Program Results (g13cfce.r)