Butterworth Coefficient Calculator

Here is a quickie post.  I inadvertently screwed up my Gnu Octave install, but still had to spit out a bunch of biquad coefficients for Butterworth filters, so I tossed this helper app together. It is a gui-less terminal app for OSX, so just double-click and follow the instructions. You should see this:

ButterCalc

You can choose 2nd-10th order (1-5 biquad second-order sections)… even number only. I COULD have added in single pole filters for odd orders but pfffffft. As you can see, it spits out an array that you can just copy/paste and run with. The format is a0,a1,a2,b1,b2 (or b0,b1,b2,a1,a2 if you prefer the numerator and denominator swapped).

I calculated the normalized butterworth polynomials out to as may decimal places as I had the stomach for, and then calculated the Q factors out to doubles. For the sake of posterity and nerd-ity, here is a table of the Q factors:


Order: slope: Q (per second order section)
2 : 12dB/Oct: 0.70710678117310
4 : 24dB/Oct: 0.54119610015281, 1.3065629649279
6 : 36dB/Oct: 0.51763809019918, 0.70710678117310, 1.93185165259695
8 : 48dB/Oct: 0.50979557910584, 0.60134488693689, 0.89997622316817, 2.56291544795338
10: 60dB/Oct: 0.50623256289151, 0.56116311880985, 0.7071067811731, 1.10134463226727, 3.19622661055023

Sorry that the app is OSX-only, but you can use the table above to roll your own if you are on another OS. Here is the coeff code I used (the equations are well-known, but whatever) for each section:


// user variables
double Q, sampleRate, cutoffFreq;
int order;

// intermediate values
double normalizedFc = cutoffFreq/sampleRate;
double K = tan(M_PI * normalizedFc);
double W = K*K;
double invNorm = 1.0/ (1.0 + K / Q + W);

// coeffs
double a0 = W * invNorm;
double a1 = 2.0 * a0;
double a2 = a0;
double b1 = 2.0 * (W - 1.0) * invNorm;
double b2 = (1.0- K / Q + W) * invNorm;

The cutoff is the same for each Butterworth section, only the Q changes.

Advertisements

About alexkenis

Guitarist, philosopher, tinkerer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: