estspec

Filename: estspec.py

Authors: Thomas Sargent, John Stachurski

Functions for working with periodograms of scalar data.

quantecon.estspec.ar_periodogram(x, window='hanning', window_len=7)[source]

Compute periodogram from data x, using prewhitening, smoothing and recoloring. The data is fitted to an AR(1) model for prewhitening, and the residuals are used to compute a first-pass periodogram with smoothing. The fitted coefficients are then used for recoloring.

Parameters:

x : array_like(float)

A flat NumPy array containing the data to smooth

window_len : scalar(int), optional

An odd integer giving the length of the window. Defaults to 7.

window : string

A string giving the window type. Possible values are ‘flat’, ‘hanning’, ‘hamming’, ‘bartlett’ or ‘blackman’

Returns:

w : array_like(float)

Fourier frequences at which periodogram is evaluated

I_w : array_like(float)

Values of periodogram at the Fourier frequences

quantecon.estspec.periodogram(x, window=None, window_len=7)[source]

Computes the periodogram

\[I(w) = (1 / n) | sum_{t=0}^{n-1} x_t e^{itw} |^2\]

at the Fourier frequences w_j := 2 pi j / n, j = 0, ..., n - 1, using the fast Fourier transform. Only the frequences w_j in [0, pi] and corresponding values I(w_j) are returned. If a window type is given then smoothing is performed.

Parameters:

x : array_like(float)

A flat NumPy array containing the data to smooth

window_len : scalar(int), optional(default=7)

An odd integer giving the length of the window. Defaults to 7.

window : string

A string giving the window type. Possible values are ‘flat’, ‘hanning’, ‘hamming’, ‘bartlett’ or ‘blackman’

Returns:

w : array_like(float)

Fourier frequences at which periodogram is evaluated

I_w : array_like(float)

Values of periodogram at the Fourier frequences

quantecon.estspec.smooth(x, window_len=7, window='hanning')[source]

Smooth the data in x using convolution with a window of requested size and type.

Parameters:

x : array_like(float)

A flat NumPy array containing the data to smooth

window_len : scalar(int), optional

An odd integer giving the length of the window. Defaults to 7.

window : string

A string giving the window type. Possible values are ‘flat’, ‘hanning’, ‘hamming’, ‘bartlett’ or ‘blackman’

Returns:

array_like(float)

The smoothed values

Notes

Application of the smoothing window at the top and bottom of x is done by reflecting x around these points to extend it sufficiently in each direction.