Skip to content

Instantly share code, notes, and snippets.

@abecode
Created March 5, 2015 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abecode/ba31e14ff4d5915ff877 to your computer and use it in GitHub Desktop.
Save abecode/ba31e14ff4d5915ff877 to your computer and use it in GitHub Desktop.
# needs zoo for "rollapply"
library(zoo)
# needs e1071 for Hamming window
library('e1071')
# load data
th <- read.csv2('app_status_report_hourly.csv', header=F, sep=',', col.names=c('time','count'))
# normalize the data by the maximum
X <- th$count[1:length(th$count)]/max(th$count)
#
Xw <- rollapply(X,24,by=1,function(x){x*hamming.window(24)})
Fw <- apply(Xw,1,fft)
Fw_avg <- colMeans(t(abs(Fw)))
Fw_rem <- Fw - Fw_avg
Xw_rem <- apply(Xw,1,fft,inverse=T)
X_rem <- vector(mode=typeof(Xw_rem),length=length(X))
for(i in seq(1, dim(Xw_rem)[2])){
X_rem[i:(i+23)] <- X_rem[i:(i+23)] + Xw_rem[,i]
}
# plot(abs(X_rem),type='l') # the recovered with high frequency artifacts
plot(runmed(abs(X_rem), 25), type='l')
plot(runmed(abs(X), 25), type='l') #compare with simple median smoothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment