Just playing around, I created arguably the simplest possible digital filter--it simply averages the current sample and the previous sample to produce each output sample. You might call this a moving average filter with averaging length = 2. I plotted the impulse and frequency responses with Matlab, and all looked as expected. Now I know from past experience that this filter is an FIR filter. While examining the frequency response, I noticed that it has infinite attenuation at Fs/2 (Nyquist) and ~3dB attenuation Fs/4, which makes sense intuitively. I also have at my disposal some equations and Matlab code to create arbitrary IIR filters (biquads or first order). So I decided to create a first-order IIR filter with a cut-off at exactly Fs/2 using my equations and compare it to the simple FIR. When I compared the two filters' responses, I noticed that they were identical! My IIR routine had generated exactly the same filter as the simple FIR I constructed (to within the numerical accuracy of Matlab). So how is it that my IIR filter routine can generate an FIR filter?
A little FIR/IIR puzzler
Started by ●January 7, 2005
Reply by ●January 7, 20052005-01-07
Jon Harris wrote: (FIR filter snip)> I also have at my disposal some equations and Matlab code to create arbitrary > IIR filters (biquads or first order). So I decided to create a first-order IIR > filter with a cut-off at exactly Fs/2 using my equations and compare it to the > simple FIR. When I compared the two filters' responses, I noticed that they > were identical! My IIR routine had generated exactly the same filter as the > simple FIR I constructed (to within the numerical accuracy of Matlab). So how > is it that my IIR filter routine can generate an FIR filter?Well, FIR filters are a subset of IIR filters. First order IIR is: y(n) = A*y(n-1) + B*x(n) It shouldn't be too hard to figure out A and B for a Fs/2 cutoff, and to expand it for y(n) in terms of x(n). -- glen
Reply by ●January 7, 20052005-01-07
Jon Harris wrote:> Just playing around, I created arguably the simplest possible digital filter--it > simply averages the current sample and the previous sample to produce each > output sample. You might call this a moving average filter with averaging > length = 2. I plotted the impulse and frequency responses with Matlab, and all > looked as expected. Now I know from past experience that this filter is an FIR > filter. > > While examining the frequency response, I noticed that it has infinite > attenuation at Fs/2 (Nyquist) and ~3dB attenuation Fs/4, which makes sense > intuitively. > > I also have at my disposal some equations and Matlab code to create arbitrary > IIR filters (biquads or first order). So I decided to create a first-order IIR > filter with a cut-off at exactly Fs/2 using my equations and compare it to the > simple FIR. When I compared the two filters' responses, I noticed that they > were identical! My IIR routine had generated exactly the same filter as the > simple FIR I constructed (to within the numerical accuracy of Matlab). So how > is it that my IIR filter routine can generate an FIR filter?I don't know yet, but it's worth noting that your "IIR" generator is probably really a recursive filter generator, and moving average filters have finite impulses responses whether recursive or not. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●January 7, 20052005-01-07
Jon Harris wrote:> Just playing around, I created arguably the simplest possible digital filter--it > simply averages the current sample and the previous sample to produce each > output sample. You might call this a moving average filter with averaging > length = 2. I plotted the impulse and frequency responses with Matlab, and all > looked as expected. Now I know from past experience that this filter is an FIR > filter. > > While examining the frequency response, I noticed that it has infinite > attenuation at Fs/2 (Nyquist) and ~3dB attenuation Fs/4, which makes sense > intuitively. > > I also have at my disposal some equations and Matlab code to create arbitrary > IIR filters (biquads or first order). So I decided to create a first-order IIR > filter with a cut-off at exactly Fs/2 using my equations and compare it to the > simple FIR. When I compared the two filters' responses, I noticed that they > were identical! My IIR routine had generated exactly the same filter as the > simple FIR I constructed (to within the numerical accuracy of Matlab). So how > is it that my IIR filter routine can generate an FIR filter? > >Did you look at the IIR filter that Matlab coughed up? -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Reply by ●January 7, 20052005-01-07
"glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message news:crn4gd$kdm$1@gnus01.u.washington.edu...> > Jon Harris wrote: > > (FIR filter snip) > > > I also have at my disposal some equations and Matlab code to createarbitrary> > IIR filters (biquads or first order). So I decided to create a first-orderIIR> > filter with a cut-off at exactly Fs/2 using my equations and compare it tothe> > simple FIR. When I compared the two filters' responses, I noticed that they > > were identical! My IIR routine had generated exactly the same filter as the > > simple FIR I constructed (to within the numerical accuracy of Matlab). Sohow> > is it that my IIR filter routine can generate an FIR filter? > > Well, FIR filters are a subset of IIR filters.Yes, I think you hit the nail on the head with that comment. In my way of thinking, they were always mutually exclusive distinct types. The names even imply as much--a filter is either in one camp or the other. The literature often treats them separately, they have different design methodologies, and different typical uses. But obviously, since an IIR filter can have both poles and zeros, whereas an FIR has only zeros, it makes sense that FIR is a subset of IIR. Or maybe it would be clearer to use different terminology and refer to them as "all-zero" and "pole/zero" filters. You could then say "all-zero filters are a subset of pole/zero fitlers" and it is quite obvious when worded like this.> First order IIR is: y(n) = A*y(n-1) + B*x(n)I think this should be: y(n) = A*y(n-1) + B*x(n) + C*x(n-1) Or using Matlab's notation: a1*y(n) = b1*x(n) + b2*x(n-1) - a2*y(n-1)> It shouldn't be too hard to figure out A and B for a Fs/2 cutoff, > and to expand it for y(n) in terms of x(n).Using the Matlab notation, a1 = 1, b1 = 0.5, b2 = 0.5, and a2 = 0. It's the fact that a2 = 0 that makes the filter effectively FIR. Interestingly, if I change the cut-off frequency by a miniscule amount, say to 0.24999*Fs (instead of 0.25*Fs), then the a2 term becomes non-zero (though still very small). -Jon
Reply by ●January 7, 20052005-01-07
Jon Harris wrote:> "glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message > news:crn4gd$kdm$1@gnus01.u.washington.edu... > >>Jon Harris wrote: >>snip>> >>Well, FIR filters are a subset of IIR filters. > > > Yes, I think you hit the nail on the head with that comment. In my way of > thinking, they were always mutually exclusive distinct types. The names even > imply as much--a filter is either in one camp or the other. The literature > often treats them separately, they have different design methodologies, and > different typical uses. But obviously, since an IIR filter can have both poles > and zeros, whereas an FIR has only zeros, it makes sense that FIR is a subset of > IIR. Or maybe it would be clearer to use different terminology and refer to > them as "all-zero" and "pole/zero" filters. You could then say "all-zero > filters are a subset of pole/zero fitlers" and it is quite obvious when worded > like this. > >snip again> -Jon > >But in the z domain FIR filters _do_ have poles -- they must have as many poles at zero as they have zeros; otherwise they're predicting the future -- and calling them "no-nonzero-pole" filters gets kinda awkward. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Reply by ●January 7, 20052005-01-07
Jon Harris wrote: (I wrote)>>First order IIR is: y(n) = A*y(n-1) + B*x(n)> I think this should be: y(n) = A*y(n-1) + B*x(n) + C*x(n-1)I think that is right. The previous one is a popular special case. Assuming one wants the best filter for the resources used, it may be a useful special case. If you set y(n) to zero, x(n) = -x(n-1), you get B = C. For unity gain at f=0, A=0, B=C=0.5 (snip) Interestingly, if I> change the cut-off frequency by a miniscule amount, say to 0.24999*Fs (instead > of 0.25*Fs), then the a2 term becomes non-zero (though still very small).You mean 0.49998 instead? They won't exactly cancel, so there will be some left for A. -- glen
Reply by ●January 7, 20052005-01-07
in article 348maaF464m2bU1@individual.net, Jon Harris at goldentully@hotmail.com wrote on 01/07/2005 19:03:> "glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message > news:crn4gd$kdm$1@gnus01.u.washington.edu......>> Well, FIR filters are a subset of IIR filters. > > Yes, I think you hit the nail on the head with that comment.here's the blow that drives the nail into the pine: "Truncated IIR Filters" Julius Smith is the person that coined the term. strictly speaking, TIIR filters are FIR. but they are implemented with recursion. you can google it. an N-tap moving average filter can be implemented two ways. one is the straight-forward direct FIR implementation with all the taps coefs = 1/N . the other is with a discrete-time integrator, a delay line (of N samples), a subtractor, and a 1/N gain. the latter has a pole at z=1 (because of the integrator) but there is a zero that kills the pole so the pole/zero constellation is the same as with the non-recursive implementation. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●January 7, 20052005-01-07
"glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message news:crnb2m$pip$1@gnus01.u.washington.edu...> > Jon Harris wrote: > > (I wrote) > > >>First order IIR is: y(n) = A*y(n-1) + B*x(n) > > > I think this should be: y(n) = A*y(n-1) + B*x(n) + C*x(n-1) > > I think that is right. The previous one is a popular special > case. Assuming one wants the best filter for the resources > used, it may be a useful special case.Agreed. I often use this simplification for quick and dirty LP filtering. I usually call it a lag filter. The response is about the same as the "full-blown" first order filter except very near Nyquist where it levels off rather than going all the way to zero (infinite attenuation) at Fs/2. The saving in execution time plus the ability to only store one filter coefficient (if arranged properly) are big plusses where you need a lot of simple LP filters.> If you set y(n) to zero, x(n) = -x(n-1), you get B = C. > For unity gain at f=0, A=0, B=C=0.5 > > (snip) > > Interestingly, if I > > change the cut-off frequency by a miniscule amount, say to 0.24999*Fs(instead> > of 0.25*Fs), then the a2 term becomes non-zero (though still very small). > > You mean 0.49998 instead? > > They won't exactly cancel, so there will be some left for A.Right. Fs/4 is the special case where everything cancels exactly.
Reply by ●January 7, 20052005-01-07
"robert bristow-johnson" <rbj@audioimagination.com> wrote in message news:BE049A2C.3AD7%rbj@audioimagination.com...> > an N-tap moving average filter can be implemented two ways. one is the > straight-forward direct FIR implementation with all the taps coefs = 1/N . > the other is with a discrete-time integrator, a delay line (of N samples),a> subtractor, and a 1/N gain. the latter has a pole at z=1 (because of the > integrator) but there is a zero that kills the pole so the pole/zero > constellation is the same as with the non-recursive implementation. > >Indeed, also known as a CIC (cascaded integrator comb) or Hogenauer filters when used in multirate DSP. Syms.






