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_uni_spectrum_daniell (g13cb)

Purpose

nag_tsa_uni_spectrum_daniell (g13cb) calculates the smoothed sample spectrum of a univariate time series using spectral smoothing by the trapezium frequency (Daniell) window.

Syntax

[xg, ng, stats, ifail] = g13cb(nx, mtx, px, mw, pw, l, lg, xg, 'kc', kc)
[xg, ng, stats, ifail] = nag_tsa_uni_spectrum_daniell(nx, mtx, px, mw, pw, l, lg, xg, 'kc', kc)

Description

The supplied time series may be mean or trend corrected (by least squares), and tapered, the tapering factors being those of the split cosine bell:
 (1/2) (1 − cos(π(t − (1/2)) / T)) , 1 ≤ t ≤ T (1/2) (1 − cos(π(n − t + (1/2)) / T)) , n + 1 − T ≤ t ≤ n 1, otherwise,
$12 (1-cos(π (t-12) /T)) , 1≤t≤T 12 (1-cos(π (n-t+12) /T)) , n+1-T≤t≤n 1, otherwise,$
where T = [(np)/2]$T=\left[\frac{np}{2}\right]$ and p$p$ is the tapering proportion.
The unsmoothed sample spectrum
f*(ω) = 1/(2π)
 (n ) ∑ xtexp(iωt)t = 1 2
$f*(ω)=12π |∑t=1nxtexp(iω t)| 2$
is then calculated for frequency values
 ωk = (2 π k)/K,   k = 0,1, … ,[K / 2], $ωk=2 π kK, k= 0,1,…,[K/2],$
where [ ] denotes the integer part.
The smoothed spectrum is returned as a subset of these frequencies for which k$k$ is a multiple of a chosen value r$r$, i.e.,
 ωrl = νl = (2πl)/L,  l = 0,1, … ,[L / 2], $ωrl=νl=2πlL, l=0,1,…,[L/2],$
where K = r × L$K=r×L$. You will normally fix L$L$ first, then choose r$r$ so that K$K$ is sufficiently large to provide an adequate representation for the unsmoothed spectrum, i.e., K2 × n$K\ge 2×n$. It is possible to take L = K$L=K$, i.e., r = 1$r=1$.
The smoothing is defined by a trapezium window whose shape is supplied by the function
 W(α) = 1, |α| ≤ p W(α) = (1 − |α|)/(1 − p), p < |α| ≤ 1
$W(α)=1, |α|≤p W(α)=1-|α| 1-p , p<|α|≤1$
the proportion p$p$ being supplied by you.
The width of the window is fixed as 2π / M$2\pi /M$ by you supplying M$M$. A set of averaging weights are constructed:
 Wk = g × W ((ωkM)/π) ,  0 ≤ ωk ≤ π/M, $Wk=g×W (ωkM π ) , 0≤ωk≤πM,$
where g$g$ is a normalizing constant, and the smoothed spectrum obtained is
 f̂(νl) = ∑|ωk| < π/MWkf*(νl + ωk). $f^(νl)=∑|ωk|< πMWkf*(νl+ωk).$
If no smoothing is required M$M$ should be set to n$n$, in which case the values returned are (νl) = f*(νl)$\stackrel{^}{f}\left({\nu }_{l}\right)={f}^{*}\left({\nu }_{l}\right)$. Otherwise, in order that the smoothing approximates well to an integration, it is essential that KM$K\gg M$, and preferable, but not essential, that K$K$ be a multiple of M$M$. A choice of L > M$L>M$ would normally be required to supply an adequate description of the smoothed spectrum. Typical choices of Ln$L\simeq n$ and K4n$K\simeq 4n$ should be adequate for usual smoothing situations when M < n / 5$M.
The sampling distribution of (ω)$\stackrel{^}{f}\left(\omega \right)$ is approximately that of a scaled χd2${\chi }_{d}^{2}$ variate, whose degrees of freedom d$d$ is provided by the function, together with multiplying limits mu$mu$, ml$ml$ from which approximate 95% confidence intervals for the true spectrum f(ω)$f\left(\omega \right)$ may be constructed as [ ml × (ω) mu × (ω) ] $\left[ml×\stackrel{^}{f}\left(\omega \right)mu×\stackrel{^}{f}\left(\omega \right)\right]$. Alternatively, log (ω)$\stackrel{^}{f}\left(\omega \right)$ may be returned, with additive limits.
The bandwidth b$b$ of the corresponding smoothing window in the frequency domain is also provided. Spectrum estimates separated by (angular) frequencies much greater than b$b$ may be assumed to be independent.

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:     nx – int64int32nag_int scalar
n$n$, the length of the time series.
Constraint: nx1${\mathbf{nx}}\ge 1$.
2:     mtx – int64int32nag_int scalar
Whether the data are to be initially mean or trend corrected.
mtx = 0${\mathbf{mtx}}=0$
For no correction.
mtx = 1${\mathbf{mtx}}=1$
For mean correction.
mtx = 2${\mathbf{mtx}}=2$
For trend correction.
Constraint: 0mtx2$0\le {\mathbf{mtx}}\le 2$.
3:     px – double scalar
The proportion of the data (totalled over both ends) to be initially tapered by the split cosine bell taper. (A value of 0.0$0.0$ implies no tapering.)
Constraint: 0.0px1.0$0.0\le {\mathbf{px}}\le 1.0$.
4:     mw – int64int32nag_int scalar
The value of M$M$ which determines the frequency width of the smoothing window as 2π / M$2\pi /M$. A value of n$n$ implies no smoothing is to be carried out.
Constraint: 1mwnx$1\le {\mathbf{mw}}\le {\mathbf{nx}}$.
5:     pw – double scalar
p$p$, the shape parameter of the trapezium frequency window.
A value of 0.0$0.0$ gives a triangular window, and a value of 1.0$1.0$ a rectangular window.
If mw = nx${\mathbf{mw}}={\mathbf{nx}}$ (i.e., no smoothing is carried out), pw is not used.
Constraint: 0.0pw1.0$0.0\le {\mathbf{pw}}\le 1.0$.
6:     l – int64int32nag_int scalar
L$L$, the frequency division of smoothed spectral estimates as 2π / L$2\pi /L$.
Constraints:
• l1${\mathbf{l}}\ge 1$;
• l must be a factor of kc.
7:     lg – int64int32nag_int scalar
Indicates whether unlogged or logged spectral estimates and confidence limits are required.
lg = 0${\mathbf{lg}}=0$
For unlogged.
lg0${\mathbf{lg}}\ne 0$
For logged.
8:     xg(kc) – double array
kc, the dimension of the array, must satisfy the constraint
• kc2 × nx${\mathbf{kc}}\ge 2×{\mathbf{nx}}$
• kc must be a multiple of l. The largest prime factor of kc must not exceed 19$19$, and the total number of prime factors of kc, counting repetitions, must not exceed 20$20$. These two restrictions are imposed by the internal FFT algorithm used
• .
The n$n$ data points.

Optional Input Parameters

1:     kc – int64int32nag_int scalar
Default: The dimension of the array xg.
K$K$, the order of the fast Fourier transform (FFT) used to calculate the spectral estimates. kc should be a multiple of small primes such as 2m${2}^{m}$ where m$m$ is the smallest integer such that 2m2n${2}^{m}\ge 2n$, provided m20$m\le 20$.
Constraints:
• kc2 × nx${\mathbf{kc}}\ge 2×{\mathbf{nx}}$;
• kc must be a multiple of l. The largest prime factor of kc must not exceed 19$19$, and the total number of prime factors of kc, counting repetitions, must not exceed 20$20$. These two restrictions are imposed by the internal FFT algorithm used.

None.

Output Parameters

