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\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ω ϕ^ω=arccos cfω Aω , if ​qfω≥0 ϕ^ω=2π-arccos cfω Aω , if ​qfω<0.$
The quantities used in these definitions are obtained as in Description in nag_tsa_multi_spectrum_bivar (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 nag_tsa_multi_spectrum_bivar (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
 $1d 1Wω -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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{xg}\left({\mathbf{ng}}\right)$ – double array
The ng univariate spectral estimates, ${f}_{xx}\left(\omega \right)$, for the $x$ series.
2:     $\mathrm{yg}\left({\mathbf{ng}}\right)$ – double array
The ng univariate spectral estimates, ${f}_{yy}\left(\omega \right)$, for the $y$ series.
3:     $\mathrm{xyrg}\left({\mathbf{ng}}\right)$ – double array
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.
4:     $\mathrm{xyig}\left({\mathbf{ng}}\right)$ – double array
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.
5:     $\mathrm{stats}\left(4\right)$ – double array
The four associated statistics for the univariate spectral estimates for the $x$ and $y$ series. ${\mathbf{stats}}\left(1\right)$ contains the degrees of freedom, ${\mathbf{stats}}\left(2\right)$ and ${\mathbf{stats}}\left(3\right)$ contain the lower and upper bound multiplying factors respectively and ${\mathbf{stats}}\left(4\right)$ holds the bandwidth.
Constraint: ${\mathbf{stats}}\left(1\right)\ge 3.0$.

### Optional Input Parameters

1:     $\mathrm{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: ${\mathbf{ng}}\ge 1$.

### Output Parameters

1:     $\mathrm{gn}\left({\mathbf{ng}}\right)$ – double array
The ng gain estimates, $\stackrel{^}{G}\left(\omega \right)$, at each frequency $\omega$.
2:     $\mathrm{gnlw}\left({\mathbf{ng}}\right)$ – double array
The ng lower bounds for the ng gain estimates.
3:     $\mathrm{gnup}\left({\mathbf{ng}}\right)$ – double array
The ng upper bounds for the ng gain estimates.
4:     $\mathrm{ph}\left({\mathbf{ng}}\right)$ – double array
The ng phase estimates, $\stackrel{^}{\varphi }\left(\omega \right)$, at each frequency $\omega$.
5:     $\mathrm{phlw}\left({\mathbf{ng}}\right)$ – double array
The ng lower bounds for the ng phase estimates.
6:     $\mathrm{phup}\left({\mathbf{ng}}\right)$ – double array
The ng upper bounds for the ng phase estimates.
7:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{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.

${\mathbf{ifail}}=1$
 On entry, ${\mathbf{ng}}<1$, or ${\mathbf{stats}}\left(1\right)<3.0$.
W  ${\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  ${\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  ${\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  ${\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}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
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.

The time taken by nag_tsa_multi_gain_bivar (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 nag_tsa_multi_gain_bivar (g13cf) to calculate the gain and the phase and their bounds and prints the results.
```function g13cf_example

fprintf('g13cf example results\n\n');

% Data
xg = [ 2.03490;     0.51554;     0.07640;
0.01068;     0.00093;     0.00100;
0.00076;     0.00037;     0.00021];
yg = [21.97712;     3.29761;     0.28782;
0.02480;     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;     0.00007];
xyig = ...
[ 0.00000;    -1.19030;     0.04087;
0.00842;     0.00032;    -0.00001;
0.00018;    -0.00016;     0.00000];
ng = numel(xg);

% Statistics
stats = [30.00000;     0.63858;     1.78670;     0.33288];

[gn, gnlw, gnup, ph, phlw, phup, ifail] = ...
g13cf( ...
xg, yg, xyrg, xyig, stats);

% Display results
fprintf('               The Gain\n\n');
fprintf('                    Lower     Upper\n');
fprintf('          Value     bound     bound\n');
for j=1:ng
fprintf('%5d%10.4f%10.4f%10.4f\n', j-1, gn(j), gnlw(j), gnup(j))
end
fprintf('\n              The Phase\n\n');
fprintf('                    Lower     Upper\n');
fprintf('          Value     bound     bound\n');
for j=1:ng
fprintf('%5d%10.4f%10.4f%10.4f\n', j-1, ph(j), phlw(j), phup(j))
end

```
```g13cf example results

The Gain

Lower     Upper
Value     bound     bound
0    3.2188    2.9722    3.4859
1    2.4018    2.1138    2.7290
2    1.7008    1.3748    2.1042
3    0.9237    0.5558    1.5350
4    0.4943    0.1327    1.8415
5    0.3901    0.1002    1.5196
6    0.4161    0.1346    1.2863
7    0.5248    0.1591    1.7306
8    0.3333    0.0103   10.8301

The Phase

Lower     Upper
Value     bound     bound
0    3.1416    3.0619    3.2213
1    4.9915    4.8637    5.1192
2    0.3199    0.1071    0.5328
3    2.1189    1.6109    2.6268
4    2.3716    1.0563    3.6868
5    3.1672    1.8075    4.5270
6    2.5360    1.4074    3.6647
7    5.3147    4.1214    6.5079
8    0.0000   -3.4809    3.4809
```