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

Butterworth odd orders look incorrect #6

Open
johnmgithub opened this issue Jan 18, 2019 · 5 comments
Open

Butterworth odd orders look incorrect #6

johnmgithub opened this issue Jan 18, 2019 · 5 comments
Assignees
Labels

Comments

@johnmgithub
Copy link

johnmgithub commented Jan 18, 2019

For odd filter orders a pair of real poles get added rather than a single pole, don't think that is right. In Butterworth::prototypeAnalogLowPass(int filterOrder) rather than

for(uint32_t k = 0; k < (filterOrder + 1) / 2; k++){
double theta = (double)(2 * k + 1) * M_PI / (2 * filterOrder);
double real = -sin(theta);
double imag = cos(theta);
poles.push_back(complex_double(real, imag));
poles.push_back(complex_double(real, -imag)); // conjugate
}

might need something like

for(uint32_t k = 0; k < filterOrder / 2; k++){
double theta = (double)(2 * k + 1) * M_PI / (2 * filterOrder);
double real = -sin(theta);
double imag = cos(theta);
poles.push_back(complex_double(real, imag));
poles.push_back(complex_double(real, -imag)); // conjugate
}
if (filterOrder % 2 == 1){
poles.push_back(complex_double(-1, 0);
}
`

@ruohoruotsi
Copy link
Owner

Thank you John, do you want to submit a pull-request and a unit test? This issues highlights the need for more comprehensive tests as well as visual reasoning aids for pedagogical purposes. Cheers.

@johnmgithub
Copy link
Author

Afraid I don't have a C++ dev environment, Java for me. Was just mooching about looking at Butterworth pole calculations to extract Q values for cascaded biquads and noticed it looked off.

@ruohoruotsi
Copy link
Owner

okay, thank you for the heads up. I'll fix it, I also wonder if its related to the gain issues someone else reported #3 (which I also need to fix). Cheers!

@ruohoruotsi ruohoruotsi self-assigned this Jan 21, 2019
@Uight
Copy link

Uight commented Jun 11, 2024

@johnmgithub is actually right with this. The poles for all odd filter orders are wrong if not corrected as show in the code he shared.
I converted your code to c# and with that i was able to show that against some manual test i did against matlab.
This bug however is not related to the one described in #3.

i verified all zero, poles and gains before the method zp2SOS which makes me believe that zp2Sos is actually wrong. If you apply the fix from here and use the method described in #3 where you multiple the gain with the values from ab[] then you can get first order and second order running for everything

@ruohoruotsi
Copy link
Owner

thank you @Uight, looks like I need to get on with fixing some of these issues, notably with zp2SOS ...thank you for you comment and attention. I'll make it a priority! 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants