BLT low-pass version (DC gain = 1, Nyquist gain = 0):JCJR wrote: ↑Wed Oct 02, 2019 7:23 pm You could do the same with the simple lowpass filter, but you would need to figure out how to find the filter cutoff frequency that would give you that required amount of cut at whatever high frequency target frequency you pick. And find the dampCoeff value which would tune your filter to that value.
Code: Select all
// one pole damper - BLT version
struct Damper
{
double b, a, z;
// assume normalized fc = f / fs
void setup(double fc, double g)
{
// BLT one-pole lowpass is
// b * (1 + z^-1) / (1 - a*z^-1)
//
// magnitude response comes out as:
// sqrt(sin(w)^2+(cos(w)+1)^2)
// b * ---------------------------------
// sqrt(a^2*sin(w)^2+(a*cos(w)+1)^2)
//
// normalizing for DC gain = 1 gives:
// b = abs(a+1)/2
//
// then setting a specific gain g at w we get:
// ((a+1)*sqrt(2*cos(w)+2))
// -------------------------- = g
// (2*sqrt(2*a*cos(w)+a^2+1))
//
// Wolfram alpha gives:
//
// a = (1 + cos(w) -2 * g^2 * cos(w)
// +/- 2 * sqrt(g^2 * sin^2(w) - g^4 * sin^2(w)))
// / (2 g^2 - cos(w) - 1)
//
// obviously only one of these is stable
double w = 2*M_PI*fc;
double cw = cos(w);
double sw = sin(w);
double g2 = g*g;
a = (1 + cw - 2*g2*cw - 2*sqrt(g2 * (1 - g2) * sw*sw)) / (2 * g2 - cw - 1);
b = (a + 1) / 2;
}
void reset()
{
z = 0;
}
double process(double x)
{
// TDF2 BLT
double y = b*x + z;
z = b*x - a*y;
return y;
}
};