pspectrum: Adaptive sine multitaper power spectral density estimation

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/func_pspectrum.R

Description

This is the primary function to be used in this package: it returns power spectral density estimates of a univariate timeseries, with an optimal number of tapers at each frequency based on iterative reweighted spectral derivatives.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
pspectrum(x, ...)

## S3 method for class 'ts'
pspectrum(x, ...)

## S3 method for class 'spec'
pspectrum(x, ...)

## Default S3 method:
pspectrum(x, x.frqsamp = 1, ntap.init = NULL, niter = 5,
  AR = FALSE, Nyquist.normalize = TRUE, verbose = TRUE,
  no.history = FALSE, plot = FALSE, ...)

pspectrum_basic(x, ntap.init = 7, niter = 5, verbose = TRUE, ...)

adapt_message(stage, dvar = NULL)

Arguments

x

vector; series to find PSD estimates for

...

Optional parameters passed to riedsid

x.frqsamp

scalar; the sampling rate (e.g. Hz) of the series x; equivalent to frequency.

ntap.init

scalar; the number of sine tapers to use in the pilot spectrum estimation; if NULL then the default in pilot_spec is used.

niter

scalar; the number of adaptive iterations to execute after the pilot spectrum is estimated.

AR

logical; should the effects of an AR model be removed from the pilot spectrum?

Nyquist.normalize

logical; should the units be returned on Hz, rather than Nyquist?

verbose

logical; Should messages be given?

no.history

logical; Should the adaptive history not be saved?

plot

logical; Should the results be plotted?

stage

integer; the current adaptive stage (0 is pilot)

dvar

numeric; the spectral variance; see also vardiff etc

Details

See the Adaptive estimation section in the description of the psd-package for details regarding adaptive estimation.

pspectrum_basic is a simplified implementation used mainly for testing.

Value

Object with class 'spec', invisibly. It also assigns the object to "final_psd" in the working environment.

Author(s)

A.J. Barbour adapted original by R.L. Parker

See Also

psdcore, pilot_spec, riedsid, prewhiten

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## Not run: #REX
library(psd)
library(RColorBrewer)

##
## Adaptive multitaper PSD estimation
## (see also the  "psd_overview"  vignette)
##

data(magnet)
Xr <- magnet$raw
Xc <- magnet$clean

# adaptive psd estimation (turn off diagnostic plot)
PSDr <- pspectrum(Xr, plot=FALSE)
PSDc <- pspectrum(Xc, plot=FALSE)

# plot them on the same scale
plot(PSDc, log="dB",
     main="Raw and cleaned Project MAGNET power spectral density estimates",
     lwd=3, ci.col=NA, ylim=c(0,32), yaxs="i")
plot(PSDr, log="dB", add=TRUE, lwd=3, lty=5)
text(c(0.25,0.34), c(11,24), c("Clean","Raw"), cex=1)

## Change sampling, and inspect the diagnostic plot
plot(pspectrum(Xc, niter=1, x.frqsamp=10, plot=TRUE))

## Say we forgot to assign the results: we can recover from the environment with:
PSDc_recovered <- psd_envGet("final_psd")
plot(PSDc_recovered)


## End(Not run)#REX

williamdeleo/psd documentation built on May 29, 2019, 11:58 a.m.