Estimate Spectrum with Smoothed Periodogram

DESCRIPTION:
Estimates the spectrum of a time series by smoothing the periodogram, and optionally plots the spectral estimate.

USAGE:
spec.pgram(x, spans=1, taper=0.1, pad=0, detrend=T, demean=F, plot=F)

REQUIRED ARGUMENTS:
x:
a univariate or multivariate time series, or a vector, or a matrix with a univariate series per column. Missing values are allowed only at the ends.

OPTIONAL ARGUMENTS:
spans:
a sequence of lengths of modified Daniell smoothers to run over the raw periodogram. Use spans = 1, the default, for the raw periodogram. A modified Daniell smoother has all values equal except for the 2 end values which are half the size of the others. The values should be odd integers.
taper:
fraction of each end of the time series that is to be tapered. A split cosine taper is applied to {taper * length(x)} points at each end of series. This must take values between 0 and 0.5.
pad:
fraction of the length of x that is to be padded: {pad * length(x)} zeros are added to the end of the series before computing the periodogram.
detrend:
if TRUE, remove a least squares line from each component of the series before computing periodogram.
demean:
if TRUE, remove the mean of each series before computing the periodogram (detrend also removes the mean).
plot:
if TRUE, a plot of the spectrum will be provided. See spec.plot for details.

VALUE:
a list with the following components:
freq:
the sequence of frequencies at which the spectrum is estimated. These correspond to the discrete Fourier frequencies between 0 and pi. Because of aliasing the jth Fourier frequency corresponds to a freq value of j/length(x) times deltat <- 1/tsp(x)[3]. Hence, Fourier frequencies between 0 and pi correspond to freq values between 0 and 0.5 * deltat.
spec:
a vector for univariate series or a matrix with each column corresponding to a column of x. The estimated spectrum is in decibels (10*log10(power)), where power refers to the estimated power spectrum at the corresponding frequency value in freq.
coh:
a matrix containing the estimated squared coherency between each pair of columns of the series. If j is less than k, then the pair (j,k) corresponds to column (k-1)(k-2)/2 + j. For univariate series this component is NULL.
phase:
a matrix like coh containing the estimated phase spectra between each pair of columns of the series. The phase spectra are made somewhat continuous by allowing no jumps of greater than pi in each. To put them back into the range [0, 2 pi) use the modulus operator %%: e.g. reducedphase <- phase%%(2*pi). For univariate series this component is NULL.
spans:
the actual spans of the Daniell windows used - even integers are increased by one.
filter:
the coefficients of the convolution of modified Daniell windows of length spans[i] used to smooth the periodogram.
df:
the number of degrees of freedom for a chi square approximation.
bandwidth:
the bandwidth of the estimate.
n.used:
the length of the nonmissing part of x.
series:
the name used for the input series as a character string.
method:
the string "Raw Periodogram" if spans=1 or "Smoothed Periodogram" otherwise.
taper:
the same as the input taper.
pad:
the same as the input pad.
detrend:
the same as the input detrend.
demean:
the same as the input demean.

SIDE EFFECTS:
if plot=TRUE, then a plot is created on the current graphics device.

DETAILS:
Only the (central) part of the time series that is free of missing values is used in the computations.

The spectrum is estimated by taking the discrete Fourier transform of the (detrended then tapered then padded) data. The squared modulus of this transform is then smoothed by a sequence of running averages. See Bloomfield (1976) for a discussion of the methods.


REFERENCES:
Bloomfield, P. (1976). Fourier Analysis of Time Series: An Introduction. Wiley, New York.

The chapter "Analyzing Time Series" of the S-PLUS Guide to Statistical and Mathematical Analysis.


SEE ALSO:
fft , spec.ar , spec.plot , spec.smo , spec.taper , spectrum .

EXAMPLES:
p <- spec.pgram(log(lynx), pad=1)  # Compute and plot Raw Periodogram.
p2 <- spec.pgram(log(lynx), pad=1, spans=c(9,7), plot=F)
spec.plot(p2,add=T)                # Superimpose a Smooth Periodogram.