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

Syntax

C#
public static void g13cb(
	int nx,
	int mtx,
	double px,
	int mw,
	double pw,
	int l,
	int kc,
	int lg,
	double[] xg,
	out int ng,
	double[] stats,
	out int ifail
)
Visual Basic
Public Shared Sub g13cb ( _
	nx As Integer, _
	mtx As Integer, _
	px As Double, _
	mw As Integer, _
	pw As Double, _
	l As Integer, _
	kc 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 g13cb(
	int nx, 
	int mtx, 
	double px, 
	int mw, 
	double pw, 
	int l, 
	int kc, 
	int lg, 
	array<double>^ xg, 
	[OutAttribute] int% ng, 
	array<double>^ stats, 
	[OutAttribute] int% ifail
)
F#
static member g13cb : 
        nx : int * 
        mtx : int * 
        px : float * 
        mw : int * 
        pw : float * 
        l : int * 
        kc : 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: 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: 0mtx2.
px
Type: System..::..Double
On entry: the proportion of the data (totalled over both ends) to be initially tapered by the split cosine bell taper. (A value of 0.0 implies no tapering.)
Constraint: 0.0px1.0.
mw
Type: System..::..Int32
On entry: the value of M which determines the frequency width of the smoothing window as 2π/M. A value of n implies no smoothing is to be carried out.
Constraint: 1mwnx.
pw
Type: System..::..Double
On entry: p, the shape parameter of the trapezium frequency window.
A value of 0.0 gives a triangular window, and a value of 1.0 a rectangular window.
If mw=nx (i.e., no smoothing is carried out), pw is not used.
Constraint: 0.0pw1.0.
l
Type: System..::..Int32
On entry: L, the frequency division of smoothed spectral estimates as 2π/L.
Constraints:
  • l1;
  • l must be a factor of kc.
kc
Type: System..::..Int32
On entry: 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 where m is the smallest integer such that 2m2n, provided m20.
Constraints:
  • kc2×nx;
  • kc must be a multiple of l. 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.
lg
Type: System..::..Int32
On entry: indicates whether unlogged or logged spectral estimates and confidence limits are required.
lg=0
For unlogged.
lg0
For logged.
xg
Type: array<System..::..Double>[]()[][]
An array of size [kc]
On entry: the n data points.
On exit: contains the ng spectral estimates f^ωi, for i=0,1,,L/2, in xg[0] to xg[ng-1] (logged if lg0). The elements xg[i-1], for i=ng+1,,kc, 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 lg0), 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 supplied time series may be mean or trend corrected (by least squares), and tapered, 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 unsmoothed sample spectrum
f*ω=12πt=1nxtexpiωt2
is then calculated for frequency values
ω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 is a multiple of a chosen value r, i.e.,
ωrl=νl=2πlL,  l=0,1,,L/2,
where K=r×L. You will normally fix L first, then choose r so that K is sufficiently large to provide an adequate representation for the unsmoothed spectrum, i.e., K2×n. It is possible to take L=K, i.e., r=1.
The smoothing is defined by a trapezium window whose shape is supplied by the function
Wα=1,αpWα=1-α1-p,p<α1
the proportion p being supplied by you.
The width of the window is fixed as 2π/M by you supplying M. A set of averaging weights are constructed:
Wk=g×WωkMπ,  0ωkπM,
where g is a normalizing constant, and the smoothed spectrum obtained is
f^νl=ωk<πMWkf*νl+ωk.
If no smoothing is required M should be set to n, in which case the values returned are f^νl=f*νl. Otherwise, in order that the smoothing approximates well to an integration, it is essential that KM, and preferable, but not essential, that K be a multiple of M. A choice of L>M would normally be required to supply an adequate description of the smoothed spectrum. Typical choices of Ln and K4n should be adequate for usual smoothing situations when M<n/5.
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

Note: g13cb may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the method:
ifail=1
On entry,nx<1,
ormtx<0,
ormtx>2,
orpx<0.0,
orpx>1.0,
ormw<1,
ormw>nx,
orpw<0.0 and mwnx,
orpw>1.0 and mwnx,
orl<1.
ifail=2
On entry,kc<2×nx,
orkc is not a multiple of l,
orkc has a prime factor exceeding 19,
orkc has more than 20 prime factors, counting repetitions.
ifail=3
This indicates that a serious error has occurred. Check all array subscripts and method parameter lists in calls to g13cb. Seek expert help.
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

g13cb carries out a FFT of length kc to calculate the sample spectrum. The time taken by the method for this is approximately proportional to kc×logkc (but see [Further Comments] in c06pa for further details).

Example

This example reads a time series of length 131. It then calls g13cb to calculate the univariate spectrum and prints the logged spectrum together with 95% confidence limits.

Example program (C#): g13cbe.cs

Example program data: g13cbe.d

Example program results: g13cbe.r

See Also