g13ca calculates the smoothed sample spectrum of a univariate time series using one of four lag windows – rectangular, Bartlett, Tukey or Parzen window.

Syntax

C#
public static void g13ca(
	int nx,
	int mtx,
	double px,
	int iw,
	int mw,
	int ic,
	int nc,
	double[] c,
	int kc,
	int l,
	int lg,
	double[] xg,
	out int ng,
	double[] stats,
	out int ifail
)
Visual Basic
Public Shared Sub g13ca ( _
	nx As Integer, _
	mtx As Integer, _
	px As Double, _
	iw As Integer, _
	mw As Integer, _
	ic As Integer, _
	nc As Integer, _
	c As Double(), _
	kc As Integer, _
	l As Integer, _
	lg As Integer, _
	xg As Double(), _
	<OutAttribute> ByRef ng As Integer, _
	stats As Double(), _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void g13ca(
	int nx, 
	int mtx, 
	double px, 
	int iw, 
	int mw, 
	int ic, 
	int nc, 
	array<double>^ c, 
	int kc, 
	int l, 
	int lg, 
	array<double>^ xg, 
	[OutAttribute] int% ng, 
	array<double>^ stats, 
	[OutAttribute] int% ifail
)
F#
static member g13ca : 
        nx : int * 
        mtx : int * 
        px : float * 
        iw : int * 
        mw : int * 
        ic : int * 
        nc : int * 
        c : float[] * 
        kc : int * 
        l : int * 
        lg : int * 
        xg : float[] * 
        ng : int byref * 
        stats : float[] * 
        ifail : int byref -> unit 

Parameters

nx
Type: System..::..Int32
On entry: n, the length of the time series.
Constraint: nx1.
mtx
Type: System..::..Int32
On entry: if covariances are to be calculated by the method (ic=0), mtx must specify whether the data are to be initially mean or trend corrected.
mtx=0
For no correction.
mtx=1
For mean correction.
mtx=2
For trend correction.
Constraint: if ic=0, 0mtx2
If covariances are supplied (ic0), mtx is not used.
px
Type: System..::..Double
On entry: if covariances are to be calculated by the method (ic=0), px must specify the proportion of the data (totalled over both ends) to be initially tapered by the split cosine bell taper.
If covariances are supplied ic0, px must specify the proportion of data tapered before the supplied covariances were calculated and after any mean or trend correction. px is required for the calculation of output statistics. A value of 0.0 implies no tapering.
Constraint: 0.0px1.0.
iw
Type: System..::..Int32
On entry: the choice of lag window.
iw=1
Rectangular.
iw=2
Bartlett.
iw=3
Tukey.
iw=4
Parzen.
Constraint: 1iw4.
mw
Type: System..::..Int32
On entry: M, the ‘cut-off’ point of the lag window. Windowed covariances at lag M or greater are zero.
Constraint: 1mwnx.
ic
Type: System..::..Int32
On entry: indicates whether covariances are to be calculated in the method or supplied in the call to the method.
ic=0
Covariances are to be calculated.
ic0
Covariances are to be supplied.
nc
Type: System..::..Int32
On entry: the number of covariances to be calculated in the method or supplied in the call to the method.
Constraint: mwncnx.
c
Type: array<System..::..Double>[]()[][]
An array of size [nc]
On entry: if ic0, c must contain the nc covariances for lags from 0 to nc-1, otherwise c need not be set.
On exit: if ic=0, c will contain the nc calculated covariances.
If ic0, the contents of c will be unchanged.
kc
Type: System..::..Int32
On entry: if ic=0, kc must specify the order of the fast Fourier transform (FFT) used to calculate the covariances. kc should be a product of small primes such as 2m where m is the smallest integer such that 2mnx+nc, provided m20.
If ic0, that is covariances are supplied, kc is not used.
Constraint: kcnx+nc. The largest prime factor of kc must not exceed 19, and the total number of prime factors of kc, counting repetitions, must not exceed 20. These two restrictions are imposed by the internal FFT algorithm used.
l
Type: System..::..Int32
On entry: L, the frequency division of the spectral estimates as 2πL. Therefore it is also the order of the FFT used to construct the sample spectrum from the covariances. l should be a product of small primes such as 2m where m is the smallest integer such that 2m2M-1, provided m20.
Constraint: l2×mw-1. The largest prime factor of l must not exceed 19, and the total number of prime factors of l, counting repetitions, must not exceed 20. These two restrictions are imposed by the internal FFT algorithm used.
lg
Type: System..::..Int32
On entry: indicates whether unlogged or logged spectral estimates and confidence limits are required.
lg=0
Unlogged.
lg0
Logged.
xg
Type: array<System..::..Double>[]()[][]
An array of size [nxg]
On entry: if the covariances are to be calculated, then xg must contain the nx data points. If covariances are supplied, xg may contain any values.
On exit: contains the ng spectral estimates, f^ωi, for i=0,1,,L/2 in xg[0] to xg[ng-1] respectively (logged if lg=1). The elements xg[i-1], for i=ng+1,,nxg contain 0.0.
ng
Type: System..::..Int32%
On exit: the number of spectral estimates, L/2+1, in xg.
stats
Type: array<System..::..Double>[]()[][]
An array of size [4]
On exit: four associated statistics. These are the degrees of freedom in stats[0], the lower and upper 95% confidence limit factors in stats[1] and stats[2] respectively (logged if lg=1), and the bandwidth in stats[3].
ifail
Type: System..::..Int32%
On exit: ifail=0 unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

Description

The smoothed sample spectrum is defined as
f^ω=12πC0+2k=1M-1wkCkcosωk,
where M is the window width, and is calculated for frequency values
ωi=2πiL,  i=0,1,,L/2,
where  denotes the integer part.
The autocovariances Ck may be supplied by you, or constructed from a time series x1,x2,,xn, as
Ck=1nt=1n-kxtxt+k,
the fast Fourier transform (FFT) being used to carry out the convolution in this formula.
The time series may be mean or trend corrected (by classical least squares), and tapered before calculation of the covariances, the tapering factors being those of the split cosine bell:
121-cosπt-12/T,1tT121-cosπn-t+12/T,n+1-Ttn1,otherwise,
where T=np2 and p is the tapering proportion.
The smoothing window is defined by
wk=WkM,  kM-1,
which for the various windows is defined over 0α<1 by
rectangular:
Wα=1
Bartlett:
Wα=1-α
Tukey:
Wα=121+cosπα
Parzen:
Wα=1-6α2+6α3,0α12Wα=21-α3,12<α<1.
The sampling distribution of f^ω is approximately that of a scaled χd2 variate, whose degrees of freedom d is provided by the method, together with multiplying limits mu, ml from which approximate 95% confidence intervals for the true spectrum fω may be constructed as ml×f^ω,mu×f^ω. Alternatively, log f^ω may be returned, with additive limits.
The bandwidth b of the corresponding smoothing window in the frequency domain is also provided. Spectrum estimates separated by (angular) frequencies much greater than 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

Error Indicators and Warnings

Errors or warnings detected by the method:
ifail=1
On entry,nx<1,
ormtx<0 and ic=0,
ormtx>2 and ic=0,
orpx<0.0,
orpx>1.0,
oriw<1,
oriw>4,
ormw<1,
ormw>nx,
ornc<mw,
ornc>nx,
ornxg<maxkc,l and ic=0,
ornxg<l and ic0.
ifail=2
On entry,kc<nx+nc,
orkc has a prime factor exceeding 19,
orkc has more than 20 prime factors, counting repetitions.
This error only occurs when ic=0.
ifail=3
On entry,l<2×mw-1,
orl has a prime factor exceeding 19,
orl has more than 20 prime factors, counting repetitions.
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.
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.
ifail=-9000
An error occured, see message report.
ifail=-8000
Negative dimension for array value
ifail=-6000
Invalid Parameters value

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.

Parallelism and Performance

None.

Further Comments

g13ca carries out two FFTs of length kc to calculate the covariances and one FFT of length l to calculate the sample spectrum. The time taken by the method for an FFT of length n is approximately proportional to nlogn (but see [Further Comments] in c06pa for further details).

Example

This example reads a time series of length 256. It selects the mean correction option, a tapering proportion of 0.1, the Parzen smoothing window and a cut-off point for the window at lag 100. It chooses to have 100 auto-covariances calculated and unlogged spectral estimates at a frequency division of 2π/200. It then calls g13ca to calculate the univariate spectrum and statistics and prints the autocovariances and the spectrum together with its 95% confidence multiplying limits.

Example program (C#): g13cae.cs

Example program data: g13cae.d

Example program results: g13cae.r

See Also