I implemented the last examples with Chebyshev response.
Firstly, it uses a second-order IIR filter, easy to implement with gen~
secondOrderIIR (x, a0, a1, a2, b1, b2)
{
History x1, x2, y1, y2;
y = a0 * x + a1 * x1 + a2 * x2 - b1 * y1 - b2 * y2;
y2 = y1;
y1 = y;
x2 = x1;
x1 = x;
return (y);
}
Then it's possible to produce a wide range of filter types.
All we need is to give it the right coefficients to these feedback loops.
It's possible to cascade these filters to produce higher order.
The bandpass coefficients work great. The example is for 1dB ripple
chebychevBandPass (center, bandwidth)
{
ripple = 1.965267;
bandfreq = PI * bandwidth / samplerate;
// tan is slower
var = cos (bandfreq) / sin (bandfreq);
// to avoid calculate this sum more than one time
var2 = ripple + var;
scale = 2 * cos (TWOPI * center / samplerate);
a0 = ripple / (var2);
a1 = 0;
a2 = -a0;
b1 = -var * scale / var2;
b2 = (var - ripple) / var2;
return a0, a1, a2, b1, b2;
}
Then I tried the bandstop coefficients generator with no success, all it outputs is -10000...
chebychevBandStop (center, bandwidth)
{
ripple = 1.965267;
bandfreq = PI * bandwidth / samplerate;
// tan is slower
var = cos (bandfreq) / sin (bandfreq);
// to avoid calculate this sum more than one time
var2 = ripple + var;
scale = 2 * cos (TWOPI * center / samplerate);
a0 = ripple / (var2);
a1 = -ripple * scale / var2;
a2 = a0;
b1 = -var * scale / var2;
b2 = (ripple - var) / var2;
return a0, a1, a2, b1, b2;
}
So, if anyone has the right coefficients for Band-stop, lowpass and highpass, I'd be grateful.
Here is a patch to listen to a fourth-order chebyshev band-pass filter.