-
Notifications
You must be signed in to change notification settings - Fork 186
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
LowPassFilter coefficients incorrectly calculated #144
Comments
The fix for The fix for
This still makes use of the sin x = x approximation, though pushes into less accurate territory. This raises the range to 3.9kHz for the lower sampling rate, 7.8kHz for the higher.
Now the input parameter, For all of these, adjustments need to be made for the fixed point arithmetic, since values can be more than 1. |
Hi, Thanks for your input, and sorry for the late reply! If I understand well, there are basically two problems with the current implementation: I think the Weirdly, I think (1) is an harder fix than (2): division a notoriously costly on small MCU so just replacing the multiplication by a division won't do the trick on the performance side I think. I will start digging into it and will keep you updated! |
Okay, I have an idea, will try to implement and test it soon. Basically, the idea would be to use the limited development (if someone can enlighten me with the correct English translation, I'll be grateful…) of Close to |
On behalf of Mozzi users, thanks to @mzero and @tomcombriat for your insights and work on this. |
The coefficients used in filter are incorrectly calculated.
The
fb
coefficient is calculated, effectively as:However, the proper equation, which is the comments at line 34, is:
The referenced algorithm at musicdsp.org correctly shows the division. The referenced fixed point code at dave's blog (pawfal.org) made the error of replacing the divide with a multiply. The error is noted in the comments to his post, and is now fixed the code in the post itself.
The effect of the error is that you can't get consistent resonance results with varying frequency.
The
f
coefficient is simply set to the input valuecutoff
, wherecutoff
maps the 8 bit fixed point value 0 to 255 to frequencies of 0 to ½ sample rate.However, it turns out that f in the DSP algorithm is computed as follows:
The effect of setting f to the input parameter directly, is that it maps 0 to 255 to frequencies of 0 to 1/6 sample rate.
The approximation of sin(x) = x for small x is good enough for this purpose, but the range of the filter is much less than expected. Rather than being able to set the cutoff of this filter between 0 and 8kHz, you can only set it between 0 and 2,7kHz.
The text was updated successfully, but these errors were encountered: