[comp.dsp] Digital Filters

optadm7@watserv1.waterloo.edu (J.Cassidy - Optometry) (11/15/90)

I have a really interesting application for digital filtering
using a DSP chip, but I am having some difficulty understanding
the derrivations for a filter's tap coefficients.

I understand that the expression of a FIR filter is:

b0*a[n] + b1*a[n-1] + b2*a[n-2] + etc...

where b[0] to b[n] are the tap coefficients and assume they
are what determine the performance of the filter.  But how
to I generate b[n], given that I have the filter parameters
such as filter type (butterworth/bandpass), lowpass cutoff
frequency, highpass cutoff frequency, etc.

I have been searching for this algorithm/program for a while
now.  Most application notes that I see show the filter 
algorithm and the values of b[n], but never show how they
derrived the values of b[n], given the filter's parameters.

Any help would be greatly appreciated!

Jim C.

=========================================================================
Jim Cassidy                           optadm7@watserv1.waterloo.{edu,cdn}
University of Waterloo                optadm7@watserv1.uwaterloo.ca
200 University Ave.                   VE3RTS
Waterloo, Ontario, Canada N2L 3G1     (519) 885-1211 ext. 6240

maverick@fir.Berkeley.EDU (Vance Maverick) (11/16/90)

> 
> [in effect] How do I design an FIR filter?
> 

This is an incredibly general question, the answers to which fill books.
 So the first answer is, look at Jackson, or Oppenheim and Schafer, or
one of the other standard textbooks.  Meanwhile, though, there's a
fairly intuitive technique (if you believe in the Fourier transform)
which allows you to design an FIR filter from a spectral specification.

(1) Pick a filter length M.  There are several considerations:
	-- longer filter -> better frequency resolution
	-- longer filter -> longer compute time, higher group delay.

(2) Fill in the magnitude frequency response you want.  This needs to be
even (i.e. H(k) = H(M-k)) if you want real filter coefficients.

(3) Take the inverse DFT of this frequency response.  (For small enough
M, the FFT isn't a big saving; just do the dumb DFT, using a real
instead of a complex sinusoid, since you know the result will be real
anyway.) Voila', the coefficients.

(4) If you want to be slick, rotate the array to put small coefficients
at the end.

jbuck@galileo.berkeley.edu (Joe Buck) (11/16/90)

In article <1990Nov15.121559.11290@watserv1.waterloo.edu>, optadm7@watserv1.waterloo.edu (J.Cassidy - Optometry) writes:
> I have a really interesting application for digital filtering
> using a DSP chip, but I am having some difficulty understanding
> the derrivations for a filter's tap coefficients.

> I understand that the expression of a FIR filter is:

> b0*a[n] + b1*a[n-1] + b2*a[n-2] + etc...

> where b[0] to b[n] are the tap coefficients and assume they
> are what determine the performance of the filter.  But how
> to I generate b[n], given that I have the filter parameters
> such as filter type (butterworth/bandpass), lowpass cutoff
> frequency, highpass cutoff frequency, etc.

A Butterworth filter is an IIR filter, so you can't represent it
using an IIR filter.  There are several design techniques for FIR
filters given a specification of cutoff frequencies and other
parameters; the best (in most cases) is the Parks-McClellan
algorithm for designing optimal FIR filters.

Find the book "Programs for digital signal processing" (I think
that's the title) published by IEEE Press (I think you can also
get a tape) for many DSP programs written in spaghetti Fortran.

--
Joe Buck
jbuck@galileo.berkeley.edu	 {uunet,ucbvax}!galileo.berkeley.edu!jbuck	

jimb@hpmcaa.mcm.hp.com (Jim Belesiu) (11/16/90)

Check out "Programs for Digital Signal Processing" by the IEEE press at your
university library.  It contains some of the classical methods (and FORTRAN 
source code) for designing FIR filters.

Another source for designing FIR filters is the classic "Digital Signal
Processing" by Oppenheim and Schafer.

A more current source is "Digital Filter Design" by Parks and Burrus.  The 
appendix contains FORTRAN source code for a couple of FIR filter designs.

But the easiest method to generate FIR filters is to use a commercial package.
MATLAB with the signal processing toolbook is a good one that comes to mind
(but certainly not the only one!).  

mcmahan@netcom.UUCP (Dave Mc Mahan) (11/16/90)

 In a previous article, optadm7@watserv1.waterloo.edu (J.Cassidy - Optometry) writes:
>I have a really interesting application for digital filtering
>using a DSP chip, but I am having some difficulty understanding
>the derrivations for a filter's tap coefficients.
>
>I understand that the expression of a FIR filter is:
>
>b0*a[n] + b1*a[n-1] + b2*a[n-2] + etc...
>
>where b[0] to b[n] are the tap coefficients and assume they
>are what determine the performance of the filter.  But how
>to I generate b[n], given that I have the filter parameters
>such as filter type (butterworth/bandpass), lowpass cutoff
>frequency, highpass cutoff frequency, etc.
>
>I have been searching for this algorithm/program for a while
>now.  Most application notes that I see show the filter 
>algorithm and the values of b[n], but never show how they
>derrived the values of b[n], given the filter's parameters.

You can simulate a butterworth filter design with an FIR filter, but it
is really an IIR filter type and is best suited for that type of filter.

To get the desired filter shape, I use MatLab.  I wrote a simple function
that does a inverse-DFT because MatLab didn't have one and the inverse-FFT
it comes with produces complex components that I would have to process anyway.
I then decide about how many taps I think it should take to do the filter I
want and make an amplitude response for that filter.  Since all the filters
I design need to have constant group delay (linear phase response) I don't
need to worry about taking the phase into account.  The IDFT routine I wrote
just assumes that I want linear phase.  I then make a vector with the desired
amplitude of the frequency spectrum I want, usually using a value of 1 for
passband frequencies and 0 for stop band frequencies.  I then use the IDFT
function to convert the frequency domain response to the time domain impulse
response that are the filter tap weights.  Do to the way the IDFT function
works, I have to swap the left half and right halves of the resulting time
domain response to obtain the tap weights in proper order.  It's not the
totally optimal design package and method, but it works for me!


>Jim C.
>Jim Cassidy                           optadm7@watserv1.waterloo.{edu,cdn}

   -dave

-- 
Dave McMahan                            mcmahan@netcom.uucp
					{apple,amdahl,claris}!netcom!mcmahan

bryanh@hplsla.HP.COM (Bryan Hoog) (11/17/90)

>
>(3) Take the inverse DFT of this frequency response.  (For small enough
>M, the FFT isn't a big saving; just do the dumb DFT, using a real
>instead of a complex sinusoid, since you know the result will be real
>anyway.) Voila', the coefficients.
>

   In a college DSP class (YEARS ago!), we used this method, and, then
 (I think; this is where my memory gets hazy) we weighted the resulting
 coefficients with a Hamming window.  I remember the teacher saying
 something like "A Hamming window usually works best", but couldn't explain
 what was so "magic" about the Hamming window for FIR filter design.

   -Bryan