# Finding cycles in data using a periodogram and Fast Fourier Transform

Problem: Detecting cyclical patterns in daily data using periodogram and FFT.

The issue is how to code in R the periodogram to detect monthly, quarterly, semi-annual, annual..etc cyclical patterns in the data. In other words I need to detect the existence of cyclical patterns for low frequencies (i.e., 1 year => 2*pi/365, 6 months => 4*pi/365, etc.).

Reproducible Example:

library(weatherData)
w2009 = getWeatherForYear("sfo", 2009)
w2010 = getWeatherForYear("sfo", 2010)
w2011 = getWeatherForYear("sfo", 2011)
w2012 = getWeatherForYear("sfo", 2012)
w2013 = getWeatherForYear("sfo", 2013)
w2014 = getWeatherForYear("sfo", 2014)
w = rbind(w2009, w2010); w=rbind(w, w2011); w=rbind(w, w2012)
w = rbind(w, w2013); w=rbind(w, w2014)

# Next we analyze the periodograms
# This is IMAGE 1
TSA::periodogram(w$Max_TemperatureF) # Next: I dont really know to use this information GeneCycle::periodogram(w$Max_TemperatureF)
# Next THIS IS IMAGE 2
stats::spectrum(w\$Max_TemperatureF)


How do you interpret these images?

• The part of your question concerning 'how do you interpret these images' is on-topic here, but the part asking 'how do you code...' is off-topic. Be aware that you may not get answers to that part. Mar 3, 2015 at 1:08
• Of course, but I will be glad to at least have a partial answer than no answer ! Thank you Mar 3, 2015 at 2:15

The periodogram is an inconsistent estimator of the spectrum of a stationary time series, hence the very erratic behaviour you see in your second plot. In order to gain a further insight in your series, you should either smooth the periodogram (look at argument spans= and taper= of spec.pgram()) or resort to a parametric estimate of the spectrum (look at spectrum(...,method="ar") and choose the autoregressive order using AIC for instance).