For instance, when using 4 data points, the SavitzkyGolay filter for estimating the derivative is, y(k) = .3 x(k) + .1 x(k1)  .1 x(k2)  .3 x(k3)
where x(k) is the newest (current) input x(k  1) is the previous input x(k2) is the next oldest input x(k3) is the oldest input used for the 4point filter y(k) is the newest (current) filtered (output) value, estimating the rate of change of input per time step.
The units for the calculations are the rate of change of the input variable per time step. To convert to the time derivative, divide the output by the time step size. In the above example, if the fixed sample time is 2 minutes, the time derivative estimate is half of y(k).
The special case of a 2point filter is just included for completeness. The least squares fit of a straight line for two points goes through both those points, so the least squares estimate is simply the difference between the values (per time step).
The sum of all the coefficients is always 0.0 (within rounding error in the tables above), which makes sense because the response to a steady input (or step response) must be zero.
For filter sizes that are an odd number, the data input at the center of the time window is completely ignored in each time step. For the most effective noise reduction for the amount of computation, you might as well use filters with an even number of data point inputs If you want to use a time period that requires more than 13 data points, consider sampling more slowly at the input to this filter, taking care to avoid aliasing by first filtering with an exponential filter at the higher sample rate.
One problem with least squares filtering is that you get overshoot in the current derivative estimate following an input (step) change, just like you get for the current value estimate. (This is not an issue for smoothing at the midpoint of the data time window.) Another problem is that, unless you use a SavitzkyGolay filter, it is computationally intensive compared to most filters. Despite these problems, this is a common approach to estimating derivatives.
The “MACD approach” to estimating rate of change
There is another approach to estimating rate of change, described on the next page in this series.
Copyright 2010  2020, Greg Stanley
Return to Filtering Next: The “MACD approach” to estimating rate of change
Return to A Guide to Fault Detection and Diagnosis
