> ----- Original Message ----- > From: "Luigi Castelli" > To: music-dsp at music.columbia.edu > Subject: [music-dsp] Filter Q and bandwidth > Date: Thu, 29 Mar 2007 12:08:50 -0700 (PDT) > > > I have a question regarding the correct way to calculate filter Q (or > resonance) "the correct way" is in the eye of the beholder. but i have thunked about this quite a bit (trying to come up with a decent and consistent expressions for the "cookbook") and have opinions that i think i can defend. > I am calculating the coefficients for a straight Butterworth Bandpass > Filter. > The user parameters are of course CenterFrequency and Resonance. > > In the above example which of the following two methods is the correct > one to calculate bw? > > bw = wfreq * 0.5 / Resonance --- or --- bw = wfreq / Resonance ??? first of all, Q has meaning only for second order sections and whether it is LPF, HPF, BRF (notch), or BPF, this Q is defined by the denominator (or the poles). consider first, the analog case (s-plane). b0 + b1*s + b2*s^2 H(s) = -------------------- a0 + a1*s + a2*s^2 "a0" can be normalized to 1 without loss of generality. also, stick in s = j*w = j*2*pi*f to get frequency response. now the transfer function above can be expressed as: (b0/a0) + (b1/a0)*s + (b2/a0)*s^2 H(s) = ----------------------------------- 1 + (1/Q)*(s/w0) + (s/w0)^2 that's the definition of resonant frequency (w0) and Q. this follows right from doing the RLC series circuit analysis where Q = w0*L/R w0 = sqrt(a0/a2) Q = a0/(a1*w0) = sqrt(a0*a2)/a1 this is the "electrical engineering" definition of Q for any 2nd order analog filter. now, for a BPF with constant "skirt", the transfer is: s/w0 H(s) = ----------------------------- 1 + (1/Q)*(s/w0) + (s/w0)^2 in evaluating the frequency response, you would find that at resonance, when w = w0: (j*w0)/w0 H(j*w0) = ----------------------------------- = Q 1 + (1/Q)*(j*w0/w0) + (j*w0/w0)^2 at at the "skirt": left w << w0: j*w/w0 H(j*w) = --------------------------------- = approx j*w/w0 1 + (1/Q)*(j*w/w0) + (j*w/w0)^2 right w >> w0: j*w/w0 H(j*w) = --------------------------------- = approx -j*w0/w 1 + (1/Q)*(j*w/w0) + (j*w/w0)^2 so the gain at the skirts is not affected by Q, but the peak gain pokes up taller as Q gets higher. the bandwidth is the "difference" (there are two ways of defining that difference, in linear frequency or log frequency) is normally defined at the -3.01 dB points (relative to the peak gain). the -3.01 dB points are the "1/2 power points" where the magnitude square at the bandedge is 1/2 of the square of the gain at the peak. | j*w/w0 |^2 H(j*w) = --------------------------------------- = (Q^2)/2 | 1 + (1/Q)*(j*w/w0) + (j*w/w0)^2 |^2 1 H(j*w) = --------------------------------------- = (Q^2)/2 | -j*w0/w + (1/Q) + j*w/w0 |^2 Q^2 H(j*w) = ---------------------------- = (Q^2)/2 |1 + j*Q*(w/w0 - w0/w)|^2 Q^2 H(j*w) = ------------------------------ = (Q^2)/2 |1 + j*2*Q*sinh(ln(w/w0))|^2 or |1 + j*Q*sinh(ln(w/w0))|^2 = 1 + (2*Q*sinh(ln(w/w0)))^2 = 2 or sinh(ln(w/w0)) = +/- 1/(2*Q) or w = w0 * exp( +/- arcsinh(1/(2*Q)) those are the bandedges and the bandwidth in linear frequency is: BW = w0*( exp(+arcsinh(1/(2*Q)) - exp(-arcsinh(1/(2*Q)) ) = w0*2*sinh(arcsinh(1/(2*Q)) = w0/Q in log frequency the bandedges are at ln(w) = ln(w0) +/- arcsinh(1/(2*Q)) and the bandwidth is: bw = 2*arcsinh(1/(2*Q)) if you were to express bandwidth in octaves (base 2 log) it's, bw = (2/ln(2))*arcsinh(1/(2*Q)) so (finally), in linear frequency, in an analog filter, the bandwidth normalized by the resonant frequency is the Q: BW/w0 = Q the units don't matter as long as you're consistent. for musical purposes, i might expect that log frequency (measured in octaves) would be more interesting and, for an analog filter the relationship between the two is bw = (2/ln(2))*arcsinh(1/(2*Q)) one last big caveat: often when analog filters are converted to digital filters, the bilinear transform (BLT) is used which causes frequency warping from the frequency in the hypothetical analog prototype to the actual digital filter. that causes relocation of the resonant filter which is fixed by compensating ("pre-warping") but it also relocates the bandedges which effectively compresses the bandwidth. as long as the bandwidth is not enormous (less than, say, 2 octaves) an first-order approximation i came up with for "pre-fudging" the bandwidth is to multiply the analog bandwidth by sinc(w0/(pi*Fs)) or sin(w0/Fs)/(w0/Fs), where Fs is the sampling frequency in Hz. then: bw = sin(w0/Fs)/(w0/Fs) * (2/ln(2))*arcsinh(1/(2*Q)) and, i think the same is true for the normalized linear frequency bandwidth BW/w0 = sin(w0/Fs)/(w0/Fs) * Q this is the case for a digital filter designed from an analog prototype by use ot the bilinear transform. since "Q", as a parameter, affects the height of peaks in the frequency response (be it BPF or LPF or HPF), and the height of peaks remain unchanged by the BLT (but the location of the peaks gets bumped lower, slightly), i did not assume that the BLT warps Q as it does for bandwidth, so it is the relationship between the invariant Q and the variant bw that must get adjusted as shown above. hi ya, Ross. > Sorry I'm afraid this is pretty basic stuff... > > I spent some more time looking at the EQ equivalence paper and now think I > see the origin of the sinh term within the derivation of alpha for bandwidth > expressed in octaves. My understanding is that it arises from equation 10, > where the upper band edge frequency is related to the lower band edge > frequency by a factor of 2^bw. didn't you see my post (to music-dsp) of the 15th? where i typed: _______________________________________________________________________ ... for a simple 2nd-order BPF, if BW is octaves, the -3 dB bandedges are: lower bandedge: w1 = w0*2^(-BW/2) upper bandedge: w2 = w0*2^(+BW/2) linear bandwidth, bw, is related to Q as: Q = w0/bw and bw = w2 - w1 = w0*2^(+BW/2) - w0*2^(-BW/2) = w0*e^(+ln(2)*BW/2) - w0*e^(-ln(2)*BW/2) = w0 * 2*sinh( +ln(2)*BW/2 ) so, in an analog BPF biquad filter, the bandwidth, in octaves, is related to Q as: 1/Q = bw/w0 = 2*sinh( (ln(2)/2)*BW ) that's where the sinh() comes from. ... _______________________________________________________________________ > I don't really understand what guided you to change the base of the exponent > from 2 to e: > > 2^bw => e^beta where beta = ln(2)bw because the sinh() is defined in terms of the base e exponential, not the base 2. but octaves is base 2, not base e. > which in the end allowed the sinh to emerge using the identity > > sinh(x) == (e^x-e^-x)/2 > > I'm guessing this was just an 'obvious' simplification? whenever you see something of the form: a^(b) - a^(-b) or even x - 1/x then there is a sinh() function hiding in there. expressing it as such enables you to combine "a" or "b" or "x" into a single spot in the expression, in case you wanna solve for it (otherwize, you gotta do the quadratic formula which is actually how you can get a nice expression for arcsinh() in terms of the natural logarithm). if you were to change the "-" sign to a "+" sign, then it's a cosh() function hiding in there. the sinh() function happens when we express bandwidth in terms of octaves (or any other measure of log frequency, like decades) which seems natural when the signals being processed are music signals. -- r b-j rbj@... "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