/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
//
/// @file Derivative.h
/// @brief A class to implement a derivative (slope) filter
/// See http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/smooth-low-noise-differentiators/
#pragma once
#include "FilterClass.h"
#include "FilterWithBuffer.h"
// 1st parameter is the type of data being filtered.
// 2nd parameter is the number of elements in the filter
template
class DerivativeFilter : public FilterWithBuffer
{
public:
// constructor
DerivativeFilter() : FilterWithBuffer() {
};
// update - Add a new raw value to the filter, but don't recalculate
void update(T sample, uint32_t timestamp);
// return the derivative value
float slope(void);
// reset - clear the filter
virtual void reset() override;
private:
bool _new_data;
float _last_slope;
// microsecond timestamps for samples. This is needed
// to cope with non-uniform time spacing of the data
uint32_t _timestamps[FILTER_SIZE];
};
typedef DerivativeFilter DerivativeFilterFloat_Size5;
typedef DerivativeFilter DerivativeFilterFloat_Size7;
typedef DerivativeFilter DerivativeFilterFloat_Size9;