[music-dsp] BiQuad Magnitude Frequency Response problem

Kevin Dixon kevin.c.dixon at gmail.com
Tue Oct 19 17:03:33 EDT 2010


Chalk it up to late night confusion -- I was putting the fabs on the
result because the data looked wrong, but compounding the problem, the
GUI code was assuming magnitude for input, and transforming it to dB
scale.

So the data returned from my method was flipped, and then GUI
transformed it again. I've change the interface specification to note
the filter magnitude is output in dB :)

Thanks all, it works now!

-Kevin

On Tue, Oct 19, 2010 at 7:28 AM, robert bristow-johnson
<rbj at audioimagination.com> wrote:
>
> On Oct 19, 2010, at 2:54 AM, Kevin Dixon wrote:
>
>> Hi all,
>>
>> I was following this thread to calculate the magnitude frequency
>> response of a BiQuad filter (as discussed in RBJ's cookbook):
>>
>> http://groups.google.com/group/comp.dsp/browse_frm/thread/8c0fa8d396aeb444/a1bc5b63ac56b686
>> in message 9, RBJ shows his revised equation, which I've implemented
>> as such, where "atFreq" is the input parameter of frequency to
>> calculate for.
>>
>>        Float64 w = 2.0 * pi * atFreq / lastSampleRate;
>>        Float64 phi = 4.0 * pow(sin(w / 2.0), 2.0);
>>
>>        Float64 c1 =  10.0 * log10(pow(b0+b1+b2, 2.0) + ( b0*b2*phi -
>> (b1*(b0+b2) + 4.0 * b0 * b2) )*phi) ;
>>
>>        Float64 c2 =  10.0 * log10(pow(a0+a1+a2, 2.0) + ( a0*a2*phi -
>> (a1*(a0+a2) + 4.0 * a0 * a2) )*phi);
>>
>>        return  fabs(c1 - c2);
>
>
> this looks okay to me except for the fabs().  that should neither be
> necessary nor desired.  but the worst that it should do is flip part of your
> response upside down.
>
>
>>
>> c1 is the first bit of the equation, and c2 is the second. I'm trying
>> to write a GUI to display the curve, so the GUI calculates the
>> frequencies it wants based on the real estate it has to render in... I
>> must have a bug, because my curves are coming out looking backwards.
>> When I calculate for a low-pass at 500Hz, 0.7Q, I wind up with data
>> points that look like a high-pass at 500Hz, but with some sort of
>> boost. I know that my filter is implemented correctly, because if I
>> run fuzzmeasure through my filter, the frequency response is proper.
>
>
> you haven't told us what your coefficients are.
>
>
> now, if you define your LPF coefficients as so:
>
>         w0 = 2*pi*f0/Fs
>
>         alpha = sin(w0)/(2*Q)
>
> LPF:     H(s) = 1 / (s^2 + s/Q + 1)
>         b0 = (1 - cos(w0))/2
>         b1 = 1 - cos(w0)
>         b2 = (1 - cos(w0))/2
>         a0 = 1 + alpha
>         a1 = -2*cos(w0)
>         a2 = 1 - alpha
>
>
> and then evaluate your dB gain as:
>
>   20*log10[ |H(e^jw)| ]  =  10 * (
>
>   log10[(b0+b1+b2)^2 + ( b0*b2*phi - (b1*(b0+b2) + 4*b0*b2) )*phi]
>
>  - log10[(a0+a1+a2)^2 + ( a0*a2*phi - (a1*(a0+a2) + 4*a0*a2) )*phi] )
>
>
>
>          where   phi = 4*sin^2(w/2)
>
>                  w  =  2*pi*f/Fs        0 < f < Fs
>
>
>
> then you still have problems?
>
> i guess i would like to see the coefs you have.
>
> --
>
> r b-j                  rbj at audioimagination.com
>
> "Imagination is more important than knowledge."
>
>
>
>
> --
> dupswapdrop -- the music-dsp mailing list and website:
> subscription info, FAQ, source code archive, list archive, book reviews, dsp
> links
> http://music.columbia.edu/cmc/music-dsp
> http://music.columbia.edu/mailman/listinfo/music-dsp
>


More information about the music-dsp mailing list