//------------------------------------------------------------------------------ void designFirstOrderLowpass(double* dcoefs, double cutoff, double withFs) // design parametric filter based on input center frequency, gain, Q and sampling rate { double b0, b1, b2, a0, a1, a2; //storage for continuous-time filter coefs double acoefs[6]; //Design lowpass filter here. Filter should be of the form // // 2 // b2s + b1s + b0 // --------------- // 2 // a2s + a1s + a0 // // where b2 and a2 are zero (1st order, just keeM_PIng them so the same BLT function can be used) // // Parameters are cutoff frequency in Hz b0 = 1; // design analog filter based on cutoff frequency b1 = 0; b2 = 0; a0 = 1; a1 = 1 / cutoff; a2 = 0; acoefs[0] = b0; acoefs[1] = b1; acoefs[2] = b2; // pack the analog coeffs into an array acoefs[3] = a0; acoefs[4] = a1; acoefs[5] = a2; // and apply the bilinear tranform bilinearTransform(acoefs, dcoefs, withFs); // inputs the 6 analog coeffs, output the 5 digital coeffs }
//------------------------------------------------------------------------------ void Reverb::designParametric(double* dcoefs, double center, double gain, double qval) // design parametric filter based on input center frequency, gain, Q and sampling rate { double b0, b1, b2, a0, a1, a2; //storage for continuous-time filter coefs double acoefs[6]; //Design parametric filter here. Filter should be of the form // // 2 // b2s + b1s + b0 // --------------- // 2 // a2s + a1s + a0 // // Parameters are center frequency in Hz, gain in dB, and Q. // TODO: design analog filter based on input gain, center frequency and Q // Remeber to handle the two cases: boost and cut! ///////////////START////////////////// float pi = 3.14159; float w = 2*pi*center; //boost if (gain > 0.0) { b2 = 1/(w*w); b1 = gain/(qval*w); b0 = 1; a2 = 1/(w*w); a1 = 1/(qval*w); a0 = 1; } //cut else { b2 = 1/(w*w); b1 = 1/(qval*w); b0 = 1; a2 = 1/(w*w); a1 = 1/(gain*qval*w); a0 = 1; } ////////////////END///////////////////// // pack the analog coeffs into an array and apply the bilinear tranform acoefs[0] = b0; acoefs[1] = b1; acoefs[2] = b2; acoefs[3] = a0; acoefs[4] = a1; acoefs[5] = a2; // inputs the 6 analog coeffs, output the 5 digital coeffs bilinearTransform(acoefs, dcoefs); }
//------------------------------------------------------------------------------ void designParametric(double* dcoefs, double center, double gain, double qval, double withFs) // design parametric filter based on input center frequency, gain, Q and sampling rate { double b0, b1, b2, a0, a1, a2; //storage for continuous-time filter coefs double acoefs[6]; //Design parametric filter here. Filter should be of the form // // 2 // b2s + b1s + b0 // --------------- // 2 // a2s + a1s + a0 // // Parameters are center frequency in Hz, gain in dB, and Q. // design analog filter based on input gain, center frequency and Q if (gain > 0.0) { // boost case b0 = 1; b1 = gain / (qval * center * 2 * M_PI); b2 = 1 / (center * center * 4 * M_PI * M_PI); a0 = 1; a1 = 1 / (qval * center * 2 * M_PI); a2 = 1 / (center * center * 4 * M_PI * M_PI); } else { // cut case b0 = 1; b1 = 1 / (qval * center * 2 * M_PI); b2 = 1 / (center * center * 4 * M_PI * M_PI); a0 = 1; a1 = 1 / (qval * gain * center * 2 * M_PI); a2 = 1 / (center * center * 4 * M_PI * M_PI); } acoefs[0] = b0; acoefs[1] = b1; acoefs[2] = b2; // pack the analog coeffs into an array acoefs[3] = a0; acoefs[4] = a1; acoefs[5] = a2; // and apply the bilinear tranform bilinearTransform(acoefs, dcoefs, withFs); // inputs the 6 analog coeffs, output the 5 digital coeffs }