Resonant filter

References : Posted by Paul Kellett
Notes :
This filter consists of two first order low-pass filters in
series, with some of the difference between the two filter
outputs fed back to give a resonant peak.

You can use more filter stages for a steeper cutoff but the
stability criteria get more complicated if the extra stages
are within the feedback loop.
Code :
//set feedback amount given f and q between 0 and 1
fb = q + q/(1.0 - f);

//for each sample...
buf0 = buf0 + f * (in - buf0 + fb * (buf0 - buf1));
buf1 = buf1 + f * (buf0 - buf1);
out = buf1;

Comments
from : mr[DOT]just starting
comment : very nice! how could i turn that into a HPF?

from : dsp[AT]dsparsons[DOT]nospam[DOT]co[DOT]uk
comment : The cheats way is to use HPF = sample - out; If you do a plot, you'll find that it isn't as good as designing an HPF from scratch, but it's good enuff for most ears. This would also mean that you have a quick method for splitting a signal and operating on the (in)discreet parts separately. :) DSP

from : scoofy[AT]inf[DOT]elte[DOT]hu
comment : This filter calculates bandpass and highpass outputs too during calculation, namely bandpass is buf0 - buf1 and highpass is in - buf0. So, we can rewrite the algorithm: // f and fb calculation f = 2.0*sin(pi*freq/samplerate); /* you can approximate this with f = 2.0*pi*freq/samplerate with tuning error towards nyquist */ fb = q + q/(1.0 - f); // loop hp = in - buf0; bp = buf0 - buf1; buf0 = buf0 + f * (hp + fb * bp); buf1 = buf1 + f * (buf0 - buf1); out = buf1; // lowpass out = bp; // bandpass out = hp; // highpass The slope of the highpass out is not constant, it varies between 6 and 12 dB/Octave with different f and q settings. I'd be interested if anyone derived a proper highpass output from this algorithm. -- peter schoffhauzer