1:     xg(kc) – double array
Contains the ng spectral estimates (ωi)$\stackrel{^}{f}\left({\omega }_{\mathit{i}}\right)$, for i = 0,1,,[L / 2]$\mathit{i}=0,1,\dots ,\left[L/2\right]$, in xg(1)${\mathbf{xg}}\left(1\right)$ to xg(ng)${\mathbf{xg}}\left({\mathbf{ng}}\right)$ (logged if lg0${\mathbf{lg}}\ne 0$). The elements xg(i)${\mathbf{xg}}\left(\mathit{i}\right)$, for i = ng + 1,,kc$\mathit{i}={\mathbf{ng}}+1,\dots ,{\mathbf{kc}}$, contain 0.0$0.0$.
2:     ng – int64int32nag_int scalar
The number of spectral estimates, [L / 2] + 1$\left[L/2\right]+1$, in xg.
3:     stats(4$4$) – double array
Four associated statistics. These are the degrees of freedom in stats(1)${\mathbf{stats}}\left(1\right)$, the lower and upper 95%$95%$ confidence limit factors in stats(2)${\mathbf{stats}}\left(2\right)$ and stats(3)${\mathbf{stats}}\left(3\right)$ respectively (logged if lg0${\mathbf{lg}}\ne 0$), and the bandwidth in stats(4)${\mathbf{stats}}\left(4\right)$.
4:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Note: nag_tsa_uni_spectrum_daniell (g13cb) may return useful information for one or more of the following detected errors or 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, nx < 1${\mathbf{nx}}<1$, or mtx < 0${\mathbf{mtx}}<0$, or mtx > 2${\mathbf{mtx}}>2$, or px < 0.0${\mathbf{px}}<0.0$, or px > 1.0${\mathbf{px}}>1.0$, or mw < 1${\mathbf{mw}}<1$, or mw > nx${\mathbf{mw}}>{\mathbf{nx}}$, or pw < 0.0${\mathbf{pw}}<0.0$ and mw ≠ nx${\mathbf{mw}}\ne {\mathbf{nx}}$, or pw > 1.0${\mathbf{pw}}>1.0$ and mw ≠ nx${\mathbf{mw}}\ne {\mathbf{nx}}$, or l < 1${\mathbf{l}}<1$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, kc < 2 × nx${\mathbf{kc}}<2×{\mathbf{nx}}$, or kc is not a multiple of l, or kc has a prime factor exceeding 19$19$, or kc has more than 20$20$ prime factors, counting repetitions.
ifail = 3${\mathbf{ifail}}=3$
This indicates that a serious error has occurred. Check all array subscripts and function parameter lists in calls to nag_tsa_uni_spectrum_daniell (g13cb). Seek expert help.
W ifail = 4${\mathbf{ifail}}=4$
One or more spectral estimates are negative. Unlogged spectral estimates are returned in xg, and the degrees of freedom, unlogged confidence limit factors and bandwidth in stats.
W ifail = 5${\mathbf{ifail}}=5$
The calculation of confidence limit factors has failed. This error will not normally occur. Spectral estimates (logged if requested) are returned in xg, and degrees of freedom and bandwidth in stats.

Accuracy

The FFT is a numerically stable process, and any errors introduced during the computation will normally be insignificant compared with uncertainty in the data.

nag_tsa_uni_spectrum_daniell (g13cb) carries out a FFT of length kc to calculate the sample spectrum. The time taken by the function for this is approximately proportional to kc × log(kc)${\mathbf{kc}}×\mathrm{log}\left({\mathbf{kc}}\right)$ (but see Section [Further Comments] in (c06pa) for further details).

Example

```function nag_tsa_uni_spectrum_daniell_example
nx = int64(131);
mtx = int64(1);
px = 0.2;
mw = int64(131);
pw = 0.5;
l = int64(100);
lg = int64(1);
xg = zeros(400, 1);
xg(1:131) = [11.5;
9.89;
8.728;
8.4;
8.23;
8.365;
8.383;
8.243;
8.08;
8.244;
8.49;
8.867;
9.469;
9.786;
10.1;
10.714;
11.32;
11.9;
12.39;
12.095;
11.8;
12.4;
11.833;
12.2;
12.242;
11.687;
10.883;
10.138;
8.952;
8.443;
8.231;
8.067;
7.871;
7.962;
8.217;
8.689;
8.989;
9.45;
9.883;
10.15;
10.787;
11;
11.133;
11.1;
11.8;
12.25;
11.35;
11.575;
11.8;
11.1;
10.3;
9.725;
9.025;
8.048;
7.294;
7.07;
6.933;
7.208;
7.617;
7.867;
8.309;
8.64;
9.179;
9.57;
10.063;
10.803;
11.547;
11.55;
11.8;
12.2;
12.4;
12.367;
12.35;
12.4;
12.27;
12.3;
11.8;
10.794;
9.675;
8.9;
8.208;
8.087;
7.763;
7.917;
8.03;
8.212;
8.669;
9.175;
9.683;
10.29;
10.4;
10.85;
11.7;
11.9;
12.5;
12.5;
12.8;
12.95;
13.05;
12.8;
12.8;
12.8;
12.6;
11.917;
10.805;
9.24;
8.777;
8.683;
8.649;
8.547;
8.625;
8.75;
9.11;
9.392;
9.787;
10.34;
10.5;
11.233;
12.033;
12.2;
12.3;
12.6;
12.8;
12.65;
12.733;
12.7;
12.259;
11.817;
10.767;
9.825;
9.15];
[xgOut, ng, stats, ifail] = nag_tsa_uni_spectrum_daniell(nx, mtx, px, mw, pw, l, lg, xg);
ng, stats, ifail
```
```

ng =

51

stats =

2.0000
-1.3053
3.6762
0.0480

ifail =

0

```
```function g13cb_example
nx = int64(131);
mtx = int64(1);
px = 0.2;
mw = int64(131);
pw = 0.5;
l = int64(100);
lg = int64(1);
xg = zeros(400, 1);
xg(1:131) = [11.5;
9.89;
8.728;
8.4;
8.23;
8.365;
8.383;
8.243;
8.08;
8.244;
8.49;
8.867;
9.469;
9.786;
10.1;
10.714;
11.32;
11.9;
12.39;
12.095;
11.8;
12.4;
11.833;
12.2;
12.242;
11.687;
10.883;
10.138;
8.952;
8.443;
8.231;
8.067;
7.871;
7.962;
8.217;
8.689;
8.989;
9.45;
9.883;
10.15;
10.787;
11;
11.133;
11.1;
11.8;
12.25;
11.35;
11.575;
11.8;
11.1;
10.3;
9.725;
9.025;
8.048;
7.294;
7.07;
6.933;
7.208;
7.617;
7.867;
8.309;
8.64;
9.179;
9.57;
10.063;
10.803;
11.547;
11.55;
11.8;
12.2;
12.4;
12.367;
12.35;
12.4;
12.27;
12.3;
11.8;
10.794;
9.675;
8.9;
8.208;
8.087;
7.763;
7.917;
8.03;
8.212;
8.669;
9.175;
9.683;
10.29;
10.4;
10.85;
11.7;
11.9;
12.5;
12.5;
12.8;
12.95;
13.05;
12.8;
12.8;
12.8;
12.6;
11.917;
10.805;
9.24;
8.777;
8.683;
8.649;
8.547;
8.625;
8.75;
9.11;
9.392;
9.787;
10.34;
10.5;
11.233;
12.033;
12.2;
12.3;
12.6;
12.8;
12.65;
12.733;
12.7;
12.259;
11.817;
10.767;
9.825;
9.15];
[xgOut, ng, stats, ifail] = g13cb(nx, mtx, px, mw, pw, l, lg, xg);
ng, stats, ifail
```
```

ng =

51

stats =

2.0000
-1.3053
3.6762
0.0480

ifail =

0

```