Skip to content

Instantly share code, notes, and snippets.

@geraldstanje
Created August 8, 2016 21:10
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 geraldstanje/a0ad53b7cb7828f1999ee9693df3a75e to your computer and use it in GitHub Desktop.
Save geraldstanje/a0ad53b7cb7828f1999ee9693df3a75e to your computer and use it in GitHub Desktop.
library(wavelets)
load_data <- function(filename, row) {
data = read.csv(filename, header=FALSE, sep=",")
return(data[[row]])
}
wavelet_transform <- function(data) {
Wavelet_out = matrix(0, 1, 8)
Wave_results = dwt(data, "filter" = "haar")
Wavelet_out[1, 1] = slot(Wave_results, "V")[[1]][1]
Wavelet_out[1, 2] = slot(Wave_results, "V")[[2]][1]
Wavelet_out[1, 3] = slot(Wave_results, "V")[[3]][1]
Wavelet_out[1, 4] = slot(Wave_results, "V")[[4]][1]
Wavelet_out[1, 5] = slot(Wave_results, "V")[[5]][1]
Wavelet_out[1, 6] = slot(Wave_results, "V")[[6]][1]
Wavelet_out[1, 7] = slot(Wave_results, "V")[[7]][1]
Wavelet_out[1, 8] = slot(Wave_results, "V")[[8]][1]
return(Wavelet_out)
}
setwd("/Users/geri/Work/wavelet_test/src")
raw_data = load_data("../data/wavelet_test.csv", 2)
res = wavelet_transform(raw_data)
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment