Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_tsa_multi_gain_bivar (g13cf)

## Purpose

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

## Syntax

[gn, gnlw, gnup, ph, phlw, phup, ifail] = g13cf(xg, yg, xyrg, xyig, stats, 'ng', ng)
[gn, gnlw, gnup, ph, phlw, phup, ifail] = nag_tsa_multi_gain_bivar(xg, yg, xyrg, xyig, stats, 'ng', ng)

## Description

Estimates of the gain G(ω)$G\left(\omega \right)$ and phase φ(ω)$\varphi \left(\omega \right)$ of the dependency of series y$y$ on series x$x$ at frequency ω$\omega$ are given by
 Ĝ(ω) = (A(ω))/(fxx(ω)) ϕ̂(ω) = arccos((cf(ω))/(A(ω))), if ​qf(ω) ≥ 0 ϕ̂(ω) = 2π − arccos((cf(ω))/(A(ω))), if ​qf(ω) < 0.
$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 [Description] in (g13ce).
Confidence limits are returned for both gain and phase, but should again be taken as very approximate when the coherency W(ω)$W\left(\omega \right)$, as calculated by nag_tsa_multi_spectrum_bivar (g13ce), is not significant. These are based on the assumption that both ((ω) / G(ω))1$\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) . $1d (1W(ω) -1) .$
Although the estimate of φ(ω)$\varphi \left(\omega \right)$ is always given in the range [0,2π)$\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

## Parameters

### Compulsory Input Parameters

1:     xg(ng) – double array
ng, the dimension of the array, must satisfy the constraint ng1${\mathbf{ng}}\ge 1$.
The ng univariate spectral estimates, fxx(ω)${f}_{xx}\left(\omega \right)$, for the x$x$ series.
2:     yg(ng) – double array
ng, the dimension of the array, must satisfy the constraint ng1${\mathbf{ng}}\ge 1$.
The ng univariate spectral estimates, fyy(ω)${f}_{yy}\left(\omega \right)$, for the y$y$ series.
3:     xyrg(ng) – double array
ng, the dimension of the array, must satisfy the constraint ng1${\mathbf{ng}}\ge 1$.
The real parts, cf(ω)$cf\left(\omega \right)$, of the ng bivariate spectral estimates for the x$x$ and y$y$ series. The x$x$ series leads the y$y$ series.
4:     xyig(ng) – double array
ng, the dimension of the array, must satisfy the constraint ng1${\mathbf{ng}}\ge 1$.
The imaginary parts, qf(ω)$qf\left(\omega \right)$, of the ng bivariate spectral estimates for the x$x$ and y$y$ series. The x$x$ series leads the y$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:     stats(4$4$) – double array
The four associated statistics for the univariate spectral estimates for the x$x$ and y$y$ series. stats(1)${\mathbf{stats}}\left(1\right)$ contains the degrees of freedom, stats(2)${\mathbf{stats}}\left(2\right)$ and stats(3)${\mathbf{stats}}\left(3\right)$ contain the lower and upper bound multiplying factors respectively and stats(4)${\mathbf{stats}}\left(4\right)$ holds the bandwidth.
Constraint: stats(1)3.0${\mathbf{stats}}\left(1\right)\ge 3.0$.

### Optional Input Parameters

1:     ng – int64int32nag_int scalar
Default: The dimension of the arrays xg, yg, xyrg, xyig. (An error is raised if these dimensions are not equal.)
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: ng1${\mathbf{ng}}\ge 1$.

None.

### Output Parameters

1:     gn(ng) – double array
The ng gain estimates, (ω)$\stackrel{^}{G}\left(\omega \right)$, at each frequency ω$\omega$.
2:     gnlw(ng) – double array
The ng lower bounds for the ng gain estimates.
3:     gnup(ng) – double array
The ng upper bounds for the ng gain estimates.
4:     ph(ng) – double array
The ng phase estimates, ϕ̂(ω)$\stackrel{^}{\varphi }\left(\omega \right)$, at each frequency ω$\omega$.
5:     phlw(ng) – double array
The ng lower bounds for the ng phase estimates.
6:     phup(ng) – double array
The ng upper bounds for the ng phase estimates.
7:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

ifail = 1${\mathbf{ifail}}=1$
 On entry, ng < 1${\mathbf{ng}}<1$, or stats(1) < 3.0${\mathbf{stats}}\left(1\right)<3.0$.
W ifail = 2${\mathbf{ifail}}=2$
A bivariate spectral estimate is zero. For this frequency the gain and the phase and their bounds are set to zero.
W ifail = 3${\mathbf{ifail}}=3$
A univariate spectral estimate is negative. For this frequency the gain and the phase and their bounds are set to zero.
W ifail = 4${\mathbf{ifail}}=4$
A univariate spectral estimate is zero. For this frequency the gain and the phase and their bounds are set to zero.
W ifail = 5${\mathbf{ifail}}=5$
A calculated value of the squared coherency exceeds 1.0$1.0$. For this frequency the squared coherency is reset to 1.0$1.0$ in the formulae for the gain and phase bounds.
If more than one failure of types 2$2$, 3$3$, 4$4$ and 5$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.

The time taken by nag_tsa_multi_gain_bivar (g13cf) is approximately proportional to ng.

## Example

```function nag_tsa_multi_gain_bivar_example
xg = [2.0349;
0.51554;
0.0764;
0.01068;
0.00093;
0.001;
0.00076;
0.00037;
0.00021];
yg = [21.97712;
3.29761;
0.28782;
0.0248;
0.00285;
0.00203;
0.00125;
0.00107;
0.00191];
xyrg = [-6.54995;
0.34107;
0.12335;
-0.00514;
-0.00033;
-0.00039;
-0.00026;
0.00011;
7e-05];
xyig = [0;
-1.1903;
0.04087;
0.00842;
0.00032;
-1e-05;
0.00018;
-0.00016;
0];
stats = [30;
0.63858;
1.7867;
0.33288];
[gn, gnlw, gnup, ph, phlw, phup, ifail] = nag_tsa_multi_gain_bivar(xg, yg, xyrg, xyig, stats)
```
```

gn =

3.2188
2.4018
1.7008
0.9237
0.4943
0.3901
0.4161
0.5248
0.3333

gnlw =

2.9722
2.1138
1.3748
0.5558
0.1327
0.1002
0.1346
0.1591
0.0103

gnup =

3.4859
2.7290
2.1042
1.5350
1.8415
1.5196
1.2863
1.7306
10.8301

ph =

3.1416
4.9915
0.3199
2.1189
2.3716
3.1672
2.5360
5.3147
0

phlw =

3.0619
4.8637
0.1071
1.6109
1.0563
1.8075
1.4074
4.1214
-3.4809

phup =

3.2213
5.1192
0.5328
2.6268
3.6868
4.5270
3.6647
6.5079
3.4809

ifail =

0

```
```function g13cf_example
xg = [2.0349;
0.51554;
0.0764;
0.01068;
0.00093;
0.001;
0.00076;
0.00037;
0.00021];
yg = [21.97712;
3.29761;
0.28782;
0.0248;
0.00285;
0.00203;
0.00125;
0.00107;
0.00191];
xyrg = [-6.54995;
0.34107;
0.12335;
-0.00514;
-0.00033;
-0.00039;
-0.00026;
0.00011;
7e-05];
xyig = [0;
-1.1903;
0.04087;
0.00842;
0.00032;
-1e-05;
0.00018;
-0.00016;
0];
stats = [30;
0.63858;
1.7867;
0.33288];
[gn, gnlw, gnup, ph, phlw, phup, ifail] = g13cf(xg, yg, xyrg, xyig, stats)
```
```

gn =

3.2188
2.4018
1.7008
0.9237
0.4943
0.3901
0.4161
0.5248
0.3333

gnlw =

2.9722
2.1138
1.3748
0.5558
0.1327
0.1002
0.1346
0.1591
0.0103

gnup =

3.4859
2.7290
2.1042
1.5350
1.8415
1.5196
1.2863
1.7306
10.8301

ph =

3.1416
4.9915
0.3199
2.1189
2.3716
3.1672
2.5360
5.3147
0

phlw =

3.0619
4.8637
0.1071
1.6109
1.0563
1.8075
1.4074
4.1214
-3.4809

phup =

3.2213
5.1192
0.5328
2.6268
3.6868
4.5270
3.6647
6.5079
3.4809

ifail =

0

```