DSPRelated.com
Forums

IIR instability/oscillations

Started by Brian Reinhold February 13, 2004
I have found a computationally efficent, 5-tap IIR band pass filter.  It's
in 'The Scientist and Engineer's Guide to Digital Signal Processing
available online (chapter 19).

However, upon implelementation, it appears to oscillate and I don't know
why.  Is there some inherent damping rate that is too small?

I select the coefficients to pass a 2100 Hz tone with a bandwith of 80 Hz
with a sampling rate of 42000 Hz.  If I send a signal of 2100 Hz full of
noise, it filters the noise beautifully; pulses, spikes, etc., all go.
However, the signal oscillates evry so often (quite often).

If I send a signal of alternating 2100 Hz and 1300 Hz at 1200 baud, it seems
to get rid of everything.

Any help?  Thanks.

Brian


"Brian Reinhold" <breinhold@comcast.net> wrote in message
news:RZ3Xb.27427$_44.27441@attbi_s52...
> I have found a computationally efficent, 5-tap IIR band pass filter. It's > in 'The Scientist and Engineer's Guide to Digital Signal Processing > available online (chapter 19). > > However, upon implelementation, it appears to oscillate and I don't know > why. Is there some inherent damping rate that is too small? > > I select the coefficients to pass a 2100 Hz tone with a bandwith of 80 Hz > with a sampling rate of 42000 Hz. If I send a signal of 2100 Hz full of > noise, it filters the noise beautifully; pulses, spikes, etc., all go. > However, the signal oscillates evry so often (quite often). > > If I send a signal of alternating 2100 Hz and 1300 Hz at 1200 baud, it
seems
> to get rid of everything.
Brian, Why not reveal the filter coefficients if you want help? Also, I have *no* idea what a 5-tap IIR filter is - it would only be conjecture. A 5-tap FIR, yes. Fred
In article <RZ3Xb.27427$_44.27441@attbi_s52>,
Brian Reinhold <breinhold@comcast.net> wrote:
>I have found a computationally efficent, 5-tap IIR band pass filter. It's >in 'The Scientist and Engineer's Guide to Digital Signal Processing >available online (chapter 19). > >However, upon implelementation, it appears to oscillate and I don't know >why. Is there some inherent damping rate that is too small? > >I select the coefficients to pass a 2100 Hz tone with a bandwith of 80 Hz >with a sampling rate of 42000 Hz. If I send a signal of 2100 Hz full of >noise, it filters the noise beautifully; pulses, spikes, etc., all go. >However, the signal oscillates evry so often (quite often).
Is what you are calling a 5-tap IIR a biquad? (3 sequential input samples + the 2 most recent past output samples)? Check your calculation precision. If the pole is very near the unit circle (very high Q), then even slight rounding errors in the feedback loop can cause the pole to move to onto or outside the unit circle, which makes the filter behave more like a (perhaps runaway) oscillator. You could try higher precision math (doubles or quads instead of floats), or use two lower Q filters (e.g. two biquad in series). IMHO. YMMV. -- Ron Nicholson rhn AT nicholson DOT com http://www.nicholson.com/rhn/ #include <canonical.disclaimer> // only my own opinions, etc.
Fred,

Here is the filter (5 coefficients, not five taps...sorry about my improper
use of the terminology)

  y(n) = a00 * x(n) + a10 * x(n-1) + a20 * x(n-2) + b10 * y(n-1) + b2 *
y(n-2);

where

cosb0 = cos(2*pi*f/samplespersec)

 r = 1.0 - 3.0 * (bandwidth) / samplespersec;

 k0 = (1.0 - 2.0 * r * cosb0 + r * r) / (2.0 - 2.0 * cosb0);

 a00 = 1.0 - k0;
 a10 = 2.0 * (k0 - r) * cosb0;
 a20 = r * r - k0;
 b10 = 2.0 * r * cosb0;

This filter comes from the book by Steve Smith (available on line) which I
found via this newsgroup in a post not to long ago.

Yes, and I guess it is a 5-tap IIR biquad.

Brian


"Ronald H. Nicholson Jr." <rhn@mauve.rahul.net> wrote in message
news:c0kuft$rbq$1@blue.rahul.net...
> In article <RZ3Xb.27427$_44.27441@attbi_s52>, > Brian Reinhold <breinhold@comcast.net> wrote: > >I have found a computationally efficent, 5-tap IIR band pass filter.
It's
> >in 'The Scientist and Engineer's Guide to Digital Signal Processing > >available online (chapter 19). > > > >However, upon implelementation, it appears to oscillate and I don't know > >why. Is there some inherent damping rate that is too small? > > > >I select the coefficients to pass a 2100 Hz tone with a bandwith of 80 Hz > >with a sampling rate of 42000 Hz. If I send a signal of 2100 Hz full of > >noise, it filters the noise beautifully; pulses, spikes, etc., all go. > >However, the signal oscillates evry so often (quite often). > > Is what you are calling a 5-tap IIR a biquad? (3 sequential input > samples + the 2 most recent past output samples)? > > Check your calculation precision. If the pole is very near the unit > circle (very high Q), then even slight rounding errors in the feedback > loop can cause the pole to move to onto or outside the unit circle, > which makes the filter behave more like a (perhaps runaway) oscillator. > > You could try higher precision math (doubles or quads instead of floats), > or use two lower Q filters (e.g. two biquad in series). > > > IMHO. YMMV. > -- > Ron Nicholson rhn AT nicholson DOT com http://www.nicholson.com/rhn/ > #include <canonical.disclaimer> // only my own opinions, etc.
Brian Reinhold wrote:
> > Yes, and I guess it is a 5-tap IIR biquad.
Sorry, thats a standard 2nd order IIR biquad. Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo nospam@mega-nerd.com (Yes it's valid) +-----------------------------------------------------------+ "The beauty of religious mania is that it has the power to explain everything. Once God (or Satan) is accepted as the first cause of everything which happens in the mortal world, nothing is left to chance...logic can be happily tossed out the window." - Stephen King
In article <ZvAXb.318031$na.474592@attbi_s04>,
Brian Reinhold <breinhold@comcast.net> wrote:
> r = 1.0 - 3.0 * (bandwidth) / samplespersec;
Note that, for very narrow bandwidths, r gets very close to 1.0, the unit circle, where you end up with an oscillator instead of a filter. So round-off error becomes very important. How many bits of precision are you using inside your IIR filter and for the past samples feed back into those calculations? IMHO. YMMV. -- Ron Nicholson rhn AT nicholson DOT com http://www.nicholson.com/rhn/ #include <canonical.disclaimer> // only my own opinions, etc.
Okay, that seems to explain it.  I notice that I could get rid of the
oscillations by increasing the bandwidth.  I use double precision (64 bits)
floating point for my calculations.

 I also noted something else which I could not explain concerning the
response time of the filter when the bandwidth was narrow.  If I fed a
signal into the filter (one designed to peak at 1300 Hz and the other at
2100 Hz) which alternated these tones at 1200 baud that essentially nothing
would get passed.

I tried the "dot pattern" signal on
(1) 1300 filter
(2) 2100 filter
and the results were the same.

Now if I fed a constant 1300 or 2100 Hz signal into the filters, I would get
the expected result (with oscillations).

Increasing the bandwidth let both of these signals pass.  I have plenty of
samples per cycle (well more than the three "delays" needed to fill the
queue, so to say) so it can't be that which is the problem.

Is there a technique whereby I could maintain the narrow bandwidth but apply
some kind of "fake" dissipation in order to keep the filter stable?  Does
double precision seem too inadequate to you?  I guess the only way to tell
is to go to higher precision and see if the problem stops.  Worth it if the
other problem also goes away (the dot pattern does not get properly
filtered).

Brian
"Ronald H. Nicholson Jr." <rhn@mauve.rahul.net> wrote in message
news:c0movn$aeh$1@blue.rahul.net...
> In article <ZvAXb.318031$na.474592@attbi_s04>, > Brian Reinhold <breinhold@comcast.net> wrote: > > r = 1.0 - 3.0 * (bandwidth) / samplespersec; > > Note that, for very narrow bandwidths, r gets very close to 1.0, > the unit circle, where you end up with an oscillator instead of a > filter. So round-off error becomes very important. > > How many bits of precision are you using inside your IIR filter > and for the past samples feed back into those calculations? > > > IMHO. YMMV. > -- > Ron Nicholson rhn AT nicholson DOT com http://www.nicholson.com/rhn/ > #include <canonical.disclaimer> // only my own opinions, etc.
In article <8UMXb.39341$yE5.140564@attbi_s54>,
Brian Reinhold <breinhold@comcast.net> wrote:
>Increasing the bandwidth let both of these signals pass. I have plenty >of samples per cycle (well more than the three "delays" needed to fill >the queue, so to say) so it can't be that which is the problem.
IIR's require far more than 3 "delays" to "fill the queue". The delay of an IIR will be more related to the length (to the median) of its impulse response. And the width of the impulse response is inversely related to the filter bandwidth as a fraction of the sample rate. Also, make sure you are not confusing "oscillation", and ordinary filter delay (which sounds like "ringing"). IMHO. YMMV. -- Ron Nicholson rhn AT nicholson DOT com http://www.nicholson.com/rhn/ #include <canonical.disclaimer> // only my own opinions, etc.
Oh yes, they do keep going.  I am pretty sure that it is an oscillation, as
it occurs when I feed it a steady signal.  For breif periods the response is
steady and then it goes into aperiodic oscillations then stops, etc.

So a narrow bandwidth will have a long impulse reponse?  That would be why a
1300 Hz and 2100 Hz tone lasting for 1/1200 of a sec would get damped out.

Wider bandwidths do stop the oscillation and the damping.  I also added a
term to the damping coefficient when the bandwidth was narrow that helped
kill the oscillation.  But in the end it looks like the best I can do is to
make it a wide bandwidth or maybe not use it at all.

Brian
"Ronald H. Nicholson Jr." <rhn@mauve.rahul.net> wrote in message
news:c0onlt$hmq$1@blue.rahul.net...
> In article <8UMXb.39341$yE5.140564@attbi_s54>, > Brian Reinhold <breinhold@comcast.net> wrote: > >Increasing the bandwidth let both of these signals pass. I have plenty > >of samples per cycle (well more than the three "delays" needed to fill > >the queue, so to say) so it can't be that which is the problem. > > IIR's require far more than 3 "delays" to "fill the queue". The delay of > an IIR will be more related to the length (to the median) of its impulse > response. And the width of the impulse response is inversely related to > the filter bandwidth as a fraction of the sample rate. > > Also, make sure you are not confusing "oscillation", and ordinary filter > delay (which sounds like "ringing"). > > > IMHO. YMMV. > -- > Ron Nicholson rhn AT nicholson DOT com http://www.nicholson.com/rhn/ > #include <canonical.disclaimer> // only my own opinions, etc.
"Brian Reinhold" <breinhold@comcast.net> wrote in message
news:RrcYb.46269$uV3.92266@attbi_s51...
> Oh yes, they do keep going. I am pretty sure that it is an oscillation,
as
> it occurs when I feed it a steady signal. For breif periods the response
is
> steady and then it goes into aperiodic oscillations then stops, etc. > > So a narrow bandwidth will have a long impulse reponse? That would be why
a
> 1300 Hz and 2100 Hz tone lasting for 1/1200 of a sec would get damped out. > > Wider bandwidths do stop the oscillation and the damping. I also added a > term to the damping coefficient when the bandwidth was narrow that helped > kill the oscillation. But in the end it looks like the best I can do is
to
> make it a wide bandwidth or maybe not use it at all. >
Brian, I don't think you ever did give us the actual coefficient values - just how to calculate them. Wouldn't that be a good idea? Just to make sure? Fred