From: Ron N. on
Ben Jackson wrote:
> On 2006-12-06, jeff227 <rocksonics(a)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.

From: jeff227 on
>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.
From: robert bristow-johnson on
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

From: Ron N. on
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

From: Ben Jackson on
On 2006-12-06, Ron N. <rhnlogic(a)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(a)ben.com>
http://www.ben.com/