# [PD] can [bp~] be obtained with biquad coefficients?

Alexandre Torres Porres porres at gmail.com
Fri Apr 11 05:23:51 CEST 2014

```well, here's an attempt to make bp out of [fexpr~]

and... it did not work

2014-04-10 22:07 GMT-03:00 Alexandre Torres Porres <porres at gmail.com>:

> hey, the code I sent only calculates the coeficients, but I left out an
> important part which is
>
> t_sample output = *in++ + coef1 * last + coef2 * prev;
>
>         *out++ = gain * output;
>
>         prev = last;
>
>         last = output;
>
>
> This shows how the filter is done with those coefficients
>
>
> It's easy to implement this with [fexpr~], it goes something like:
>
>
> [fexpr~ \$x + (coef1 * \$x1[-1]) + (coef2 * \$x1[-2])]
>
>
> It's seems this formula can also be achieved done with biquad, which
> receives a list where the first two elements are the same coefficients.
>
>
> But it still doesn't seem it is as simple as that. Maybe there's also
> something regarding the gain of the filter or something.
>
>
> Hope the wizards can help me solve this
>
>
> Cheers
>
>
>
>
>
>
> 2014-04-09 14:20 GMT-03:00 Alexandre Torres Porres <porres at gmail.com>:
>
> "I'd start with a look at the [bp~] source to see if you can extract some
>> hints about how the filter is implemented."
>>
>> Anyway, this is what I got from the code. But I wasn't successful to
>> extract biquad coefficients from it. I still assume it can be done. It says
>> it's a 2-pole bandpass filter, so I understand you can get to it with
>> biquad, cause biquad is 2-pole and 2-zero. It's just a matter to get rid of
>> the zeros somehow. I was able to leave them with a vlue of 0, but didn't
>> seem to do the job.
>>
>>
>> thanks
>>
>>
>> static t_float sigbp_qcos(t_float f)
>>
>> {
>>
>>     if (f >= -(0.5f*3.14159f) && f <= 0.5f*3.14159f)
>>
>>     {
>>
>>         t_float g = f*f;
>>
>>         return (((g*g*g * (-1.0f/720.0f) + g*g*(1.0f/24.0f)) - g*0.5) + 1
>> );
>>
>>     }
>>
>>     else return (0);
>>
>> }
>>
>>
>> static void sigbp_docoef(t_sigbp *x, t_floatarg f, t_floatarg q)
>>
>> {
>>
>>     t_float r, oneminusr, omega;
>>
>>     if (f < 0.001) f = 10;
>>
>>     if (q < 0) q = 0;
>>
>>     x->x_freq = f;
>>
>>     x->x_q = q;
>>
>>     omega = f * (2.0f * 3.14159f) / x->x_sr;
>>
>>     if (q < 0.001) oneminusr = 1.0f;
>>
>>     else oneminusr = omega/q;
>>
>>     if (oneminusr > 1.0f) oneminusr = 1.0f;
>>
>>     r = 1.0f - oneminusr;
>>
>>     x->x_ctl->c_coef1 = 2.0f * sigbp_qcos(omega) * r;
>>
>>     x->x_ctl->c_coef2 = - r * r;
>>
>>     x->x_ctl->c_gain = 2 * oneminusr * (oneminusr + r * omega);
>>
>>     /* post("r %f, omega %f, coef1 %f, coef2 %f",
>>
>>         r, omega, x->x_ctl->c_coef1, x->x_ctl->c_coef2); */
>>
>> }
>>
>>
>> 2014-04-08 22:21 GMT-03:00 Alexandre Torres Porres <porres at gmail.com>:
>>
>> "I'd start with a look at the [bp~] source to see if you can extract
>>> some hints about how the filter is implemented."
>>>
>>> Done that, way out of my head. What I can deal with is wether I can get
>>> to it with biquad coefficients.
>>>
>>> thanks
>>>
>>>
>>>
>>> 2014-04-08 21:28 GMT-03:00 Bill Gribble <grib at billgribble.com>:
>>>
>>>   The quick and dirty way is just to feed the filter white noise and
>>>> plot the output signal's spectrum.   Guaranteed to show the actual
>>>> performance of the filter, and not somebody's idea of how it ought to be
>>>> working.
>>>>
>>>> If you need a theoretical curve, I'd start with a look at the [bp~]
>>>> source to see if you can extract some hints about how the filter is
>>>> implemented.  It may be quite easy to figure out the poles and zeros if the
>>>> code is clear and/or documented.
>>>>
>>>> Good luck!
>>>> Bill Gribble
>>>>
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20140411/cdb9af64/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bp.pd
Type: application/octet-stream
Size: 1892 bytes
Desc: not available
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20140411/cdb9af64/attachment-0001.obj>
```