Thursday, August 24, 2017

filters - Prewarping both resonant frequency $f_0$ 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.



$dB_\text{gain}$ is the number of dB gain of the peak (for $dB_\text{gain} > 0$) or cut (for $dB_\text{gain} < 0$). it appears to be 6 dB in the plots.


$$A^2 \triangleq 10^{dB_\text{gain}/20}$$


is the linear gain for the boost or cut.


$f_\text{s}$ is sample rate.


$f_0$ 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


$$\begin{align} \\ H(s) &= \frac{b_0 + b_1 s + b_2 s^2 }{1 + a_1 s + a_2 s^2} \\ \\ &= \frac{b_0 + b_1 s + b_2 s^2}{1 + \frac{1}{Q}\frac{s}{2 \pi f_0} + \left(\frac{s}{2 \pi f_0} \right)^2} \\ \\ \end{align} $$


don't mistake the $a_k, \ b_k$ 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) = \frac{ \frac{1}{Q}\frac{s}{2 \pi f_0} }{1 + \frac{1}{Q}\frac{s}{2 \pi f_0} + \left(\frac{s}{2 \pi f_0} \right)^2} $$



note when $f = f_0$ then $H(j 2 \pi f_0) = 1$. note also that there are two bandedges $f_+$ and $f_-$ such that $f_- < f_0 < f_+$ and


$$ f_+ = f_0 \cdot 2^{bw/2} $$ $$ f_- = f_0 \cdot 2^{-bw/2} $$


and


$$ |H(j 2 \pi f_-)|^2 = |H(j 2 \pi f_+)|^2 = \frac{1}{2} \quad . $$


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_+ = 2^{bw} f_-$ 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:


$$\begin{align} \\ \frac{1}{Q} &= \frac{2^{bw} - 1}{2^{bw/2}} \\ \\ &= 2 \ \sinh \left( \frac{\ln(2)}{2} \ bw \right) \\ \end{align} $$




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:


$$\begin{align} H(s) &= (A^2 - 1)\frac{ \frac{1}{Q}\frac{s}{2 \pi f_0} }{1 + \frac{1}{Q}\frac{s}{2 \pi f_0} + \left(\frac{s}{2 \pi f_0} \right)^2} \ + 1 \\ \\ &= \frac{1 + \frac{A^2}{Q}\frac{s}{2 \pi f_0} + \left(\frac{s}{2 \pi f_0} \right)^2}{1 + \frac{1}{Q}\frac{s}{2 \pi f_0} + \left(\frac{s}{2 \pi f_0} \right)^2}\\ \end{align}$$


this is the "traditional" analog parametric EQ. note that $$|H(j 2 \pi f_0)| = A^2 = 10^{dB_\text{gain}/20} \quad .$$ the problem is that, leaving $f_0$ and $Q$ constant, the curve for $dB_\text{gain} > 0$ is not a mirror image for $dB_\text{gain} < 0$, given the same number of dB, $|dB_\text{gain}|$, 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 \ \leftarrow \ A \cdot Q $$


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


$$\begin{align} H(s) &= \frac{1 + \frac{A^2}{A \cdot Q}\frac{s}{2 \pi f_0} + \left(\frac{s}{2 \pi f_0} \right)^2}{1 + \frac{1}{A \cdot Q}\frac{s}{2 \pi f_0} + \left(\frac{s}{2 \pi f_0} \right)^2} \\ \\ &= \frac{1 + \frac{A}{Q}\frac{s}{2 \pi f_0} + \left(\frac{s}{2 \pi f_0} \right)^2}{1 + \frac{1}{A \ Q}\frac{s}{2 \pi f_0} + \left(\frac{s}{2 \pi f_0} \right)^2} \\ \end{align} $$


note that if $dB_\text{gain}$ is replaced with $-dB_\text{gain}$, then $A$ is replaced with $\frac{1}{A}$ 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$:


$$ \frac{1}{Q} = 2 \ \sinh \left( \frac{\ln(2)}{2} \ bw \right) $$


then the bandedges


$$ f_+ = f_0 \cdot 2^{+bw/2} $$ $$ f_- = f_0 \cdot 2^{-bw/2} $$


satisfy this gain definition:



$$ |H(j 2 \pi f_-)| = |H(j 2 \pi f_+)| = A = 10^{dB_\text{gain}/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{...