A little FIR/IIR puzzler
CASTalk.com Forum Index CASTalk.com
Discussion of DSP, FPGA, storage and embedded system.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web castalk.com
A little FIR/IIR puzzler
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> DSP
Author Message
Jon Harris
Guest





Posted: Sat Jan 08, 2005 3:44 am    Post subject: A little FIR/IIR puzzler Reply with quote

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?
Back to top
glen herrmannsfeldt
Guest





Posted: Sat Jan 08, 2005 4:03 am    Post subject: Re: A little FIR/IIR puzzler Reply with quote

Jon Harris wrote:

(FIR filter snip)

Quote:
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
Back to top
Jerry Avins
Guest





Posted: Sat Jan 08, 2005 4:07 am    Post subject: Re: A little FIR/IIR puzzler Reply with quote

Jon Harris wrote:

Quote:
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.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Back to top
Tim Wescott
Guest





Posted: Sat Jan 08, 2005 5:02 am    Post subject: Re: A little FIR/IIR puzzler Reply with quote

Jon Harris wrote:

Quote:
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
Back to top
Jon Harris
Guest





Posted: Sat Jan 08, 2005 5:03 am    Post subject: Re: A little FIR/IIR puzzler Reply with quote

"glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message
news:crn4gd$kdm$1@gnus01.u.washington.edu...
Quote:

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.

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.

Quote:
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)

Quote:
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
Back to top
Tim Wescott
Guest





Posted: Sat Jan 08, 2005 5:07 am    Post subject: Re: A little FIR/IIR puzzler Reply with quote

Jon Harris wrote:

Quote:
"glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message
news:crn4gd$kdm$1@gnus01.u.washington.edu...

Jon Harris wrote:

snip


Quote:

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


Quote:
-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
Back to top
glen herrmannsfeldt
Guest





Posted: Sat Jan 08, 2005 5:55 am    Post subject: Re: A little FIR/IIR puzzler Reply with quote

Jon Harris wrote:


(I wrote)

Quote:
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
Quote:
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
Back to top
robert bristow-johnson
Guest





Posted: Sat Jan 08, 2005 5:57 am    Post subject: Re: A little FIR/IIR puzzler Reply with quote

in article 348maaF464m2bU1@individual.net, Jon Harris at
goldentully@hotmail.com wrote on 01/07/2005 19:03:

Quote:
"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."
Back to top
Jon Harris
Guest





Posted: Sat Jan 08, 2005 6:42 am    Post subject: Re: A little FIR/IIR puzzler Reply with quote

"glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message
news:crnb2m$pip$1@gnus01.u.washington.edu...
Quote:

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.

Quote:
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.
Back to top
Symon
Guest





Posted: Sat Jan 08, 2005 7:17 am    Post subject: Re: A little FIR/IIR puzzler Reply with quote

"robert bristow-johnson" <rbj@audioimagination.com> wrote in message
news:BE049A2C.3AD7%rbj@audioimagination.com...
Quote:

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.
Back to top
Randy Yates
Guest





Posted: Sat Jan 08, 2005 7:59 am    Post subject: Re: A little FIR/IIR puzzler Reply with quote

"Jon Harris" <goldentully@hotmail.com> writes:

Quote:
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'll take a stab, Jon.


The boxcar moving average filter is given by.

y[n] = (1/N) * sum_{j=0}^{N-1} x[n-j].

However, there is a recursive way to compute the filter as well:

y[n] = y[n-1] + (1/N) * (x[n] - x[n-N]).

This can be easily derived by reexpressing the non-recursive form as

y[n-1] = (1/N) * (x[n - 1] + x[n - 2] + ... + x[n - N])

and

y[n] = (1/N) * (x[n - 0] + x[n - 1] + x[n - 2] + ... + x[n-N+1])

Then

y[n] - y[n - 1] = (1/N) * (x[n - 0] - x[n - N])

and we solve for y[n]:

y[n] = y[n - 1] + (1/N) * (x[n - 0] - x[n - N])

Thus here in your case N = 2 and thus

y[n] = y[n - 1] + (1/2) * (x[n] - x[n - 2])

If we take the z-transform and solve for the transfer function we get

Y(z)/X(z) = (1/2) * (z^2 - 1) / [z * (z - 1)].

Is this the IIR your matlab routine came up with?
--
% Randy Yates % "Bird, on the wing,
%% Fuquay-Varina, NC % goes floating by
%%% 919-577-9882 % but there's a teardrop in his eye..."
%%%% <yates@ieee.org> % 'One Summer Dream', *Face The Music*, ELO
http://home.earthlink.net/~yatescr
Back to top
Rick Lyons
Guest





Posted: Sat Jan 08, 2005 7:20 pm    Post subject: Re: A little FIR/IIR puzzler Reply with quote

On Fri, 07 Jan 2005 19:57:32 -0500, robert bristow-johnson
<rbj@audioimagination.com> wrote:

Quote:
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.


Hi

your post piqued my interest again and I found a
1997 paper by Wang & Smith describing what they
call their "Truncated IIR Filters". See:
http://ccrma.stanford.edu/~jos/pdf/tiir.pdf

It looks to me, after reading a few pages, that their
Truncated IIR Filters are very similar to filters that
are called "Frequency Sampling Filters" (FSF).
(I say that because both filter types are
implemented with a comb filter followed by parallel
banks of biquads.)

FSFs have been around for roughly forty years!

FSFs are recursive FIR linear-phase filters.
I cover them, in some detail, in Section 7.1 of
the 2nd Edition of my book. As it turns out, for
some applications, FSFs are more computationally
efficient than Parks-McClellan-designed FIR filters.

For that reason I've been "preaching the gospel" of
these filters.
I made a presentation on FSFs at the COMP.DSP Conference
at Al Clark's place, and at the 2004 GSPx Conference in
San Jose CA last September.

I think every DSP guy should know that FSFs exist and
learn in what situations they may be useful.

[-Rick-]
Back to top
robert bristow-johnson
Guest





Posted: Sat Jan 08, 2005 11:07 pm    Post subject: Re: A little FIR/IIR puzzler Reply with quote

in article 41dfe318.47111171@news.sf.sbcglobal.net, Rick Lyons at
r.lyons@_BOGUS_ieee.org wrote on 01/08/2005 09:20:

Quote:
On Fri, 07 Jan 2005 19:57:32 -0500, robert bristow-johnson
rbj@audioimagination.com> wrote:

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.

your post piqued my interest again and I found a
1997 paper by Wang & Smith describing what they
call their "Truncated IIR Filters". See:
http://ccrma.stanford.edu/~jos/pdf/tiir.pdf

i remember when Avery Wang gave me a copy of that at an IEEE Mohonk back
then.

Quote:
It looks to me, after reading a few pages, that their
Truncated IIR Filters are very similar to filters that
are called "Frequency Sampling Filters" (FSF).
(I say that because both filter types are
implemented with a comb filter followed by parallel
banks of biquads.)

even though there is certainly conceptual overlap with FSF, i think that the
design philosophy is a bit different. the design philosophy that Smith and
Wang do is somewhat similar to that of

S. R. Powell & P. M. Chau, "A Technique for Realizing Linear Phase IIR
Filters", IEEE ASSP-39, no.11, pp. 2425-2435, (Nov. 1991).

S. A. Azizi, "Performance Analysis of Linear Phase Audio Filters Based
on the Zero Phase Filtering Concept", 103rd AES Convention (Sept. 1997),
AES preprint no. 4535.

which is similar to that of running the FILTFILT utility. you design an IIR
filter to exactly 1/2 the dB specification that you ultimately want because
you're gonna run the signal through the filter twice once forward and
another time in reverse, or in the case of Wang/Smith, once through a stable
TIIR and another through an unstable (mirrored poles/zeros) TIIR (and then
worry about the consequences of that unstability by ping-ponging two
identical unstable TIIRs and overlap adding the result. i like the time
reversing idea of Powell & Chau or Azizi better. it just seems safer.

your FSF filters are never really unstable, just "critically stable" and
then you nudge them into the unit circle a teeny bit.

but i am taken by the similarity of concept and am reading your chapter 7
now. it's amazing how many ways there are to skin the cat.

Quote:
FSFs have been around for roughly forty years!

FSFs are recursive FIR linear-phase filters.
I cover them, in some detail, in Section 7.1 of
the 2nd Edition of my book. As it turns out, for
some applications, FSFs are more computationally
efficient than Parks-McClellan-designed FIR filters.

but their frequency response is not as "tightly designed" as with P-McC, is
it Rick? the FSF seems to hit the target right on the sampling frequencies
of 2*pi*k/N, and in between it interpolates nicely, but might not do what
you want it to.

Quote:
For that reason I've been "preaching the gospel" of
these filters.
I made a presentation on FSFs at the COMP.DSP Conference
at Al Clark's place, and at the 2004 GSPx Conference in
San Jose CA last September.

another reason to regret not making it to the comp.dsp conference. the
event timing for me just couldn't have been much worse.

--

r b-j rbj@audioimagination.com

"Imagination is more important than knowledge."
Back to top
glen herrmannsfeldt
Guest





Posted: Sat Jan 08, 2005 11:36 pm    Post subject: Re: A little FIR/IIR puzzler Reply with quote

Randy Yates wrote:
(snip)

Quote:
Thus here in your case N = 2 and thus

y[n] = y[n - 1] + (1/2) * (x[n] - x[n - 2])

If we take the z-transform and solve for the transfer function we get

Y(z)/X(z) = (1/2) * (z^2 - 1) / [z * (z - 1)].


Then factor out (z-1):

Y(z)/X(z) = (1/2) (z+1)/z

-- glen
Back to top
Randy Yates
Guest





Posted: Sun Jan 09, 2005 5:09 am    Post subject: Re: A little FIR/IIR puzzler Reply with quote

glen herrmannsfeldt <gah@ugcs.caltech.edu> writes:

Quote:
Randy Yates wrote:
(snip)

Thus here in your case N = 2 and thus

y[n] = y[n - 1] + (1/2) * (x[n] - x[n - 2])

If we take the z-transform and solve for the transfer function we get

Y(z)/X(z) = (1/2) * (z^2 - 1) / [z * (z - 1)].


Then factor out (z-1):

Y(z)/X(z) = (1/2) (z+1)/z

Then it's not recursive!
--
% Randy Yates % "Remember the good old 1980's, when
%% Fuquay-Varina, NC % things were so uncomplicated?"
%%% 919-577-9882 % 'Ticket To The Moon'
%%%% <yates@ieee.org> % *Time*, Electric Light Orchestra
http://home.earthlink.net/~yatescr
Back to top
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> DSP All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




VoIP Electronics Powered by phpBB