DSPRelated.com
Forums

FIR Cookbook?

Started by jeff227 December 6, 2006
Has anyone come up with a "cookbook" for simple FIR filters similar to
RBJ's IIR cookbook?

I am looking for audio filters (i.e., mild rolloff, fast compute)  using
relatively short FIRs (50 coeffs max).  Reason for FIR is that I need
linear phase.  Reason for cookbook is that I need to calculate the
coefficients as part of the routine (so the filter will work at different
sample rates).  Window-based FIRs would probably be most efficient for
audio purposes.

I have started compiling bits of code for Window-based FIRs but it would
nice not to re-invent the wheel if a "cookbook" already exists!

Thank you.


jeff227 skrev:
> Has anyone come up with a "cookbook" for simple FIR filters similar to > RBJ's IIR cookbook? > > I am looking for audio filters (i.e., mild rolloff, fast compute) using > relatively short FIRs (50 coeffs max). Reason for FIR is that I need > linear phase. Reason for cookbook is that I need to calculate the > coefficients as part of the routine (so the filter will work at different > sample rates). Window-based FIRs would probably be most efficient for > audio purposes. > > I have started compiling bits of code for Window-based FIRs but it would > nice not to re-invent the wheel if a "cookbook" already exists!
Cookbooks on FIR filter window designs are all over the place; get an intermediate-level text on DSP (Oppenheim, Schafer & Buck or Proakis & Manolakis). Now, your requirements for the FIR might not go very well with window design. You might have to llok into the Parks-McClellan algorithm to get filters that meet all your specs. Rune
Rune Allnor wrote:
> jeff227 skrev: > > Has anyone come up with a "cookbook" for simple FIR filters similar to > > RBJ's IIR cookbook? > > > > I am looking for audio filters (i.e., mild rolloff, fast compute) using > > relatively short FIRs (50 coeffs max). Reason for FIR is that I need > > linear phase. Reason for cookbook is that I need to calculate the > > coefficients as part of the routine (so the filter will work at different > > sample rates). Window-based FIRs would probably be most efficient for > > audio purposes. > > > > I have started compiling bits of code for Window-based FIRs but it would > > nice not to re-invent the wheel if a "cookbook" already exists! > > Cookbooks on FIR filter window designs are all over the place; get an > intermediate-level text on DSP (Oppenheim, Schafer & Buck or > Proakis & Manolakis). > > Now, your requirements for the FIR might not go very well with > window design. You might have to llok into the Parks-McClellan > algorithm to get filters that meet all your specs.
The IIR cookbook filters can be calculated quickly with only a few common transcendental function evaluations or table lookups needed. remez is hardly on the same order if filter generation time is a more important constraint than filter passband/stopband quality. Just off the top of my head, how about a windowed sinc with a pre-calculated window. Change the width of the sinc to change the passband width, Spiral the phase of the sinc to change the center frequency. Seems to require on the order of only a couple table lookups and a few MACs per tap, for an arbitrary (3 degree of freedom) filter with it's quality limited by the window shape. What would be the next better recipe given the same computational time constraints? Is there a recipe that could generate a FIR filter with even less computation? IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
On 2006-12-06, jeff227 <rocksonics@earthlink.net> wrote:
> I have started compiling bits of code for Window-based FIRs but it would > nice not to re-invent the wheel if a "cookbook" already exists!
The ultimate cookbook is Matlab, or the free clone Octave (with the DSP stuff from Octave-forge). You still want the book for the principles, but there's no need to re-implement the design code. -- Ben Jackson AD7GD <ben@ben.com> http://www.ben.com/
Also, I think is something like a Handbook of Filter Design or
something like that by Sanjit K Mitra.

