{"id":1152,"date":"2013-09-12T12:26:32","date_gmt":"2013-09-12T10:26:32","guid":{"rendered":"http:\/\/www.tonmeister.ca\/wordpress\/?p=1152"},"modified":"2020-08-10T14:43:09","modified_gmt":"2020-08-10T12:43:09","slug":"q-vs-q","status":"publish","type":"post","link":"http:\/\/www.tonmeister.ca\/wordpress\/2013\/09\/12\/q-vs-q\/","title":{"rendered":"Q vs Q"},"content":{"rendered":"<p>I recently was interviewed by cycling74.com to talk about how I use Max\/MSP when I&#8217;m doing the sound design for loudspeakers at Bang &amp; Olufsen. I used part of the interview to &#8220;complain&#8221; gently about the fact that the filtergraph~ object in Max uses Robert Bristow-Johnson&#8217;s definition of &#8220;Q&#8221; without being explicit in stating that it does. (Don&#8217;t get me wrong here &#8211; I have no issues with RB-J&#8217;s definition &#8211; I just want to know what I&#8217;m using without having to find out for myself&#8230;)<\/p>\n<p>Following the interview&#8217;s publication on the website, there was a discussion that ensued about this issue. So, I decided to put my money where my mouth is and to find out for sure what the filtergraph~ object is doing.<\/p>\n<p>I could have done this by analysing the 5 coefficients that come out of the object. I decided not to do this &#8211; but to actually run an impulse through a biquad~ object to look at the whole filtergraph~ + biquad~ system. So, the patcher I put together to do the analysis looked like this<\/p>\n<p><a class=\"thumbnail\" href=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/Screen-Shot-2013-09-12-at-11.43.32-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1153\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/Screen-Shot-2013-09-12-at-11.43.32-AM.png\" alt=\"Screen Shot 2013-09-12 at 11.43.32 AM\" width=\"598\" height=\"454\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/Screen-Shot-2013-09-12-at-11.43.32-AM.png 598w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/Screen-Shot-2013-09-12-at-11.43.32-AM-300x227.png 300w\" sizes=\"auto, (max-width: 598px) 100vw, 598px\" \/><\/a><\/p>\n<p>\u00a0<\/p>\n<p>Admittedly, it&#8217;s a bit quick-and-dirty, but it does the job. If you&#8217;re wondering, the only reason the \/~ 16 object is there is to make sure I don&#8217;t clip the sfrecord~ object.<\/p>\n<p>I kept the centre frequency (fc) at 1 kHz and then did 24 combinations of 6 gains (0.0625, 0.25, 0.5, 2, 4, and 16) and 4 Q&#8217;s (1, 2, 4, 16), each producing a single impulse response that I imported into Matlab for analysis.<\/p>\n<p>So, the first question to answer is a rather simple one: Is the filtergraph~ object producing reciprocal peak\/dip or constant Q filters when you set its type to &#8220;peaknotch&#8221;? We can quickly figure this out by putting two filters in series with reciprocal gains and identical centre frequencies and Q&#8217;s and looking at the output. Instead, I&#8217;ll just put up a plot.<\/p>\n<p><a class=\"thumbnail\" href=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/q1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1154\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/q1.png\" alt=\"q1\" width=\"560\" height=\"420\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/q1.png 560w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/q1-300x225.png 300w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><\/p>\n<p>\u00a0<\/p>\n<p>This plot shows 6 filter settings, all with fc=1 kHz and Q = 1. The linear gains are\u00a00.0625, 0.25, 0.5, 2, 4, and 16. As you can see there, the filters with gains of 0.0625 and 16 (or -24 and +24 dB) are symmetrical. Therefore, we can reasonably conclude that we&#8217;re using reciprocal peak\/dip filters and not constant Q.<\/p>\n<p>Now to the meaty stuff. The question then is &#8220;exactly how is Q defined?&#8221; If you stay away from definitions of Q that involve damping or the S plane (see <a href=\"http:\/\/en.wikipedia.org\/wiki\/Q_factor\">here<\/a>), and we stick with the definitions that people who make filters use (i.e. see <a href=\"http:\/\/en.wikipedia.org\/wiki\/Q_factor#Electrical_systems\">here<\/a>\u00a0as an example), then there are (kind of) <em>seven<\/em>\u00a0different, but typical definitions of Q for a peaking filter. (Yes &#8211; SEVEN!) This is not because there are seven different equations for calculating Q. Q is calculated by dividing the frequency of the maximum of the peak in the magnitude response over the bandwidth of the boosted frequency band of the signal. (more simply expressed as Q = fc \/ bw). The problem is that the <em>bandwidth<\/em> is defined differently by different people, and therefore has different implementation in different gear.<\/p>\n<p>If the frequency band being affected is a boost, then you have three possible definitions of bandwidth:<\/p>\n<ol>\n<li>The bandwidth is the difference in Hz between the two frequencies that are 1\/sqrt(2) lower (in other words, -3.01 dB or half of the power) in magnitude than the highest peak in the magnitude response.<\/li>\n<li>But what do you do when the maximum peak is less than 3\u00a0db greater than the minimum magnitude? How do you find a -3 dB point? Well, in [Moorer, J. A. (1983). The manifold joys of conformal mapping: Applications to digital filtering in the studio. Journal of the Audio Engineering Society, 31(11):826\u2013841.], Andy Moorer suggested that, in this case, we use a different definition where we look for the frequencies where the magnitude is one-half the value of the maximum magnitude (in dB). So, if the peak in the magnitude response is +4 dB and the minimum is 0 dB, we look for the +2 dB points. The difference between these two points is the bandwidth.<\/li>\n<li>Robert Bristow-Johnson in his Cookbook and in [Bristow-Johnson, R. (1994). The equivalence of various methods of computing biquad coefficients for audio parametric equalizers. In 97th International Convention of the Audio Engineering Society. Audio Engineering Society.] rightly complains that this IF &gt; 6.02 dB ELSE statement is confusing. So, he suggested that we just use the half-gain definition all of the time. So, if you have a boost of 12 dB, you look for the 6 dB points to get the bandwidth.<\/li>\n<\/ol>\n<p>If the frequency band being affected is a cut, then you have four possible definitions.<\/p>\n<ol>\n<li>The bandwidth is the difference in Hz between the two frequencies that are 1\/sqrt(2) lower (in other words, -3.01 dB or half of the power) in magnitude than the highest peak in the magnitude response. This is interesting, because we&#8217;re looking at a cut &#8211; so the points we&#8217;re looking for are always -3.01 dB, regardless of the depth of the notch. This is what is known as a &#8220;constant Q&#8221; filter.<\/li>\n<li>The bandwidth is the difference in Hz between the two frequencies that are 1\/sqrt(2) <em>higher<\/em> (in other words, +3.01 dB or twice the power) in magnitude than the lowest dip in the magnitude response.<\/li>\n<li>We use Andy Moorer&#8217;s IF \/ THEN statement, but we&#8217;re looking for the +3.01 dB points above the dip when it is lower than -6.02 dB.<\/li>\n<li>We use Robert Bristow-Johnson&#8217;s definition and look for the mid-point between the maximum and minimum values in the magnitude response.<\/li>\n<\/ol>\n<p>So, we have 3 options if the band is boosted, and 4 options if it&#8217;s a cut.<\/p>\n<p>Enough of the back-story. Let&#8217;s look at how the filtergraph~ object behaves.<\/p>\n<p>As I said, I set the fc to 1 kHz and did impulse response of the 24 combinations of 6 gains and 4 Q&#8217;s. I then converted the impulse responses to magnitude responses with 2^17-point FFT&#8217;s (giving me a frequency resolution of &lt;1 Hz, since I did the impulse responses at 44.1 kHz). I then found out the Q of the results, using two definitions (the gain-midpoint, and the -3.01 dB definitions) of each. And the results are as follows:<\/p>\n<p>\u00a0<\/p>\n<p><!--EndFragment--><\/p>\n<table border=\"0\" width=\"260\" cellspacing=\"0\" cellpadding=\"0\"><!--StartFragment--> <colgroup> <col span=\"4\" width=\"65\" \/> <\/colgroup>\n<tbody>\n<tr>\n<td width=\"65\" height=\"15\"><strong>Linear Gain<\/strong><\/td>\n<td width=\"65\"><strong>MSP Q<\/strong><\/td>\n<td width=\"65\"><strong>Midpoint gain Q<\/strong><\/td>\n<td width=\"65\"><strong>-3.01 dB Q<\/strong><\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">0.0625<\/td>\n<td align=\"right\">1<\/td>\n<td align=\"right\">1.0<\/td>\n<td align=\"right\">1.0<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">0.25<\/td>\n<td align=\"right\">1<\/td>\n<td align=\"right\">1.0<\/td>\n<td align=\"right\">0.5<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">0.5<\/td>\n<td align=\"right\">1<\/td>\n<td align=\"right\">1.0<\/td>\n<td align=\"right\">0.3<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">2<\/td>\n<td align=\"right\">1<\/td>\n<td align=\"right\">1.0<\/td>\n<td align=\"right\">1.0<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">4<\/td>\n<td align=\"right\">1<\/td>\n<td align=\"right\">1.0<\/td>\n<td align=\"right\">1.9<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">16<\/td>\n<td align=\"right\">1<\/td>\n<td align=\"right\">1.0<\/td>\n<td align=\"right\">4.0<\/td>\n<\/tr>\n<tr>\n<td height=\"15\">\u00a0<\/td>\n<td>\u00a0<\/td>\n<td>\u00a0<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">0.0625<\/td>\n<td align=\"right\">2<\/td>\n<td align=\"right\">2.0<\/td>\n<td align=\"right\">0.5<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">0.25<\/td>\n<td align=\"right\">2<\/td>\n<td align=\"right\">2.0<\/td>\n<td align=\"right\">1.1<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">0.5<\/td>\n<td align=\"right\">2<\/td>\n<td align=\"right\">2.0<\/td>\n<td align=\"right\">2.0<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">2<\/td>\n<td align=\"right\">2<\/td>\n<td align=\"right\">2.0<\/td>\n<td align=\"right\">2.0<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">4<\/td>\n<td align=\"right\">2<\/td>\n<td align=\"right\">2.0<\/td>\n<td align=\"right\">3.8<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">16<\/td>\n<td align=\"right\">2<\/td>\n<td align=\"right\">2.0<\/td>\n<td align=\"right\">8.0<\/td>\n<\/tr>\n<tr>\n<td height=\"15\">\u00a0<\/td>\n<td>\u00a0<\/td>\n<td>\u00a0<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">0.0625<\/td>\n<td align=\"right\">4<\/td>\n<td align=\"right\">4.0<\/td>\n<td align=\"right\">1.0<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">0.25<\/td>\n<td align=\"right\">4<\/td>\n<td align=\"right\">4.0<\/td>\n<td align=\"right\">2.1<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">0.5<\/td>\n<td align=\"right\">4<\/td>\n<td align=\"right\">4.0<\/td>\n<td align=\"right\">4.0<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">2<\/td>\n<td align=\"right\">4<\/td>\n<td align=\"right\">4.0<\/td>\n<td align=\"right\">4.0<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">4<\/td>\n<td align=\"right\">4<\/td>\n<td align=\"right\">4.0<\/td>\n<td align=\"right\">7.5<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">16<\/td>\n<td align=\"right\">4<\/td>\n<td align=\"right\">4.0<\/td>\n<td align=\"right\">16.1<\/td>\n<\/tr>\n<tr>\n<td height=\"15\">\u00a0<\/td>\n<td>\u00a0<\/td>\n<td>\u00a0<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">0.0625<\/td>\n<td align=\"right\">16<\/td>\n<td align=\"right\">15.9<\/td>\n<td align=\"right\">4.0<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">0.25<\/td>\n<td align=\"right\">16<\/td>\n<td align=\"right\">15.9<\/td>\n<td align=\"right\">8.5<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">0.5<\/td>\n<td align=\"right\">16<\/td>\n<td align=\"right\">15.9<\/td>\n<td align=\"right\">15.9<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">2<\/td>\n<td align=\"right\">16<\/td>\n<td align=\"right\">16.2<\/td>\n<td align=\"right\">16.2<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">4<\/td>\n<td align=\"right\">16<\/td>\n<td align=\"right\">16.2<\/td>\n<td align=\"right\">30.3<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" height=\"15\">16<\/td>\n<td align=\"right\">16<\/td>\n<td align=\"right\">16.2<\/td>\n<td align=\"right\">66.0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>There are a few things to mention here:<\/p>\n<ul>\n<li>The &#8220;midpoint gain Q&#8221; values are slightly different at high &#8220;MSP Q&#8221; values, probably due to small errors caused by my limited resolution in the frequency domain. Please feel to ignore the fact that they are not identical to the &#8220;MSP Q&#8221;. Call it a measurement error.<\/li>\n<li>In the case of the gains of 2 and 0.5, the two Q&#8217;s will always match, since the -3.01 dB point is the gain-midpoint. (This is just a nice rule of thumb to remember &#8211; like the fact that -40\u00b0 C = -40\u00b0 F.)<\/li>\n<li>As you can see, the higher the Q and the higher the gain (or attenuation), the more the two definitions of Q diverge. This can be a problem if (taking me as an example) you are working with someone who does a measurement of a system that needs correction with a filter, and then you implement the correction with a filter. The only problem here is that they&#8217;re using the -3 dB definition and you&#8217;re using Max\/MSP, for example&#8230; Bad things will happen if they want a Q of 16 but you&#8217;re giving them a Q of 66 (see the last line of the table above) &#8211; just because you think you&#8217;re saying the same thing but you&#8217;re not.<\/li>\n<li>Obviously (ignoring measurement error &#8211; see above) Max\/MSP&#8217;s filtergraph~ object uses Robert Bristow-Johnson&#8217;s equations for the peaknotch type of filter.<\/li>\n<\/ul>\n\n\n<p>N.B. If you need to convert from one system to another, I&#8217;ve described how to do this in <a href=\"https:\/\/www.tonmeister.ca\/wordpress\/2020\/08\/10\/translating-q-to-q\/\">this posting<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently was interviewed by cycling74.com to talk about how I use Max\/MSP when I&#8217;m doing the sound design for loudspeakers at Bang &amp; Olufsen. I used part of the interview to &#8220;complain&#8221; gently about the fact that the filtergraph~ object in Max uses Robert Bristow-Johnson&#8217;s definition of &#8220;Q&#8221; without being explicit in stating that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[],"class_list":["post-1152","post","type-post","status-publish","format-standard","hentry","category-audio"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p48hIM-iA","_links":{"self":[{"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/posts\/1152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/comments?post=1152"}],"version-history":[{"count":5,"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/posts\/1152\/revisions"}],"predecessor-version":[{"id":6141,"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/posts\/1152\/revisions\/6141"}],"wp:attachment":[{"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/media?parent=1152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/categories?post=1152"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/tags?post=1152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}