Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

ar_psd

Power spectrum of AR model


Description

Compute the power spectral density of an autoregressive model.

Usage

ar_psd(
  a,
  v = 1,
  freq = 256,
  fs = 1,
  range = ifelse(is.numeric(a), "half", "whole"),
  method = ifelse(length(freq) == 1 && bitwAnd(freq, freq - 1) == 0, "fft", "poly")
)

## S3 method for class 'ar_psd'
plot(
  x,
  yscale = c("linear", "log", "dB"),
  xlab = NULL,
  ylab = NULL,
  main = NULL,
  ...
)

Arguments

a

numeric vector of autoregressive model coefficients. The first element is the zero-lag coefficient, which always has a value of 1.

v

square of the moving average coefficient, specified as a positive scalar Default: 1

freq

vector of frequencies at which power spectral density is calculated, or a scalar indicating the number of uniformly distributed frequency values at which spectral density is calculated. Default: 256.

fs

sampling frequency (Hz). Default: 1

range

character string. one of:

"half" or "onesided"

frequency range of the spectrum is from zero up to but not including fs / 2. Power from negative frequencies is added to the positive side of the spectrum.

"whole" or "twosided"

frequency range of the spectrum is -fs / 2 to fs / 2, with negative frequencies stored in "wrap around order" after the positive frequencies; e.g. frequencies for a 10-point "twosided" spectrum are 0 0.1 0.2 0.3 0.4 0.5 -0.4 -0.3 -0.2. -0.1.

"shift" or "centerdc"

same as "whole" but with the first half of the spectrum swapped with second half to put the zero-frequency value in the middle. If freq is a vector, "shift" is ignored.

Default: If model coefficients a are real, the default range is "half", otherwise the default range is "whole".

method

method used to calculate the power spectral density, either "fft" (use the Fast Fourier Transform) or "poly" (calculate the power spectrum as a polynomial). This argument is ignored if the freq argument is a vector. The default is "poly" unless the freq argument is an integer power of 2.

x

object to plot.

yscale

character string specifying scaling of Y-axis; one of "linear", "log", "dB"

xlab, ylab, main

labels passed to plotting function. Default: NULL

...

additional arguments passed to functions

Details

This function calculates the power spectrum of the autoregressive model

M
x(n) = sqrt(v).e(n) + SUM a(k).x(n-k)
                      k=1

where x(n) is the output of the model and e(n) is white noise.

Value

An object of class "ar_psd" , which is a list containing two elements, freq and psd containing the frequency values and the estimates of power-spectral density, respectively.

Author(s)

Peter V. Lanspeary, pvl@mecheng.adelaide.edu.au.
Conversion to R by Geert van Boxtel, gjmvanboxtel@gmail.com

Examples

a <- c(1, -2.7607, 3.8106, -2.6535, 0.9238)
psd <- ar_psd(a)

gsignal

Signal Processing

v0.3-1
GPL-3
Authors
Geert van Boxtel [aut, cre] (Maintainer), Tom Short [aut] (Author of 'signal' package), Paul Kienzle [aut] (Majority of the original sources), Ben Abbott [ctb], Juan Aguado [ctb], Muthiah Annamalai [ctb], Leonardo Araujo [ctb], William Asquith [ctb], David Bateman [ctb], David Billinghurst [ctb], Juan Pablo Carbajal [ctb], André Carezia [ctb], Vincent Cautaerts [ctb], Eric Chassande-Mottin [ctb], Luca Citi [ctb], Dave Cogdell [ctb], Carlo de Falco [ctb], Carne Draug [ctb], Pascal Dupuis [ctb], John W. Eaton [ctb], R.G.H Eschauzier [ctb], Andrew Fitting [ctb], Alan J. Greenberger [ctb], Mike Gross [ctb], Daniel Gunyan [ctb], Kai Habel [ctb], Kurt Hornik [ctb], Jake Janovetz [ctb], Alexander Klein [ctb], Peter V. Lanspeary [ctb], Bill Lash [ctb], Friedrich Leissh [ctb], Laurent S. Mazet [ctb], Mike Miller [ctb], Petr Mikulik [ctb], Paolo Neis [ctb], Georgios Ouzounis [ctb], Sylvain Pelissier [ctb], Francesco Potortì [ctb], Charles Praplan [ctb], Lukas F. Reichlin [ctb], Tony Richardson [ctb], Asbjorn Sabo [ctb], Thomas Sailer [ctb], Rolf Schirmacher [ctb], Rolf Schirmacher [ctb], Ivan Selesnick [ctb], Julius O. Smith III [ctb], Peter L. Soendergaard [ctb], Quentin Spencer [ctb], Doug Stewart [ctb], P. Sudeepam [ctb], Stefan van der Walt [ctb], Andreas Weber [ctb], P. Sudeepam [ctb], Andreas Weingessel [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.