Skip to content

synthio: Replace Biquad's fast_sincos() - #11678

Open
bdbarnett wants to merge 1 commit into
adafruit:mainfrom
bdbarnett:biquad-trig-fix
Open

bdbarnett wants to merge 1 commit into
adafruit:mainfrom
bdbarnett:biquad-trig-fix

Conversation

@bdbarnett

Copy link
Copy Markdown

First of the three changes from #11269. The old sine/cosine fit only covers 0 to pi/2, so filters above sample_rate/4 ran off its end: at 48 kHz a 22 kHz low-pass was 7 dB down at its cutoff.

This reflects the angle into 0 to pi/4 and uses a four-term minimax polynomial for each of sine and cosine. Worst error up to Nyquist drops from 0.17 to 1.2e-7. A coefficient update takes 9 multiplies and 9 adds (was 10 and 7), and raspberry_pi_pico grows by 32 bytes.

Tested with a new synthio_biquad_high_frequency test on the unix coverage build, and on a Pico Plus 2 W and a Feather RP2040, where a 50 Hz low-pass gives sample-identical output to main. I didn't regenerate synthio_biquad.py.exp: it already differs from main's output on my machine, and this changes it, since it sweeps past Nyquist.

Written by an agent, reviewed by a human

The old fit covered [0, pi/2] only. A filter above sample_rate / 4 used it
outside that range, where the error grows to 0.17 by Nyquist, so a low-pass
at 22 kHz / 48 kHz was 7 dB down at its own cutoff and a 22 kHz high-pass
rejected a 12 kHz tone by only 28 dB.

Reflect the angle into [0, pi/2] and then into [0, pi/4] by swapping sine and
cosine, and evaluate a four-term minimax polynomial for each. The error is
at the last bits of a float over the whole 0..Nyquist range, and a frequency
above Nyquist is merely wrong rather than absurd.
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.

1 participant