Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createIIRFilter should take doubles #631

Closed
rtoy opened this issue Oct 15, 2015 · 0 comments
Closed

createIIRFilter should take doubles #631

rtoy opened this issue Oct 15, 2015 · 0 comments
Assignees
Labels
Needs Edits Decision has been made, the issue can be fixed. https://speced.github.io/spec-maintenance/about/
Milestone

Comments

@rtoy
Copy link
Member

rtoy commented Oct 15, 2015

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):

iirfilter-float

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:

iirfilter-double

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.

@rtoy rtoy self-assigned this Oct 15, 2015
rtoy pushed a commit to rtoy/web-audio-api that referenced this issue Oct 15, 2015
The coefficients for createIIRFilter are explicitly doubles and not
floats now.

We also fix a minor issue that was accepted in
WebAudio#323 where a sequence<float> was allowed instead
of Float32Array to make it easier for the developer to specify
coefficients.

Note that for some reason respec replaces sequence<double> with just
sequence in the document.  Is this a bug in respec?

Fix WebAudio#631
@mdjp mdjp added this to the Web Audio V1 milestone Oct 16, 2015
@joeberkovitz joeberkovitz added the Needs Edits Decision has been made, the issue can be fixed. https://speced.github.io/spec-maintenance/about/ label Oct 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Edits Decision has been made, the issue can be fixed. https://speced.github.io/spec-maintenance/about/
Projects
None yet
Development

No branches or pull requests

3 participants