Design Article
Synthesize FIR filters using high-school algebra (Part 2)
Kendall Castor-Perry, Cypress Semiconductor
3/19/2012 11:09 AM EDT
Now for a real example. Let's say that I want very high attenuation between around 49 Hz and 51 Hz, again between 59 Hz and 61 Hz (i.e. the system must be able to reject both commonly-used AC line frequencies without change of coefficients or sample rate), and finally also between 98 Hz and 102 Hz. I'll specify 220 Hz as the sample rate to ensure that the 2nd harmonic of 60 Hz aliases round and falls right into that same hole that the 50 Hz second harmonic does (homework, if you can't see why that happens).
So, what happens if I just build a filter that has nulls at these six frequencies? It's simple to make up a spreadsheet that calculates the z coefficient shown in equation [8] for a set of frequencies, and multiplies them up into a single polynomial. The six frequencies create six quadratic factors, shown in Table 1.

When multiplied together (equation [9]), these six quadratic factors produce a twelfthorder polynomial (equation [10]).

The frequency response of this filter is shown in Figure 3, straight out of Excel. For the intended application, it's actually already a pretty good filter, “straight out of the box”, and it has no wasted coefficients at all!

Let's take a closer look at the region around 50 Hz and 60 Hz in LTSpice. Yep, those nulls are indeed where we wanted them to be – see Figure 4. Now, it's easy to play around with this approach using the spreadsheet, adding and moving nulls until you get exactly what you want.
Not all combinations of null frequencies will necessarily produce a response that you're happy with first time round. You'll find that as you try to push the stopband of a lowpass filter well below fs/4, for example, you'll need to add extra nulls above this frequency to 'pin the stopband down'. It's an empirical way to proceed, for sure – but you certainly get a feeling for what's going on with these nulls.

If you want a filter with an even number of taps, you can multiply in an extra linear term of (z+1), which has the effect of putting a null at fs/2 (which gives us some extra stopband rejection). That's something we can deduce from one of those earlier special cases; if a function Q(z)=(z+1)*(z+1) has a null at fs/2, so must its square root.
Next: Flattening the passband


Frank Eory
4/3/2012 6:04 PM EDT
Thanks for this great article Kendall. I see now why you bothered factoring -- it does provide good insight into which coefficients create which zeros.
Sign in to Reply