Finding all our coefficients:
\[b0 = \frac{1-\cos(\omega)}{2}\] \[b1 = 1-\cos(\omega)\] \[b2 = \frac{1-\cos(\omega)}{2}\] \[a0 = 1 + \alpha\] \[a1 = -2 * \cos(\omega)\] \[a2 = 1-\alpha\]This can be represented in code the following way:
biquadLowpassCoefficients(fc: number, Q: number) {
const omega = (2 * Math.PI * fc) / 44100;
const alpha = Math.sin(omega) / (2 * Q);
const b0 = (1 - Math.cos(omega)) / 2;
const b1 = 1 - Math.cos(omega);
const b2 = (1 - Math.cos(omega)) / 2;
const a0 = 1 + alpha;
const a1 = -2 * Math.cos(omega);
const a2 = 1 - alpha;
}
After the co-efficients are done, you are good to go, since we are using the Elementary Audio library we can use their biquad function. I am probably too stupid at the moment to explain it properly and this is a good way to get started.
This can be done easily with the following code snippet
return el.biquad (
coeffs.b0,
coeffs.b1,
coeffs.b2,
coeffs.a1,
coeffs.a2,
inputSignal,
);
And voila, you now have a low-pass filter implemented in JavaScript.
If you want to learn more about how to implement this library easily on the client-side (your website) you can go to Elementary Audio. For more information on how to change the co-efficients to change the type of filter to something like a high-pass filter, you can go have a look here Cookbook formulea for audio equalizer biquad coefficients
If you want to get more info, don’t hesitate to hit me up on Twitter/Threads, and I’ll try to help as best I can.