From fe2d9c197f93cbf2023eb3e07dbe769c95614e9f Mon Sep 17 00:00:00 2001 From: Curtis Malainey Date: Wed, 13 Mar 2019 12:54:15 -0700 Subject: [PATCH] EQ: Handle edge case in peaking filter Handle div by 0 case for gui Signed-off-by: Curtis Malainey --- tools/tune/eq/eq_define_parametric_eq.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/tune/eq/eq_define_parametric_eq.m b/tools/tune/eq/eq_define_parametric_eq.m index 444c5b86e..70a728e14 100644 --- a/tools/tune/eq/eq_define_parametric_eq.m +++ b/tools/tune/eq/eq_define_parametric_eq.m @@ -126,6 +126,17 @@ function [b, a] = peak_2nd(fhz, gdb, Q, fs) % Reference http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt A = 10^(gdb/40); % Square root of linear gain wc = 2*pi*fhz/fs; + + if Q <= 0 + % To fix gui edge cases, comment from CRAS code: + % When Q = 0, the above formulas have problems. If we + % look at the z-transform, we can see that the limit + % as Q->0 is A^2, so set the filter that way. + b = [A * A, 0, 0] + a = [1, 0, 0]; + return; + endif + alpha = sin(wc)/(2*Q); b0 = 1 + alpha * A; b1 = -2 * cos(wc);