Main Archive Specials Wiki | FAQ Links Submit Forum


Simple biquad filter from apple.com

Type : LP
References : Posted by neolit123 at gmail dot com

Notes :
Simple Biquad LP filter from the AU tutorial at apple.com

Code :
//cutoff_slider range 20-20000hz
//res_slider range -25/25db
//srate - sample rate

//init
mX1 = 0;
mX2 = 0;
mY1 = 0;
mY2 = 0;
pi = 22/7;

//coefficients
cutoff = cutoff_slider;
res = res_slider;

cutoff = 2 * cutoff_slider / srate;
res = pow(10, 0.05 * -res_slider);
k = 0.5 * res * sin(pi * cutoff);
c1 = 0.5 * (1 - k) / (1 + k);
c2 = (0.5 + c1) * cos(pi * cutoff);
c3 = (0.5 + c1 - c2) * 0.25;

mA0 = 2 * c3;
mA1 = 2 * 2 * c3;
mA2 = 2 * c3;
mB1 = 2 * -c2;
mB2 = 2 * c1;

//loop
output = mA0*input + mA1*mX1 + mA2*mX2 - mB1*mY1 - mB2*mY2;

mX2 = mX1;
mX1 = input;
mY2 = mY1;
mY1 = output;



Comments


Added on : 05/03/09 by neolit123[ AT ]gmail[ DOT ]com
Comment :
here are coefficients for the hp version.
the br,bp & peak are also easy to calculate:

k = 0.5*res*sin(pi*cutoff);
c1 = 0.5*(1-k)/(1+k);
c2 = (0.5+c1)*cos(pi*cutoff);
c3 = (0.5+c1+c2)*0.25;

a0 = 2*c3;
a1 = -4*c3;
a2 = 2*c3;
b1 = -2*c2;
b2 = 2*c1;

if you wish to create a cascade, use the this:

//----sample loop

//mem: buffer array
//N: number of biquads, n=4 -> 48dB/oct

//set input here

for (i=0;i<N;i++) {
output = a0 * input + a1 * mem[4*i+1] + a2 * mem[4*i+2] - b1 * mem[4*i+3] - b2 * mem[4*i+4];
mem[4*i+2] = mem[4*i+1];
mem[4*i+1] = input;
mem[4*i+4] = mem[4*i+3];
mem[4*i+3] = output;
);

//----sample loop




Added on : 20/04/09 by neolit123[ AT ]gmail[ DOT ]com
Comment :
i've missed a line:

===========================
mem[4*i+3] = output;

//>>> insert here
input = output;
//>>> insert here

);
//----sample loop
===========================

lubomir




Added on : 25/01/11 by giku[ DOT ]itoa[ AT ]gmail[ DOT ]com
Comment :
How to make bandpass from this?              



Add your own comment
Comments are displayed in fixed width, no HTML code allowed!
Email:

Comment:

Are you human?



Site created and maintained by Bram
Graphic design by line.out | Server sponsered by fxpansion