Learn R Programming

⚠️There's a newer version (2.1.2) of this package.Take me there.

#psd

Adaptive, sine multitaper power spectral density estimation for R

by Andrew J Barbour and Robert L Parker

###Description### This is an R package for computing univariate power spectral density estimates with little or no tuning effort. We employ sine multitapers, allowing the number to vary with frequency in order to reduce mean square error, the sum of squared bias and variance, at each point. The approximate criterion of Riedel and Sidorenko (1995) is modified to prevent runaway averaging that otherwise occurs when the curvature of the spectrum goes to zero. An iterative procedure refines the number of tapers employed at each frequency. The resultant power spectra possess significantly lower variances than those of traditional, non-adaptive estimators. The sine tapers also provide useful spectral leakage suppression. Resolution and uncertainty can be estimated from the number of degrees of freedom (twice the number of tapers).

This technique is particularly suited to long time series, because it demands only one numerical Fourier transform, and requires no costly additional computation of taper functions, like the Slepian functions. It also avoids the degradation of the low-frequency performance associated with record segmentation in Welch's method. Above all, the adaptive process relieves the user of the need to set a tuning parameter, such as time-bandwidth product or segment length, that fixes frequency resolution for the entire frequency interval; instead it provides frequency-dependent spectral resolution tailored to the shape of the spectrum itself.

psd elegantly handles spectra with large dynamic range and mixed-bandwidth features|features typically found in geophysical datasets.

##How to Cite##

Bob and I have published a paper in Computers & Geosciences to accompany this software (download a pdf, 1MB); it describes the theory behind the estimation process, and how we apply it in practice. If you find psd useful in your research, we kindly request you cite our paper.

citation("psd")

##Getting Started##

Firstly you'll need to install the package and it's dependencies from CRAN (from within the R environment):

install.packages("psd", dependencies=TRUE)

then load the package library

library(psd)

We have included a dataset to play with, named Tohoku, which represents recordings of high-frequency borehole strainmeter data during teleseismic waves from the 2011 Mw 9.0 Tohoku earthquake (source). Access and inspect these data with:

data(Tohoku)
print(str(Tohoku))

The 'preseismic' data has interesting spectral features, so we subset it, and use the areal strain (the change in borehole diameter):

Dat <- subset(Tohoku, epoch=="preseismic")
Areal <- ts(Dat$areal)

For the purposes of spectral estimation, we remove a linear trend:

Dat <- prewhiten(Areal, plot=FALSE)

Now we can calculate the adaptive PSD:

mtpsd <- pspectrum(Dat$prew_lm, plot=TRUE)
print(class(mtpsd))

We can visualize the spectrum with builtin methods:

plot(mtpsd, log="dB")

and the spectral uncertainty:

sprop <- spectral_properties(mtpsd)
Ntap <- sprop$taper/max(sprop$taper)
plot(Ntap, type="h", ylim=c(0,2), col="dark grey") 
lines(sprop$stderr.chi.lower)
lines(sprop$stderr.chi.upper)

##Installing the Development Version##

Should you wish to install the development version of this software, the devtools library will be useful:

install.packages("devtools", dependencies=TRUE)
library(devtools)
install_github("abarbour/psd")

Copy Link

Version

Install

install.packages('psd')

Monthly Downloads

828

Version

1.0-1

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Andrew Barbour

Last Published

March 22nd, 2015

Functions in psd (1.0-1)

Tohoku

Observations of teleseismic strains from the 2011 Tohoku earthquake.
psd-utilities

Various utility functions.
psd-normalization

Normalization of power spectral density estimates.
prewhiten

Prepare a series for spectral estimation
hfsnm

Noise levels found in PBO strainmeter data at seismic frequencies.
ctap_simple_rcpp

Taper constraints using simple derivatives
spec_confint

Confidence intervals for multitaper power spectral density estimates
spectral_properties

Calculate properties of multitaper power spectral density estimates
psd-environment

Various environment manipulation functions.
modulo_floor

Nearest value below
magnet

A single line of Project MAGNET horizontal field intensity
psd-package

Adaptive power spectral density estimation using optimal sine multitapers
rcpp_ctap_simple

c++ implementation of constrain filter
pilot_spec

Calculate inital power spectral density estimates
pgram_compare

Compare multitaper spectrum with cosine-tapered periodogram
pspectrum

Adaptive sine multitaper power spectral density estimation
as.tapers

Coerce an object into a 'tapers' object.
resample_fft_rcpp

Resample an fft using varying numbers of sine tapers
riedsid

Constrained, optimal tapers using the Riedel & Sidorenko--Parker method
parabolic_weights_rcpp

Calculate parabolic weighting factors.
spec-methods

Generic methods for objects with class 'spec'
psdcore

Multitaper power spectral density estimates of a series
splineGrad

Numerical derivatives of a series based on its smooth-spline representation
tapers-constraints

Taper constraint methods
ctap_loess

Taper constraints using loess smoothing
tapers-methods

Generic methods for objects with class 'tapers'