Ben Jackson wrote:
> On 2006-12-06, jeff227 <rocksonics@earthlink.net> wrote: > > I have started compiling bits of code for Window-based FIRs but it would > > nice not to re-invent the wheel if a "cookbook" already exists! > > The ultimate cookbook is Matlab, or the free clone Octave (with the DSP > stuff from Octave-forge). You still want the book for the principles, > but there's no need to re-implement the design code. > > -- > Ben Jackson AD7GD > <ben@ben.com> > http://www.ben.com/
Ben Jackson wrote:
> On 2006-12-06, jeff227 <rocksonics@earthlink.net> wrote: > > I have started compiling bits of code for Window-based FIRs but it would > > nice not to re-invent the wheel if a "cookbook" already exists! > > The ultimate cookbook is Matlab, or the free clone Octave (with the DSP > stuff from Octave-forge). You still want the book for the principles, > but there's no need to re-implement the design code.
How does this cookbook allow him to create FIR filters on the fly as part of a subroutine? Can Matlab generate C code which can then generate parameterized FIR filters? Whereas RBJ's cookbook algorithms can easily be used to quickly generate IIR coefficients from within small subroutines written in C, Perl, or even Basic.
>How does this cookbook allow him to create FIR filters on >the fly as part of a subroutine? Can Matlab generate C code >which can then generate parameterized FIR filters?
Yes, exactly. Maybe I need to re-state my question. I am hoping to find a C routine that will calculate FIR coefficients at run time. "Window" methods seem to be the best for my needs (simple audio LP/HP filters, relatively wide transition bands, modest stop band atten, etc.) Nothing fancy but fast to compute. I was hoping to find something like RBJ's "Audio EQ" cookbook but for audio FIR applications.
jeff227 wrote:
> >How does this cookbook allow him to create FIR filters on > >the fly as part of a subroutine? Can Matlab generate C code > >which can then generate parameterized FIR filters? > > > Yes, exactly. Maybe I need to re-state my question. > > I am hoping to find a C routine that will calculate FIR coefficients at > run time. "Window" methods seem to be the best for my needs (simple audio > LP/HP filters, relatively wide transition bands, modest stop band atten, > etc.) Nothing fancy but fast to compute.
well, pick on a certain window. Kaiser might be best, but it's sorta hard to generate. maybe some even-symmetry polynomial (with only even power terms) that approximate this Kaiser window you like: N w(x) = SUM a[n] x^(2n) for |x| <= 1 n=0 = 0 for |x| > 1 you'll need help with MATLAB (polyfit) or something to determine the a[n] coefficients and to check the spectrum of your window (how small the outside lobes are and how narrow the main lobe is which defines how sharp is the transition regions). that window definition gets fixed and the coefficients are simply constants that are fixed and defined in your cookbook. then you, or your user, draws out or specifies by whatever means whatever frequency response they want. put that into an iFFT (with the reflected negative frequencies components complex conjugated and placed where they belong in upper half) with a lot of points - many times more than the FIR size you plan to use. after running the iFFT you will have an impulse response that is longer than you want. use your predefined window (which is defined as a polynomial of x^2) scaled to the non-zero length you want and apply it to your impulse response. if you want to see how bad it is, FFT back and look at the frequency response. your user interface will need the means to draw or somehow specify the target frequency response and you need an FFT handy as well as a good window definition in some form that you can evaluate. r b-j
robert bristow-johnson wrote:
> jeff227 wrote: > > >How does this cookbook allow him to create FIR filters on > > >the fly as part of a subroutine? Can Matlab generate C code > > >which can then generate parameterized FIR filters? > > > > > > Yes, exactly. Maybe I need to re-state my question. > > > > I am hoping to find a C routine that will calculate FIR coefficients at > > run time. "Window" methods seem to be the best for my needs (simple audio > > LP/HP filters, relatively wide transition bands, modest stop band atten, > > etc.) Nothing fancy but fast to compute. > > well, pick on a certain window. Kaiser might be best, but it's sorta > hard to generate. maybe some even-symmetry polynomial (with only even > power terms) that approximate this Kaiser window you like: > > N > w(x) = SUM a[n] x^(2n) for |x| <= 1 > n=0 > > = 0 for |x| > 1 > > you'll need help with MATLAB (polyfit) or something to determine the > a[n] coefficients and to check the spectrum of your window (how small > the outside lobes are and how narrow the main lobe is which defines how > sharp is the transition regions). that window definition gets fixed > and the coefficients are simply constants that are fixed and defined in > your cookbook. then you, or your user, draws out or specifies by > whatever means whatever frequency response they want. put that into an > iFFT (with the reflected negative frequencies components complex > conjugated and placed where they belong in upper half) with a lot of > points - many times more than the FIR size you plan to use. after > running the iFFT you will have an impulse response that is longer than > you want. use your predefined window (which is defined as a polynomial > of x^2) scaled to the non-zero length you want and apply it to your > impulse response. if you want to see how bad it is, FFT back and look > at the frequency response. your user interface will need the means to > draw or somehow specify the target frequency response and you need an > FFT handy as well as a good window definition in some form that you can > evaluate.
Can't one just precalculate one filter and shift it about? (similar to how your IIR cookbook picks one basic pole/zero geometry and just scales their locations for the filters few degrees of freedom...) I would start with a Hamming windowed (trig table lookup) sinc (pre-fft'd rectangle), and see it that fits his needs well enough (before getting out a pile driver when a boot heel would have sufficed). IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
On 2006-12-06, Ron N. <rhnlogic@yahoo.com> wrote:
> Ben Jackson wrote: >> >> The ultimate cookbook is Matlab, or the free clone Octave (with the DSP >> stuff from Octave-forge). > > How does this cookbook allow him to create FIR filters on > the fly as part of a subroutine? Can Matlab generate C code > which can then generate parameterized FIR filters?
Actually, Matlab can generate Verilog and VHDL to implement filters, but it will not generate code to generate filters, afaik. :) At least the Octave-forge source would be a good reference. -- Ben Jackson AD7GD <ben@ben.com> http://www.ben.com/