From: Ron N. on 8 Dec 2006 19:43 Ron N. wrote: (repost, corrected for bw > fs/n) > jeff227 wrote: > > Has anyone come up with a "cookbook" for simple FIR filters similar to > > RBJ's IIR cookbook? The one on the musicdsp site is a bit wordy, and uses 2 sinc functions for bandpass filter, when 1 sinc function will do. Here's my recipe for a simple Q&D windowed sinc FIR filter generator in about a 8 lines of Basic, plus some comments: n = 256 : rem number of taps fs = 44100 : rem sample rate bw = 5000 : rem bandwidth, range 0 .. fs/2 and bw >= fs/n fc = 0 : rem center frequency, range 0 (lowpass) ... fs/2 (highpass) g = 1 : rem filter gain dim fir(n+1) for i = 0 to n-1 a = 2.0*pi*(i-n/2)*bw/fs : rem scale sinc width if a <> 0 then ys = sin(a)/a : else ys = 1 : rem calculate sinc ys = g * (2.0*bw/fs) * ys : rem correct gain yw = (0.54-0.46*cos(2.0*pi*i/n)) * ys : rem Hamming window yf = yw * cos(2.0*pi*(i-n/2)*fc/fs) : rem shift to fc fir(i) = yf : rem assign fir coeff. next i rem R. Nicholson's QDDS FIR filter generator cookbook recipe rem QDDS = Quick, Dirty, Dumb and Short rem version 0.1 - 2006-Dec-08 rem No warranties implied. Error checking, optimization, and quality rem assessment of the "results" is left as an exercise for the student. rem (consider this code Open Source under a BSD style license) .... IMHO. YMMV. -- Ron N. http://www.nicholson.com/rhn/
From: Ron N. on 8 Dec 2006 20:32 Ron N. wrote: > jeff227 wrote: > > Has anyone come up with a "cookbook" for simple FIR filters similar to > > RBJ's IIR cookbook? The one on the musicdsp site is a bit wordy, and uses 2 sinc functions for bandpass filter, when 1 sinc function will do. Here's my recipe for a simple Q&D windowed sinc FIR filter generator in about a 8 lines of Basic, plus some comments: n = 256 : rem number of taps fs = 44100 : rem sample rate bw = 5000 : rem bandwidth, range 0 .. fs/2 and bw < fs/n fc = 0 : rem center frequency, range 0 (lowpass) ... fs/2 (highpass) g = 1 : rem filter gain dim fir(n+1) for i = 0 to n-1 a = 2.0*pi*(i-n/2)*bw/fs : rem scale sinc width if a <> 0 then ys = sin(a)/a : else ys = 1 : rem calculate sinc ys = g * (2.0*bw/fs) * ys : rem correct gain yw = (0.54-0.46*cos(2.0*pi*i/n)) * ys : rem Hamming window yf = yw * cos(2.0*pi*(i-n/2)*fc/fs) : rem shift to fc fir(i) = yf : rem assign fir coeff. next i rem R. Nicholson's QDDS FIR filter generator cookbook recipe rem QDDS = Quick, Dirty, Dumb and Short rem version 0.1 - 2006-Dec-08 rem No warranties implied. Error checking, optimization, and quality rem assessment of the "results" is left as an exercise for the student. rem (consider this code Open Source under a BSD style license) .... IMHO. YMMV. -- Ron N. http://www.nicholson.com/rhn/
From: jeff227 on 10 Dec 2006 15:17 >Ron N. wrote: >Here's my recipe for a simple Q&D windowed sinc FIR filter generator >in about a 8 lines of Basic... > Thank you, Ron! That is a straight forward routine I was hoping to find! I will give it some study and a go. Thanks everyone for your feedback!
From: Ron N. on 11 Dec 2006 17:56 jeff227 wrote: > >Ron N. wrote: > > >Here's my recipe for a simple Q&D windowed sinc FIR filter generator > >in about a 8 lines of Basic... .... > Thank you, Ron! That is a straight forward routine I was hoping to find! > I will give it some study and a go. Note that there more degrees of freedom to explore even with this Q&D recipe. You should explore other window functions (von Hann, Blackman, etc.). Optimizations for certain types of systems and performance requirements might include doing an interpolated table look-up for the sinc and window function, which can be done in a few additional lines of code. IMHO. YMMV. -- Ron N. http://www.nicholson.com/rhn
From: jeff227 on 12 Dec 2006 10:18
>Ron N. >You should explore other window >functions (von Hann, Blackman, etc.). Ron, yes I understand there are window influences and other areas to tweak. Thank you for the heads up. Now, what I don't understand is your use of BW and Fc in the code above - it seems to have a different meaning than what I have seen elsewhere. Is "BW" the transition band or something else? In other Window FIRs I have have worked with the "cutoff" (-6dB) point has been at Fc + 1/2Tr. This doesn't seem to be the case with the above code. The cutoff point I observed in a gain plot is at Fc + Tr. So I'm confused as to what "Fc" and "BW" mean in this code. I was under the impression (probably wrong) that the rolloff response of a "window based" FIR was determined soley by the window selection and the number of taps. In your code there are 3 variables - BW, Fc and Window. Does this mean passband ripple is adjustable or ???? |