# Deseasonalizing data with fourier analysis

I have a data which has two underlying behavior. First there is a periodicity in it. It looks like a sine curve. Secondly the data points have constant growth in it. So, if I have 100 data points without any growth it will look like a sine curve. But due to growth rate in it. there is an increase in magnitude going from point 1 to point 100.

I am not sure what is the right term to search for in google. Is there a method for this kind of data analysis?

• Similar to stats.stackexchange.com/a/213455/17230? Harmonic regression, or regression with Fourier terms, I think. The idea can be used in various types of time series model. – Scortchi Jun 8 '16 at 0:15
• can you post plot? more context? – Matthew Gunn Jun 8 '16 at 4:52

The term you're looking for is "trend and seasonality decomposition of time series". Google this.

There are many approaches. If you really have only 100 points then Fourier will not work very well. Yule-Walker based approaches may work better. There are also filter based approaches. For instance, Google band pass filters such as bpassm from Atlanta Fed. The idea's that you filter out different frequency components from the series, so that low frequency would be trend, medium frequency the signal, and the high frequency - seasonality etc.

There's a full set of code in this matlab example. It takes you step by step through the process of deseasoning, it works quite well for economic data in my experience

• Love this example. This is what I was looking for kind of. – user1243255 Jun 8 '16 at 16:33

Classic auto-regressive models can handle cycles! Going way back, Yule (1927) and Walker (1931) modeled the periodicity of sunspots using an equation of the form:

$$y_{t+1} = a + b_1 y_t + b_2 y_{t-1} + \epsilon_{t+1}$$

Sunspot activity tends to operate on 11 year cycles, and though it's not immediately obvious, the inclusion of two auto-regressive terms can create cyclic behavior! Auto-regressive models are now ubiquitous in modern time-series analysis. The U.S. Census Bureau uses an ARIMA model to calculate seasonal adjustment.

More generally, you can fit an ARIMA model which involves:

• $p$ order auto-regressive terms (as above)
• $q$ order moving-average terms
• $d$ differences (to get the data stationary)

If you dive into the math, there's a relation between ARIMA models and representations in the frequency domain with a Fourier transform. You can represent a stationary time-series process using an auto-regressive model, moving average model, or the spectral density.

## Practical way forward:

1. You first need to obtain a stationary time series. For example with gross domestic product or aggregate consumption, people typically take the logarithm and compute the first difference. (Basic idea is that distribution over percent changes in aggregate consumption is invariant across time.) To obtain a stationary time series $\Delta c_t$ from aggregate consumption $C_t$.

$$\Delta c_t = \log C_t - \log C_{t-1}$$

1. Once you have a stationary time series, it's easy to fit an auto-regressive AR(n) model. You can simply do least squares. For an AR(2) model you can run the regression.

$$y_{t} = a + b_1 y_{t-!} + b_2 y_{t-2} + \epsilon_t$$

Of course you can get more fancy, but often simple stuff can work surprisingly well. There are well developed packages for time series analysis in R, EViews, Stata, etc...

If your data is a time series, you may want to look into triple exponential smoothing, also known as Holt-Winters' method. This can accommodate additive seasonality (where the seasonal amplitude does not grow with the upwards trend over time) and multiplicative seasonality. Here is the difference:

This section in Hyndman's & Athanasopoulos' free online forecasting textbook explains Holt-Winters. Here is the entire taxonomy of exponential smoothing methods, based on Gardner (2006, International Journal of Forecasting). To actually model such a series, extract trend, seasonal and error components and forecast, I recommend the ets() function in the forecast package for R.