g13 Chapter Contents
g13 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_tsa_gain_phase_bivar (g13cfc)

## 1  Purpose

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

## 2  Specification

 #include #include
 void nag_tsa_gain_phase_bivar (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)

## 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 ω 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 nag_tsa_cross_spectrum_bivar (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 nag_tsa_gain_phase_bivar (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.

## 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  Arguments

1:     xg[ng]const doubleInput
On entry: the ng univariate spectral estimates, ${f}_{xx}\left(\omega \right)$, for the $x$ series.
2:     yg[ng]const doubleInput
On entry: the ng univariate spectral estimates, ${f}_{yy}\left(\omega \right)$, for the $y$ series.
3:     xyg[ng]const ComplexInput
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:     ngIntegerInput
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:     stats[$4$]const doubleInput
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:     gn[ng]doubleOutput
On exit: the ng gain estimates, $\stackrel{^}{G}\left(\omega \right)$, at each frequency $\omega$.
7:     gnlw[ng]doubleOutput
On exit: the ng lower bounds for the ng gain estimates.
8:     gnup[ng]doubleOutput
On exit: the ng upper bounds for the ng gain estimates.
9:     ph[ng]doubleOutput
On exit: the ng phase estimates, $\stackrel{^}{\varphi }\left(\omega \right)$, at each frequency $\omega$.
10:   phlw[ng]doubleOutput
On exit: the ng lower bounds for the ng phase estimates.
11:   phup[ng]doubleOutput
On exit: the ng upper bounds for the ng phase estimates.
12:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error 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.

## 7  Accuracy

All computations are very stable and yield good accuracy.

The time taken by nag_tsa_gain_phase_bivar (g13cfc) is approximately proportional to ng.

## 9  Example

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 nag_tsa_gain_phase_bivar (g13cfc) to calculate the gain and the phase and their bounds and prints the results.

### 9.1  Program Text

Program Text (g13cfce.c)

### 9.2  Program Data

Program Data (g13cfce.d)

### 9.3  Program Results

Program Results (g13cfce.r)