X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=epclust%2Fsrc%2Ffilter.c;h=8ece9c3f439dc7eaf2e23f3962e816fec42e829a;hb=282342bafdc9ff65c5df98c6e2304d63b33b9fb2;hp=382910a89f0dc024bed4a3c8da520ac5d7582c2e;hpb=e161499b97c782aadfc287c22b55f85724f86fae;p=epclust.git diff --git a/epclust/src/filter.c b/epclust/src/filter.c index 382910a..8ece9c3 100644 --- a/epclust/src/filter.c +++ b/epclust/src/filter.c @@ -1,37 +1,70 @@ -#include #include -#include -#include +#include -#include - -SEXP filter(SEXP cwt_) +// filterMA +// +// Filter [time-]series by replacing all values by the moving average of values +// centered around current one. Border values are averaged with available data. +// +// @param M_ A real matrix of size LxD +// @param w_ The (odd) number of values to average +// +// @return The filtered matrix, of same size as the input +SEXP filterMA(SEXP M_, SEXP w_) { - int L = INTEGER(getAttrib(cwt_, R_DimSymbol))[0], - D = INTEGER(getAttrib(cwt_, R_DimSymbol))[1]; - double *cwt = REAL(cwt_); - SEXP R_fcwt; - PROTECT(R_fcwt = allocMatrix(REALSXP, L, D)); - double* fcwt = REAL(R_fcwt); - - //TODO: coding style is terrible... no time for now. - for (int col=0; col=0; col--) { - double v1 = cwt[0]; - double ma = v1 + cwt[1] + cwt[2]; - for (int i=1; i=0; i--) + cs += M[i]; + + // Left border + for (i=0; i