Learn R Programming

sapa (version 2.0-3)

taper: Oracle function for obtaining a particular taper/window

Description

Develop signal processing tapers or windows.

Usage

taper(type="rectangle", n.sample=100, n.taper=NULL,
    sigma=0.3, beta=4*pi*(n.sample-1)/n.sample, cutoff=floor(n.sample/2),
    sidelobedB=80, roughness=n.sample/2, flatness=0.3,
    bandwidth=4, normalize=TRUE)

Arguments

bandwidth

bandwidth for DPSS tapers. See Details for more information. Default: 4.

beta

kaiser window shape factor (must be positive or zero). See Details for more information. Default: 4*pi*(n.sample-1)/n.sample.

cutoff

parzen or Papoulis window cutoff (must be greater than unity). See Details for more information. Default: floor(n.sample/2).

flatness

raised cosine taper flatness fraction (must be on [0,1]). See Details for more information. Default: 0.3.

n.sample

an integer denoting the number of samples. Default: 1000.

n.taper

an integer defining the multitaper order (number of orthogonal tapers) to use in a multitaper scheme. The taper order directly impacts the quality of the SDF estimate. Low taper orders are usually associated with SDF estimates with low bias and high variance, while high taper orders attenuate the variance of the estimate at the risk of incurring a large bias. This tradeoff between bias and variance is unavoidable but taper order allows you to tune the SDF to meet the needs of your application. Studies show that a multitaper order of 5 typically provides a good balance with reasonably low bias and variance properties (see the references for more details). Default: NULL, which serves as a flag to set the default taper order depending on the type of taper chosen for the analysis. If sine or dpss multitapers are chosen, the default taper order is 5, otherwise is set to unity.

normalize

a logical value. If TRUE, the taper is normalized to have unit energy. Default: TRUE.

roughness

daniell windown roughness factor (must be positive). See Details for more information. Default: n.sample/2.

sidelobedB

chebyshev sidelobedB bandwidth in decibels (must be positive). See Details for more information. Default: 80.

sigma

standard deviation for Guassian taper. Default: 0.3.

type

a character string denoting the type of taper to create. Supported types are "rectangle", "triangle", "raised cosine", "hanning", "hamming", "blackman", "nuttall", "gaussian", "kaiser", "chebyshev", "born jordan", "sine", "parzen", "papoulis", "daniell", and "dpss". See Details for more information. Default: "rectangle".

Value

an object of class taper.

S3 METHODS

as.matrix

converts output to a matrix.

plot

plots the output. Optional arguments are:

ylab

Character string denoting the y-axis label for the plot. Default: upperCase(attr(x,"type")).

type

Line type (same as the type argument of the par function). Default: "l".

...

Additional plot arguments (set internally by the par function).

print

prints a summary of the output object.

Details

Let \(w(\cdot)\) and \(h(t)\) for t = 0, ..., N-1 be a lag window and taper, respectively. The following lag window or taper types are supported.

rectangular

A rectangular taper is defined as \(h_t=1\).

triangle

A triangular taper is defined as \(h_t=h_{N-t-1}=2(t+1)/(N+1)\) for \(t < M\) where \(M = \lfloor N / 2 \rfloor\) and \(h_M=1\) if \(N\) is evenly divisible by 2.

raised cosine

A raised cosine is a symmetric taper with a flat mid-plateau. Let \(p \in [0,1]\) be the fraction of the length of the taper that is flat, \(M=\lfloor pN \rfloor\), and \(\beta=2\pi/(M+1)\). A raised cosine taper is defined as $$ h_t=h_{N-t-1}= 0.5 (1 - \cos(\beta(t+1))) \enskip\hbox{for}\enskip 0 \le t < \lfloor M/2 \rfloor $$ $$ h_t = 1 \enskip\hbox{for}\enskip \lfloor M/2 \rfloor \le t < N - \lfloor M/2 \rfloor. $$

hanning

Let \(\beta=2\pi/(N+1)\). A Hanning taper is defined as \(h_t=0.5 (1 - \cos(\beta(t+1)))\).

hamming

Let \(\beta=2\pi/(N-1)\). A Hamming taper is defined as \(h_t=0.54 - 0.46\cos(\beta t)\).

blackman

Let \(\beta=2\pi/(N+1)\). A Blackman taper is defined as \(h_t=0.42 - 0.5 \cos( \beta ( t + 1 ) ) + 0.08 \cos( 2 \beta ( t + 1 ) )\).

nuttall

Let \(\beta=2\pi/(N-1)\). A Nuttall taper is defined as \(h_t=0.3635819 - 0.4891775 \cos( \beta t ) + 0.1365995 \cos( 2\beta t ) - 0.0106411 \cos( 3\beta t )\)

gaussian

Let \(\sigma\) be the standard deviation of a Gaussian distribution. Let \(\beta(t)=2\sigma(0.5 - t/(N-1))\). A Gaussian taper is defined as $$h_t = h_{N-t-1} = e^{-B^2/2} \enskip\hbox{for}\enskip 0 \le t < \lfloor N/2 \rfloor$$. $$h_{N/2}=1\enskip\hbox{if N is evenly divisible by 2}$$.

kaiser

