Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I know this is a post on an old thread, and I would usually leave this as a comment, but I'm apparently not able to do that.</p> <p>In any case, for people searching for similar code, I thought I would post the link from where this code originates (it also has C code for other types of Butterworth filter coefficients and some other cool signal processing code).</p> <p>The code is located here: <a href="http://www.exstrom.com/journal/sigproc/">http://www.exstrom.com/journal/sigproc/</a></p> <p>Additionally, I think there is a piece of code which calculates said scaling factor for you already.</p> <pre><code>/********************************************************************** sf_bwbp - calculates the scaling factor for a butterworth bandpass filter. The scaling factor is what the c coefficients must be multiplied by so that the filter response has a maximum value of 1. */ double sf_bwbp( int n, double f1f, double f2f ) { int k; // loop variables double ctt; // cotangent of theta double sfr, sfi; // real and imaginary parts of the scaling factor double parg; // pole angle double sparg; // sine of pole angle double cparg; // cosine of pole angle double a, b, c; // workspace variables ctt = 1.0 / tan(M_PI * (f2f - f1f) / 2.0); sfr = 1.0; sfi = 0.0; for( k = 0; k &lt; n; ++k ) { parg = M_PI * (double)(2*k+1)/(double)(2*n); sparg = ctt + sin(parg); cparg = cos(parg); a = (sfr + sfi)*(sparg - cparg); b = sfr * sparg; c = -sfi * cparg; sfr = b - c; sfi = a - b - c; } return( 1.0 / sfr ); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload