arntanguy / gram_savitzky_golay

C++ Implementation of Savitzky-Golay filtering based on Gram polynomials
BSD 2-Clause "Simplified" License
100 stars 29 forks source link

Timestep for derivatives #2

Closed stephane-caron closed 6 years ago

stephane-caron commented 6 years ago

The current config only allows one to specify the order of the derivative. However, for time series there is also a time step between data points.

Example for a first-order derivative: with the current API, one should post-divide by the time step:

d = 1;
SavitzkyGolayFilter first_derivative_filter(m, t, n, d);
std::vector<double> values = {.1, .2, .3, .4, .5, .6, .7};
double timestep = 0.005; // [s]
double time_derivative = first_derivative_filter.filter(values) / timestep;

It would be nice to be able to specify the timestep, e.g. in SavitzkyGolayFilterConfig, and read the time derivatives as filter outputs directly.

arntanguy commented 6 years ago

Thanks @BenjaminNavarro !

I merged this, and added a very basic unit test for it. I'm leaving the issue open for now, as the timeStep should be handled differently for higher order derivatives, ie when s > 1

BenjaminNavarro commented 6 years ago

ah yes you're right. It sould be divided by dt^s right? If it's just that, I'll make the fix.

arntanguy commented 6 years ago

Implemented in f1f4ef4304fcc41fa18538f04e112d3c5e10d7ab, thanks for the feedback ;)