createIIRFilter should take doubles #631
Labels
Needs Edits
Decision has been made, the issue can be fixed. https://speced.github.io/spec-maintenance/about/
Milestone
Currently, createIIRFilter expects the filter coefficients to be floats. This has accuracy implications.
Consider this simple case of cascading two lowpass biquad filters. The output of that should be identical to an IIR filter created using the appropriate coefficients computed from the biquad filter coefficients. If we do that, we get the following graph (with an impulse of amplitude 100):
Note that the max difference between the cascaded biquads and the IIR filter is about .006. That's rather large.
If we do the same where createIIRFilter accepts doubles for the coefficients, we get this graph:
The peak error is greatly reduced.
Also, since we support filter orders up to 20, the filter is fairly sensitive to the coefficients, and if the filter is close to being unstable, restricting the coefficients to floats can easily make the filter unstable, even if the original design is stable.
For these reasons, createIIRFilter should take doubles for the coefficients. This does not prevent implementations from internally converting the doubles to floats if desired, but the current method prevents implementations that want to do a more accurate implementation.
The text was updated successfully, but these errors were encountered: