void BandFilter::setup(){ LOUDIA_DEBUG("BANDFILTER: Setting up..."); _filter.setChannelCount( _channelCount, false ); LOUDIA_DEBUG("BANDFILTER: Getting zpk"); // Get the lowpass z, p, k MatrixXC zeros, poles; Real gain; switch( _filterType ){ case CHEBYSHEVI: chebyshev1(_order, _passRipple, _channelCount, &zeros, &poles, &gain); break; case CHEBYSHEVII: chebyshev2(_order, _stopAttenuation, _channelCount, &zeros, &poles, &gain); break; case BUTTERWORTH: butterworth(_order, _channelCount, &zeros, &poles, &gain); break; case BESSEL: bessel(_order, _channelCount, &zeros, &poles, &gain); break; } LOUDIA_DEBUG("BANDFILTER: zeros:" << zeros ); LOUDIA_DEBUG("BANDFILTER: poles:" << poles ); LOUDIA_DEBUG("BANDFILTER: gain:" << gain ); // Convert zpk to ab coeffs MatrixXC a; MatrixXC b; zpkToCoeffs(zeros, poles, gain, &b, &a); LOUDIA_DEBUG("BANDFILTER: Calculated the coeffs"); // Since we cannot create matrices of Nx0 // we have created at least one Zero in 0 if ( zeros == MatrixXC::Zero(zeros.rows(), zeros.cols()) ){ // Now we must remove the last coefficient from b MatrixXC temp = b.block(0, 0, b.rows(), b.cols()-1); b = temp; } // Get the warped critical frequency Real fs = 2.0; Real warped = 2.0 * fs * tan( M_PI * _lowFrequency / fs ); Real warpedStop = 2.0 * fs * tan( M_PI * _highFrequency / fs ); Real warpedCenter = sqrt(warped * warpedStop); Real warpedBandwidth = warpedStop - warped; // Warpped coeffs MatrixXC wa; MatrixXC wb; LOUDIA_DEBUG("BANDFILTER: Create the band type filter from the analog prototype"); switch( _bandType ){ case LOWPASS: lowPassToLowPass(b, a, warped, &wb, &wa); break; case HIGHPASS: lowPassToHighPass(b, a, warped, &wb, &wa); break; case BANDPASS: lowPassToBandPass(b, a, warpedCenter, warpedBandwidth, &wb, &wa); break; case BANDSTOP: lowPassToBandStop(b, a, warpedCenter, warpedBandwidth, &wb, &wa); break; } LOUDIA_DEBUG("BANDFILTER: Calculated the low pass to band pass"); // Digital coeffs MatrixXR da; MatrixXR db; bilinear(wb, wa, fs, &db, &da); LOUDIA_DEBUG("BANDFILTER: setup the coeffs"); // Set the coefficients to the filter _filter.setA( da.transpose() ); _filter.setB( db.transpose() ); _filter.setup(); LOUDIA_DEBUG("BANDFILTER: Finished set up..."); }