Skip to content

Fix sign of b2 in synthio PEAKING_EQ biquad - #11275

Merged
tannewt merged 1 commit into
adafruit:mainfrom
bdbarnett:fix-peaking-eq-sign
Aug 31, 2026
Merged

Fix sign of b2 in synthio PEAKING_EQ biquad#11275
tannewt merged 1 commit into
adafruit:mainfrom
bdbarnett:fix-peaking-eq-sign

Conversation

@bdbarnett

Copy link
Copy Markdown

Fixes #11265.

common_hal_synthio_biquad_tick() computes the PEAKING_EQ numerator
with b2 = 1 + alpha * A; the RBJ cookbook peaking section is

b0 = 1 + alpha*A    b1 = -2*cos(w0)    b2 = 1 - alpha*A
a0 = 1 + alpha/A    a1 = -2*cos(w0)    a2 = 1 - alpha/A

The minus is what makes numerator and denominator sum to the same value
at DC and again at Nyquist — unity everywhere except the band around
f0. With the plus, the numerator picks up 2*alpha*A at DC that the
denominator does not, so the "bell" is actually a bass shelf with a
bell buried in it.

Measured on a unix coverage build of main, a +6 dB bell at 1 kHz,
Q 1, 48 kHz (audiofilters.Filter fed DC and sine RawSamples):

before after should be
DC +21.39 dB −0.11 0.00
centre +23.42 dB +5.94 +6.00
12 kHz −0.01 dB +0.03 0.00

The other six filter modes already match the cookbook and are
untouched. The wrong coefficient reaches both audiofilters.Filter
and synthio.Note.filter, since they share these coefficients.

Includes a regression test (tests/circuitpython/synthio_biquad_peaking.py)
that checks the DC, centre, and 12 kHz gains; it fails on current
main and passes with the fix. The neighboring biquad/filter tests
that pass on unmodified main in the same environment still pass.

The RBJ cookbook peaking section is b2 = 1 - alpha*A; the + turned a
+6 dB bell at 1 kHz into a bass shelf reading +21.4 dB at DC. With the
minus the response is unity at DC and Nyquist and hits its gain at the
centre frequency, as measured on the unix build.

Adds a regression test that checks DC, centre, and 12 kHz gains.

Fixes adafruit#11265

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@tannewt
tannewt merged commit cc11ec6 into adafruit:main Aug 31, 2026
538 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

synthio.Biquad PEAKING_EQ has the wrong sign on b2

2 participants