Learn R Programming

psd (version 0.4-1)

psdcore: Multitaper power spectral density estimates of a series.

Description

Compute power spectral density (PSD) estimates for the input series using sine multitapers.

Usage

psdcore(X.d, X.frq = NULL, ntaper = as.tapers(1), ndecimate = 1L,
  preproc = TRUE, na.action = stats::na.fail, first.last = TRUE,
  plotpsd = FALSE, as.spec = TRUE, refresh = FALSE, verbose = FALSE,
  ...)

## S3 method for class 'default': psdcore(X.d, X.frq = NULL, ntaper = as.tapers(1), ndecimate = 1L, preproc = TRUE, na.action = stats::na.fail, first.last = TRUE, plotpsd = FALSE, as.spec = TRUE, refresh = FALSE, verbose = FALSE, ...)

Arguments

X.d
the series to estimate a spectrum for
X.frq
scalar; the sampling information (see section Sampling)
ntaper
scalar, or vector; the number of tapers
ndecimate
scalar; decimation factor
preproc
logical; should X.d have a linear trend removed?
na.action
the function to deal with NA values
first.last
the extrapolates to give the zeroth and Nyquist frequency estimates
plotpsd
logical; should the estimate be shown compared to the spec.pgram estimate
as.spec
logical; should the object returned be of class 'spec'?
refresh
logical; ensure a free environment prior to execution
verbose
logical; should messages be given?
...
(unused) Optional parameters

Value

  • An list object, invisibly. If as.spec=TRUE then an object with class spec; otherwise the list object will have information similar to a spec object, but with a few additional fields.

Warning

Decimation is not well tested as of this point.

The first.last parameter is a workaround for potential bug (under investigation), which causes the power at the zero and Nyquist frequencies to have anomalously low values. This argument enables using linear extrapolation to correct these values. The feature will be deprecated if the supposed bug is both identified and fixed.

Details

Tapering{ The parameter ntaper specifies the number of sine tapers to be used at each frequency: equal tapers at each frequency for a scalar; otherwise, use ntaper[j] sine tapers at frequency[j]. }

Truncation{ The series, with length $N$, is necessarily truncated so that $1+N/2$ evenly spaced frequencies are returned. This truncation makes the series length ``highly composite", which the discrete Fourier transform (DFT) is most efficient. The vignette "fftw" (accessed with vignette("fftw",package="psd")) shows how the performance of a DFT can be affected by series length. }

Decimation{ The parameter ndecimate determines the number of PSD estimates actually computed. This number is defined as a fraction of the truncated length, $(1+N/2)/n_d$. Linear interpolation is used. }

Sampling{ If X.frq is NULL, the value is assumed to be 1, unless X.d is a 'ts' object. If X.frq > 0 it's assumed the value represents frequency (e.g. Hz). If X.frq < 0 it's assumed the value represents interval (e.g. seconds). }

See Also

pspectrum, riedsid

Examples

Run this code
#RDEX#\dontrun{
require(psd)
##
## Multitaper PSD estimation
##
set.seed(1234)
X <- rnorm(1e3)
#
# use the defaults, and appeal to plot.spec
plot(psdcore(X))
#
# use more tapers, compare to stats::spectrum, and clear 
# env data from the previous calculation
psdcore(X, ntapers=10, plotpsd=TRUE, refresh=TRUE)
#
# change the sampling frequency to 20
psdcore(X, 20, 10, plotpsd=TRUE, refresh=TRUE) 
#RDEX#}

Run the code above in your browser using DataLab