This is not a cutting edge filter, but this might be useful for analog inputs with relatively infrequent variations. This is perhaps a old discarded idea, but I would like to have your opinion.
low pass filter with dynamic cut frequency adjustment:
- the variable gain g0 varies between gmin and gmax depending on the rate of variation of the signal
- The idea is to adapt the cut frequency of the filter according to the slope of the input.
- the variable gain g0 is itself filtered by a low-pass filter.
double gmin=0.3; // low cut frequency gain double gmax=0.7; // high cut frequency gain double epsilon = 0.05; double delta;
// Low pass single pole filter: double low_pass (double n0, double n1, double g) { double filt = n1 * (1.0 - g) + g * n0; return filt; }
double filt_adapt(double n0, double n1, double n2) // n0 : current signal, n1 : filtered signal at t-1, n2 filtered signal at t-2 // g0 : current gain, g1 : filtered gain at t-1 { double filt = low_pass(n0, n1, g0);
if (fabs(n1-n2) < epsilon) delta = 1.0; else delta = fabs(n0-n1)/fabs (n1-n2);
if (delta > 1.0) g0 = min(gmax,g0 + delta*0.3); else g0 = max(gmin,g0 - delta*0.3);
g0 = low_pass(g0,g1,0.3); g1=g0; return filt;
}