Signal extraction in time series, as simple as that?

Frequency-domain filters provide a straightforward way to decompose a time series. In this post I briefly introduce this approach advocated by Prof. D. Stephen G. Pollock in this document that introduces the software IDEOLOG.

As pointed out by Prof. Pollock, the advantage of frequency domain filter is that they are able to achieve clear separations of components of the data that reside in adjacent frequency bands in a way that the conventional time-domain methods cannot. By conventional time-domain methods the author refers to filters like the Baxter and King and Christiano and Fitzgerald that are often applied to extract the business cycle from macroeconomic data.

Following the notation of the above-mentioned document, frequency-domain filters are based on the Fourier coefficients:

\displaystyle{ \zeta_j = \frac{1}{T} \sum_{t=0}^{T-1} y_t e^{-i\omega_j t}\,dt \,, \quad j=0,... ,T-1 \,. }

Each coefficient \zeta_j is related to a cycle of frequency \omega_j. Thus, a natural way to filter desired frequencies is to set equal to zero those coefficients that are related to frequencies that do not belong to the target component (e.g. seasonal) and then synthesise the target component, s_t, by means of the inverse transform:

\displaystyle{s_t = \sum_{j=0}^{T-1} \zeta_t e^{i\omega_j t}\,dt \,, \quad t=1,... ,T \,.}

Let's see some examples. (The UK consumption data employed in the first example is available here.)

First, we load the data and remove a linear trend to which the Fourier filter will be applied to extract a cycle.

n <- length(UKconsumption)
fit <- lm(log(UKconsumption) ~ seq_along(UKconsumption))
y <- ts(residuals(fit))
tsp(y) <- tsp(UKconsumption)

Following Pollock we choose a cut-off frequency \pi/8 radians to extract a cycle, which involves a low-pass filter that passed the cycles in the low range frequencies 2\pi\,j/(T-1), j = 0,\dots,10 (whose periodicity ranges from infinity to 15.9 quarters).

It is convenient to define the \zeta_j coefficients as \displaystyle{\zeta_j = \frac{\alpha_j - i\beta_j}{2}}, with:
\displaystyle{\alpha_j = \frac{2}{T} \sum_{t=1}^T y_t \cos \omega_j t \,,\qquad\qquad\qquad\qquad\qquad\qquad  \beta_j = \frac{2}{T} \sum_{t=1}^T y_t \sin \omega_j t \,.}

Then, the Fourier coefficients can be obtained in R as follows (a direct translation of the summation terms above into explicit loops to obtain \alpha_j and \beta_j would work as well, but the vectorized approach followed below is slightly faster):

cutOffInt <- 10
seqnm1 <- 2 * pi *, n-1) / n
tmp <- outer(seqnm1, seq_len(cutOffInt), function(a, j) a * j)
alpha <- c(mean(y, na.rm = TRUE), colSums(c(y) * cos(tmp) * 2/n))
beta <- c(0, colSums(c(y) * sin(tmp) * 2/n))

Upon the first 10 Fourier coefficients, it is straightforward to synthesize the corresponding trend-cycle component:

seqCutOffInt <- 2 * pi * seq_len(cutOffInt) / n
seqnm1 <-, n-1)
tmp <- outer(seqCutOffInt,, n-1), function(a, j) a * j)
x <- colSums(alpha[-1] * cos(tmp) + beta[-1] * sin(tmp))
x <- ts(x + alpha[1])
tsp(x) <- tsp(y)


Similarly, a seasonal component can be obtained by obtaining the Fourier coefficients for the seasonal and nearby cycles.


A potential downside of frequency-domain filters is that macroeconomic data may exhibit some peculiarities (e.g., damping trends, periodic integration, time-varying parameters) that may be better captured by a time series model. Nevertheless, I find this approach appealing and helpful for the following reasons:

  • It is simple. The bottom-line idea is enclosed in neat and well-known expressions (i.e. Fourier coefficients). Besides it is relatively simple to implement, just a few of lines of code were required in the example above (actual computations could be condensed in about 4 lines of code).
  • It's intuitive. The filter can be defined in terms of cycles of known periodicity. We can choose the relevant cycles by looking to the spectrum, which show the frequency of those cycles that explain the variability of the data. This could be automated following for example this idea in order to easily get the frequency of the cycles for which a peak is observed in the spectrum. This is especially appealing when obtaining a cycle signal, for which we do not beforehand the proper periodicity of the underlying cycle. In the time-domain there isn't a straightforward translation from the autocorrelation functions to the filters than extracts the relevant components. This is also an advantage over non-parametric methods such as the smoothing of a time series by LOESS, where the options of the procedure must be chosen by eyeball, but I must say I don't have much experience with this method.
  • In theory, a clear separation across components can be achieved, with no leakages from cycles that do not belong to the specified component or band-pass filter. This seems to be an advantage over time-domain filters, where a large number of coefficients are required to avoid leakage from cycles close to the stop bands of the filter.

D.S.G. Pollock. IDEOLOG: A Program for Filtering Econometric Data. A Synopsis of Alternative Methods. URL: ideolog.pdf

This entry was posted in R, time series and tagged , , , . Bookmark the permalink.

Leave a Reply
