C++ classes for designing high-order Butterworth IIR & equalization filters
C++ classes for designing high-order Butterworth IIR & equalization filters
Butterworth Filter Design is a collection of C++ classes and an accompanying suite of unit tests for designing high order Butterworth IIR and EQ filters using the bilinear transform.
The generated filter coefficients are split out into cascaded biquad sections, for easy use in any biquad or second-order section (SOS) implementation.
As with any good audio signal processing toolkit, there are unit tests that provide basic proof of correctness. There are currently 6 primary test cases that check 113 different conditions.
Unit tests live in tests.cpp and are written using the compact Catch2 test framework for C++.
MacOS →
$ brew install catch2$ brew install libsndfileLinux →
$ sudo apt-get update; sudo apt-get install catch2$ sudo apt-get install libsndfile1The unit tests are a good place to start for a survey of usage.
$ export LDFLAGS="-L$(brew --prefix libsndfile)/lib"
$ export CPPFLAGS="-I$(brew --prefix libsndfile)/include"
$ cmake ..
$ make
$ ctestFor example, to design an 8-tap Butterworth lowpass filter with a cutoff @ 500Hz (which will generate coefficients for 4 biquad filters), running @ 44100Hz, with unity gain (1.0) execute the following:
vector coeffs; // array of biquad filters (for this case, array size = 4 )
Butterworth butterworth;
bool designedCorrectly = butterworth.loPass(44100, // fs
500, // freq1
0, // freq2. N/A for lowpass
8, // filter order,
coeffs, // coefficient array being filled
1.0); // overall gainTo generate the same set of coefficients in MATLAB (R14) as a comparison, to double-check our work, execute the following MATLAB commands:
[z, p, k] = butter(8, 500, 's'); % designs a 8-tap lowpass s-domain filter
[Zd, Pd, Kd] = bilinear(z, p, k, 44100); % analog-to-digital filter conversion
[sos, g] = zpk2sos(Zd, Pd, Kd) % zero-pole-gain form to second-order sections (SOS)For my Master's thesis, and in the course of work writing audio plugins and music apps, I've implemented a few different IIR and EQ filter design classes (e.g. RBJ's EQ Cookbook, Cheby and Butter IIRs). These classes are a fresh rewrite and should be considered unoptimized reference code, with an emphasis on clarity (and for pedagogical reasons, being able to refer to the textbook, see the math and understand the code). For this reason, in the hope they can be useful, these classes are provided under GPL v3.
Butterworth Filter Design - Copyright © 2013 iroro orife
Source code is provided under GPL v3
No open issues yet, or sync has not completed.