Thursday, August 24, 2017

filters - Prewarping both resonant frequency f0 and bandwidth (or Q) when using bilinear transform


RBJ's Audio EQ cookbook takes into account only frequency prewarping when case Q is used for bandwidth. Why not Q prewarping as well with some of those filter types defined there? At KVR I got info that BLT turns to kind of II (Impulse Invariant) when both prewarpings are in use and BLT looses some nice properties in that case.



Well, I tried the Q prewarping and made few plots:


enter image description here


Right column plots uses EE's Q definition just for the (original) cookbook. Did not check the situation of phases.


If my plots are correct then it looks like prewarping Q might bring some improvement at least for peak filter magnitude. For LP filter, situation is different.


BTW, some doctoral thesis showed plots where both prewarpings were used and set to have same factor. How's that factoring done?


Any thoughts?


EDIT: Plots showing the end results for this query. enter image description here Clarifications can be found from RBJ's answer and comments related to that answer.



Answer



alright, there are a couple of different issues that may (or may not) need to be de-conflated.


i'm gonna try to keep the number of symbols minimized.



dBgain is the number of dB gain of the peak (for dBgain>0) or cut (for dBgain<0). it appears to be 6 dB in the plots.


A210dBgain/20


is the linear gain for the boost or cut.


fs is sample rate.


f0 is frequency of the boost or cut in the same units as the sample rate.


the analog transfer function of a resonant second-order filter (a.k.a. "biquad" or "SOS") is


H(s)=b0+b1s+b2s21+a1s+a2s2=b0+b1s+b2s21+1Qs2πf0+(s2πf0)2


don't mistake the ak, bk coefficients of the analog prototype with those in the resulting digital filter from the recipe in the cookbook. this is how the "EE definition" of Q is defined.


an analog BPF with passband gain of 0 dB, has transfer function:


H(s)=1Qs2πf01+1Qs2πf0+(s2πf0)2



note when f=f0 then H(j2πf0)=1. note also that there are two bandedges f+ and f such that f<f0<f+ and


f+=f02bw/2 f=f02bw/2


and


|H(j2πf)|2=|H(j2πf+)|2=12.


we define those bandedges for the BPF to be the "half-power frequencies" (a.k.a. "-3 dB frequencies"). and the bw parameter is the bandwidth expressed in octaves. the higher bandedge f+=2bwf is bw octaves higher log frequency than the lower bandedge f. turns out that this bandwidth bw in octaves is related to Q as follows:


1Q=2bw12bw/2=2 sinh(ln(2)2 bw)




keeping the same definition of Q, the "bell-shaped" boost/cut parametric EQ takes that BPF, gives it some gain (with sign) and adds it to a wire. it has transfer function:


H(s)=(A21)1Qs2πf01+1Qs2πf0+(s2πf0)2 +1=1+A2Qs2πf0+(s2πf0)21+1Qs2πf0+(s2πf0)2


this is the "traditional" analog parametric EQ. note that |H(j2πf0)|=A2=10dBgain/20. the problem is that, leaving f0 and Q constant, the curve for dBgain>0 is not a mirror image for dBgain<0, given the same number of dB, |dBgain|, boost or cut. the cut will be much skinnier than the boost.



some people might want the cut to exactly undo the boost given all other parameters being the same. so in the cookbook (and in some other papers), a redefinition of Q is made. this redefinition is the substitution:


Q  AQ


so that makes the transfer function for the parametric EQ (with adjusted Q):


H(s)=1+A2AQs2πf0+(s2πf0)21+1AQs2πf0+(s2πf0)2=1+AQs2πf0+(s2πf0)21+1A Qs2πf0+(s2πf0)2


note that if dBgain is replaced with dBgain, then A is replaced with 1A and the numerator and denominator of H(s) are essentially swapped, which causes the frequency response of the cut to mirror that of the boost.


now, using the same relationship between bandwidth bw and Q:


1Q=2 sinh(ln(2)2 bw)


then the bandedges


f+=f02+bw/2 f=f02bw/2


satisfy this gain definition:



|H(j2πf)|=|H(j2πf+)|=A=10dBgain/40


which are the "mid-gain frequencies" having dB gain of \frac{dB_\text{gain}}{2}.


so the definition of bandedge gain is a bit different, but at least for the analog prototype, we're keeping the relationship between bw and Q the same. higher Q means tighter bw.


so, first, before we discuss "warping Q", let's be completely consistent about which Q to compare. for this, i might recommend leaving the "EE definition" of Q behind to not confuse.




so the bilinear transform which compensates for the frequency warping at the "significant frequency" or the resonant frequency f_0 makes this substitution:


\text{normalized }s \triangleq \frac{s}{2 \pi f_0} \ \leftarrow \ \frac{1}{\tan(\pi f_0/f_\text{s})} \ \frac{1 - z^{-1}}{1 + z^{-1}}


H(z) is the resulting digital filter transfer function after making that substitution for normalized s.


the frequency warping function turns out to be:


f_\text{analog} = \frac{f_0}{\tan\left(\pi \frac{f_0}{f_\text{s}} \right)} \ \tan\left( \pi \frac{f_\text{digital}}{f_\text{s}} \right) or f_\text{digital} = \frac{f_\text{s}}{\pi} \ \arctan \left( \tan\left(\pi \frac{f_0}{f_\text{s}} \right) \frac{f_\text{analog}}{f_0} \right)



(note that DC gets mapped to DC and f_0 gets mapped to f_0, but when f_\text{analog} \to \infty, then f_\text{digital} \to \frac{f_\text{s}}{2}.)


fixing (or "prewarping") f_0 does not compensate for a cramped bandwidth because, besides the resonant frequency f_0, so also are the bandedges f_+ and f_- warped by the bilinear transform. measured in octaves the bandwidth, BW, in the digital filter is:


\begin{align} BW &= \log_2\left( \frac{f_\text{s}}{\pi} \arctan \left( \tan\left(\pi \frac{f_0}{f_\text{s}} \right) \right) \frac{f_+}{f_0} \right) - \log_2\left( \frac{f_\text{s}}{\pi} \arctan \left( \tan\left(\pi \frac{f_0}{f_\text{s}} \right) \frac{f_-}{f_0} \right) \right) \\ \\ &= \log_2\left(\arctan \left(\tan\left(\pi \frac{f_0}{f_\text{s}}\right) 2^{+bw/2} \right) \right) - \log_2\left(\arctan \left(\tan\left(\pi \frac{f_0}{f_\text{s}}\right) 2^{-bw/2} \right) \right) \\ \\ &= \log_2\left(\frac{\arctan \left(\tan\left(\pi \frac{f_0}{f_\text{s}}\right) 2^{+bw/2} \right)}{\arctan \left(\tan\left(\pi \frac{f_0}{f_\text{s}}\right) 2^{-bw/2} \right)} \right) \\ \\ \end{align}


you can see that the mapping of bw to BW is an odd-symmetry function, so it goes through 0 and has no even-order terms in a Maclaurin (a.k.a. Taylor series) expansion. now if you fix f_0 and plot digital BW vs. analog bw, you will see that BW < bw and that is the bandwidth cramping done by frequency warping of the bilinear transform. to uncramp the bandwidth, you would have to solve for bw in terms of BW and f_0 and f_\text{s}. and that is (how shall we say?) a female canine.


if you read the cookbook a little, you will notice a slightly adjusted mapping between BW and Q:


\frac{1}{Q} = 2 \ \sinh \left( \frac{\ln(2)}{2} \ BW \frac{2 \pi f_0/f_\text{s}}{\sin(2 \pi f_0/f_\text{s})} \right)


so the digital filter bandwidth BW was increased by a factor of \frac{2 \pi f_0/f_\text{s}}{\sin(2 \pi f_0/f_\text{s})} as a first-order attempt to compensate for the bandwidth cramping. this result comes from assuming a narrow bandwidth in the first place and evaluating the derivative:


\frac{\partial \, BW}{\partial \, bw} \Bigg|_{bw = 0} = \frac{\sin(2 \pi f_0/f_\text{s})}{2 \pi f_0/f_\text{s}}


the first term of the Maclaurin series is


BW \approx \frac{\sin(2 \pi f_0/f_\text{s})}{2 \pi f_0/f_\text{s}} bw



compensating (or "prewarping") that first-order cramping of the bandwidth (which is what i think you mean by "prewarping Q") is done in the cookbook and always has been. but it is only a first-order compensation. if you want to do it better, be my guest and try to compute the next third-order term for the Maclaurin expansion (and flip it around so you have an expression of the approximate analog bw in terms of digital BW). doing this with Maclaurin series expansion is the only way i know because i don't think you will invert the bw \to BW mapping above directly.


No comments:

Post a Comment

periodic trends - Comparing radii in lithium, beryllium, magnesium, aluminium and sodium ions

Apparently the of last four, \ce{Mg^2+} is closest in radius to \ce{Li+}. Is this true, and if so, why would a whole larger shell ($\ce{...