Complex Demodulation with Least Squares Lowpass Filter

DESCRIPTION:

Estimates the instantaneous amplitude and phase of a given harmonic component in order to analyze nonstationary time series. This function can also be used to construct lowpass filters.

USAGE:

demod(x, centerfreq, passfreq, stopfreq, wrapphase=F) 

REQUIRED ARGUMENTS:

x
a univariate or multivariate time series, or a vector, or a matrix with one univariate series per column. Missing values are allowed only at the ends.
centerfreq
the frequency at which to demodulate the series.
passfreq
the pass frequency of the lowpass filter. passfreq must be less than stopfreq.
stopfreq
the stop frequency of the lowpass filter.

OPTIONAL ARGUMENTS:

wrapphase
logical flag: if TRUE, then phase is wrapped into the interval [- pi, pi]. When FALSE, phase is made continuous by not allowing jumps greater than 2 times pi.

VALUE:

a list with the following components:
amp
a time series like x containing the amplitude at frequency centerfreq.
phase
a time series like x containing the phase in radians at frequency centerfreq.
filter
vector of the lowpass filter coefficients.
centerfreq
the same as the input centerfreq.
stopfreq
the same as the input stopfreq.
passfreq
the same as the input passfreq.
series
the name of the input time series as a character string.

DETAILS:

Missing values at the ends of the series are excluded from the computations.

The phase and amplitude of the demodulation are smoothed with a least squares approximation to a lowpass filter. The cutoff of the filter is half-way between passfreq and stopfreq. The number of terms in the filter is floor(2*max(2,d)+1), where

d=frequency(x)/(stopfreq-passfreq).

BACKGROUND:

Complex demodulation is a technique for analyzing nonstationary time series by estimating the instantaneous amplitude and phase of a given harmonic component. See Bloomfield (1976) for an account of the method. To better understand the results of complex demodulation several lowpass filters should be tried: the smaller the pass band, the less instantaneous in time but more specific in frequency is the result.

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:

.

EXAMPLES:

p <- spectrum(sunspots, span=c(7,5), plot=F) 
fpeak <- p$freq[p$spec==max(p$spec)]  # the frequency of the spectral peak 
d <- demod(sunspots, fpeak, .02, .04) 
par(mar=c(5,4,4,4)+.1) 
tsplot(d$amp, lty=1, ylab="amplitude") 
legend(1750, 40, c("amplitude", "phase"), lty=1:2) 
par(new=T) 
tsplot(d$phase, lty=2, main="Sunspot Demodulation", axes=F) 
axis (4) 
mtext(side=4, line=3, "phase") 
  # a sloped phase plot indicates that the frequency used  
  # is slightly off the mark