X-Git-Url: https://git.auder.net/?p=epclust.git;a=blobdiff_plain;f=epclust%2Fsrc%2Ffilter.cpp;h=5268a5fefbb187070c3072ce16bff9aeddc385fb;hp=ee24af604ab2c5cd35a4c754635b7716ca9d477f;hb=d9bb53c5e1392018bf67f92140edb10137f3423c;hpb=363ae13430cdee6ba76b42b7316aa4b292b04d93 diff --git a/epclust/src/filter.cpp b/epclust/src/filter.cpp index ee24af6..5268a5f 100644 --- a/epclust/src/filter.cpp +++ b/epclust/src/filter.cpp @@ -4,37 +4,47 @@ using namespace Rcpp; //' filter //' -//' Filter time-series +//' Filter [time-]series by replacing all values by the moving average of previous, current and +//' next value. Possible extensions: larger window, gaussian kernel... (but would be costly!). +//' Note: border values are unchanged. //' -//' @param cwt Continuous wavelets transform +//' @param cwt Continuous wavelets transform (in columns): a matrix of size LxD //' -//' @return The filtered CWT +//' @return The filtered CWT, in a matrix of same size (LxD) // [[Rcpp::export]] -NumericMatrix epclustFilter(NumericMatrix cwt) +RcppExport SEXP epclustFilter(SEXP cwt_) { - int L = cwt.nrow(), - D = cwt.ncol(); - NumericMatrix fcwt(L, D); //fill with 0... TODO: back to SEXP C-style? - double *cwt_c = cwt.begin(), - *fcwt_c = fcwt.begin(); + // NOTE: C-style for better efficiency (this must be as fast as possible) + int L = INTEGER(Rf_getAttrib(cwt_, R_DimSymbol))[0], + D = INTEGER(Rf_getAttrib(cwt_, R_DimSymbol))[1]; + double *cwt = REAL(cwt_); - //TODO: coding style is terrible... no time for now. - for (int col=0; col=0; col++) { - double v1 = cwt_c[0]; - double ma = v1 + cwt[1] + cwt_c[2]; + double v1 = cwt[0]; //first value + double ms = v1 + cwt[1] + cwt[2]; //moving sum at second value for (int i=1; i