Let \(V_t = (2t-1-N)/N\) and \(I_0(\cdot)\) be the zeroth-order modified Bessel function of the first kind. Given the shape factor \(\beta > 0\), a Kaiser taper is defined as \(h_t = I_0(\beta \sqrt{1-V_t^2})/I_0(\beta)\).

chebyshev

The Dolph-Chebyshev taper is a function of both the desired length \(N\) and the desired sidelobe level (our routine accepts a sidelobe attenuation factor expressed in decibels). See the Mitra reference for more details.

born jordan

Let \(M=(N-1)/2\). A Born-Jordan taper is defined as \(h_t==h_{N-t-1} = 1 / ( M - t + 1 )\).

sine

Sine multitapers are defined as $$ h_{k,t} = \left({2\over{N+1}}\right)^{1/2} \sin\,\left( {{(k+1)\pi (t+1)} \over {N+1}}\right), $$ for t = 0, ..., N-1 and k = 0, ..., .. This simple equation defines a good approximation to the discrete prolate spheroidal sequences (DPSS) used in multitaper SDF estimation schemes.

parzen

A Parzen lag window is defined as $$ w_{\tau,m} = \left\{ \begin{array}{lll} {1 - 6(t/m)^2 + 6(|t|/m)^3},& \mbox{$|t| \le m/2$;}\\ {2(1 - |t|/m)^3},& \mbox{$m/2 < |t| \le m/2$;}\\ 0,& \mbox{otherwise}. \end{array} \right. $$ for \(-(N-1) \le \tau \le (N - 1)\). The variable \(m\) is referred to as the cutoff since all values beyond that point are zero.

papoulis

A Papoulis lag window is defined as $$ w_{\tau,m} = \left\{ \begin{array}{ll} {{1 \over \pi} |\sin(\pi\tau/m)| +(1-|\tau|/m)\cos(\pi\tau/m)},& \mbox{$|\tau| < m$;}\\ 0,& \mbox{$|\tau| \ge m$} \end{array} \right. $$ for \(-(N-1) \le \tau \le (N - 1)\). The variable \(m\) is referred to as the cutoff since all values beyond that point are zero.

daniell

A Daniell lag window is defined as $$ w_{\tau,m} = \left\{ \begin{array}{ll} {\sin(\pi\tau/m) \over \pi\tau/m},& \mbox{$|\tau| < N$;}\\ 0,& \mbox{$|\tau| \ge N$} \end{array} \right. $$ for \(-(N-1) \le \tau \le (N - 1)\). The variable \(m\) is referred to as the roughness factor, since, in the context of spectral density function (SDF) estimation, it controls the degree of averaging that is performed on the preliminary direct SDF estimate. The smaller the roughness, the greater the amount of smoothing.

dpss

Discrete prolate spheroidal sequences are (typically) used for multitaper spectral density function estimation. The first order DPSS can be defined (to a good approximation) as $$h_{t,0} = C \times I_0\bigl(\widetilde{W} \sqrt{1 - (1 - g_t)^2}\bigr) /I_0(\widetilde{W} ) $$ for \(t=1,\ldots,N\), where \(C\) is a scaling constant used to force the normalization \(\sum{h_{t,k}^2}=1\); \(\widetilde{W}=\pi W (N-1)\Delta t\) where \(\Delta t\) is the sampling interval; \(g_t=(2t - 1)/N\); and \(I_0(\cdot)\) is the modified Bessel function of the first kind and zeroth order. The parameter \(W\) is related to the resolution bandwidth since it roughly defines the desired half-width of the central lobe of the resulting spectral window. Higher order DPSS tapers (i.e., \(h_{t,k}\) for \(k > 0\)) can be calculated using a relatively simple tridiagonalization formulation (see the references for more information). Finally, we note that the sampling interval \(\Delta t\) can be set to unity without any loss of generality.

References

A. T. Walden, ``Accurate Approximation of a 0th Order Discrete Prolate Spheroidal Sequence for Filtering and Data Tapering", Signal Processing, 18, 341--8 (1989).

Percival, Donald B. and Constantine, William L. B. (2005) ``Exact Simulation of Gaussian Time Series from Nonparametric Spectral Estimates with Application to Bootstrapping", Journal of Computational and Graphical Statistics, accepted for publication.

D.B. Percival and A. Walden (1993), Spectral Analysis for Physical Applications: Multitaper and Conventional Univariate Techniques, Cambridge University Press, Cambridge, UK.

S.K.Mitra, J. Kaiser (1993), Handbook for Digital Signal Processing, John Wiley and Sons, Inc.

See Also

taper.

Examples

Run this code
# NOT RUN {
require(ifultools)
## change plot layout 
gap <- 0.11
old.plt <- splitplot(4,4,1,gap=gap)

## create a plot of all supported tapers and 
## windows 
nms <- c("rectangle", "triangle", "raised cosine",
    "hanning", "hamming", "blackman",
    "nuttall", "gaussian", "kaiser",
    "chebyshev", "born jordan", "sine",
    "parzen", "papoulis", "daniell", "dpss")

for (i in seq(along=nms)){
    if (i > 1) splitplot(4,4,i,gap=gap)
    plot(taper(type=nms[i]))
}

## restore plot layout to initial state 
par(old.plt)
# }

Run the code above in your browser using DataLab