-
Notifications
You must be signed in to change notification settings - Fork 16
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
Extract coefficients from IIR filter #4
Comments
The For example: #include <Filters.h>
#include <Filters/Butterworth.hpp>
// Sampling frequency
const double f_s = 100; // Hz
// Cut-off frequency (-3 dB)
const double f_c = 25; // Hz
// Normalized cut-off frequency
const double f_n = 2 * f_c / f_s;
// Sixth-order Butterworth filter
auto butter_sos = butter_coeff<6>(f_n);
auto butter_tf = sos2tf(butter_sos);
void setup() {
Serial.begin(115200);
while (!Serial);
Serial << setprecision(7);
Serial << "fₙ: " << f_n << endl;
Serial << "b: " << butter_tf.b << endl;
Serial << "a: " << butter_tf.a << endl;
}
void loop() {} Prints:
You can compare them to the coefficients generated by SciPy, for example: from scipy.signal import butter
f_s = 100 # Hz, Sampling frequency
f_c = 25 # Hz, Cut-off frequency (-3 dB)
f_n = 2 * f_c / f_s # Normalized cut-off frequency
b, a = butter(6, f_n)
print('b:', ', '.join(map(lambda x: f'{x:10.7f}', b)))
print('a:', ', '.join(map(lambda x: f'{x:10.7f}', a))) Prints:
A Butterworth filter has no ripple, apart from the filter order, the cut-off frequency is the only parameter, see https://tttapa.github.io/Pages/Mathematics/Systems-and-Control-Theory/Analog-Filters/Butterworth-Filters.html#mjx-eqn-8. |
Great thank you for your prompt reply and the additional precisions. I have been confused by the MATLAB designfilt GUI. But it seems all make sense to me now. |
Hi there,
I see the implementation require high knowledge of C++ coding. I have been through the example of the Butterworth filter, and I am keen on getting the b and a coefficients to compare with an algorithm I have developed on another platform.
Do you know a simple method to extract them?
Also can you confirm the filter is only specified by the cut-off frequency? (i.e. no pass band ripple, stop band attenuation?
Thank you
Sylvano
The text was updated successfully, but these errors were encountered: