How to implement a filtered derivative

The formula you quote corresponds a first-order IIR filter. Is there a reason why you want to use this particular filter, vs. a finite difference filter (= FIR filter, as in your other recent thread) in conjunction with smoothing (low-pass filtering) to reduce noise, or a higher-order IIR filter, or …?

In general, filter design is very context dependent. How noisy is your data? Over what bandwidth do you need to be accurate? How will it be implemented, and how efficient does it need to be?

If you have 50000 points that you need to approximately differentiate in Julia, that is a very small-scale problem where efficiency doesn’t sound like a primary concern (as opposed to something that needs to operate continuously in an embedded system). So if I were you, I would implement something straightforward that you can understand completely, e.g. smoothing followed by a finite-difference approximation, instead of trying to copy formulas whose properties you don’t really understand.

But if you want to learn more, I would pick up a textbook on discrete-time signal processing and start by understanding IIR and FIR filters. They are extremely simple to implement once you understand them (and the DSP.jl package, for example, can do this for you) — the hard part is designing the filter weights for a particular application.

3 Likes