2
$\begingroup$

This question already has an answer here:

I'm working on a DSP-based senior project, and we'd like to allow the user to provide a 20-20kHz cutoff specification for IIR/FIR high and low-pass filters on the fly. This would be a simple problem on a desktop, but we're working on a TI 5535 DSP chip. So we're looking for a C library for generating coefficients. We're currently looking at adapting this code from C++ to C and cutting out the input stuff, but if there's a better solution we'd love to hear it.

For IIR - Any of Butterworth / Bessel / Chebyshev would work. Whatever has the fastest runtime / lowest complexity is optimal. Accuracy is not important (educational product, so as long as the output changes when they change the cutoff, we're fine).

For FIR - not really sure what to do here. Raised cosine for the lowpass, ?? for the highpass.

We're sampling stereo audio at 44.1kHz/channel. I'm unsure what other parameters we can set constant to make calculations simpler. The number of poles can be held constant, and the rolloff and other specifications aren't terribly important to us.

The question - what are some existing methods or C libraries for generating filter coefficients from a cutoff frequency in the auditory range?

$\endgroup$

marked as duplicate by Paul R, Peter K. Nov 23 '13 at 19:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4
$\begingroup$

A computationally cheap way to generate quick & dirty FIR filter coefficients is to evaluate a windowed Sinc function. Any rectangle in the frequency domain (low/high/bandpass) has a Sinc impulse response in the time domain, which can be windowed to a length roughly proportionally inverse in size to the desired width of the transition bands, and then sampled for some FIR coefficients.

About a dozen lines of BASIC pseudo code on my web page to do this should be trivial to convert to plain C : http://www.nicholson.com/rhn/dsp.html#2

$\endgroup$
1
$\begingroup$

I am not familiar with the TI 5535, so I am not sure how cheap your definition of cheap is :-)

It seems however that a Kaiser filter would be considered reasonably cheap, especially if you separate the window code from the ideal impulse code. In other words, if your tap count remains the same, and you don't change the side lobe levels, then the window values can be pre-computed and stored. Then only the ideal low pass, band pass, high pass, or notch impulse values needs to be computed.

This is the code for a low pass impulse. The high pass and other code is similar.

double LPF_Impulse(int m, int M, double Omega)
{
 double Arg;
 Arg = (double)m - (double)(M-1) / 2.0;
 return( Omega * Sinc(Omega * Arg * M_PI) );
}

This is just textbook code. The rest of it is here: http://www.iowahills.com/A7ExampleCodePage.html

There is also Bilinear Transform code here to compute IIR coefficients from the normalized 2nd order coefficients of H(s).

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.