DSPRelated.com
Forums

Fixed Point IIR implementation

Started by Fred Nach November 30, 2005
Hi pals,

I would like to implement a IIR Biquad filter using the fixed point 
arithmetics...
Hence to reduced the intermediate states I plan to use the following trick:
s(k) = x(k) -a1*s(k-1) -a2*s(k-2)
y(n) = b0*s(k) + b1*s(k-1) + b2*s(k-2)

The I can compute each y, saving only 2 states (s(k-1) a�nd s(k-2))...

BUT ... in order to scale my coefficients or input, I need to know what 
are the boundaries of the s(k) serie... in order to find a proper Fixed 
Point format for my coefficients..
So my questions are :

* for which conditions, s(k) is bounded
* If the s(k) is bounded, what are the boundaries?

Thanks in advance for your help (and sorry for my poor englsih)

Fred.
Fred Nach wrote:
> Hi pals, > > I would like to implement a IIR Biquad filter using the fixed point > arithmetics... > Hence to reduced the intermediate states I plan to use the following trick: > s(k) = x(k) -a1*s(k-1) -a2*s(k-2) > y(n) = b0*s(k) + b1*s(k-1) + b2*s(k-2) > > The I can compute each y, saving only 2 states (s(k-1) a�nd s(k-2))... > > BUT ... in order to scale my coefficients or input, I need to know what > are the boundaries of the s(k) serie... in order to find a proper Fixed > Point format for my coefficients.. > So my questions are : > > * for which conditions, s(k) is bounded > * If the s(k) is bounded, what are the boundaries? > > Thanks in advance for your help (and sorry for my poor englsih)
Your English is good enough, I think. The s[k] are data you supply. They can't be larger or smaller than the representation allows, but they may have smaller limits. I see no feedback in the formulas you give. Is that correct? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Fred Nach wrote:
> > I would like to implement a IIR Biquad filter using the fixed point > arithmetics... > Hence to reduced the intermediate states I plan to use the following tric=
k:
> s(k) =3D x(k) -a1*s(k-1) -a2*s(k-2) > y(n) =3D b0*s(k) + b1*s(k-1) + b2*s(k-2) > > The I can compute each y, saving only 2 states (s(k-1) a=E9nd s(k-2))...
this is the Direct 2 Form (sometimes called the "Direct II Canonical Form"). unrecommeded for floating-point (if the Q is quite high, you end up subtracting numbers very close to each other and losing precision) and *highly* unrecommended for fixed-point (saturation clipping will be your lot). try the Direct 1 Form: y[n] =3D b0*x[n] + b1*x[n-1] + b2*x[n-2] - a1*y[n-1] - a2*y[n-2] every product on the right side of the =3D sign is a double precision fixed point and all of those products should be added together in double precision. this is trivial in the Mot 56K and the ADI SHArC and maybe in the TI fixed-pointers.
> BUT ... in order to scale my coefficients or input, I need to know what > are the boundaries of the s(k) serie... in order to find a proper Fixed > Point format for my coefficients..
your coefs are defined strictly in terms of the frequency response you want. the gross range of a1 is -2 to +2 and a2 is -1 to +1 for any stable biquad filter. the b0, b1, b2 coefs can be nearly anything but you will have to choose a range and possibly do some scaling using the arithmetic shift operation on the result before saving to y[n].
> So my questions are : > > * for which conditions, s(k) is bounded > * If the s(k) is bounded, what are the boundaries?
that is a purely artificial construct. are your fixed-point signal values considered 16 bit signed integers? then it's -32768 <=3D x[n] < +32768 . are they normalized? then it's -1 <=3D x[n]< +1. their range is whatever you want them to be.
> Thanks in advance for your help (and sorry for my poor englsih)
as Jerry said, your English is fine. r b-j
> I see no feedback in the formulas you give. Is that correct?
The aX coeffecients should be the feedback terms and the bX coefficients should be the feed forward terms (from drawing a direct form II simulation diagram). The s(k) terms are the inputs to the delay buffers, which will be a function of the input, feed forward and feedback terms. I see the question he is asking, how to determine if these terms overflow the fixed point number format in use, and how to determine a proper scaling value to keep it from happening. Unfortunately, I don't know how to answer this question, but in the project I am presently working on I have encountered the same problem, so I am hoping someone has a good answer. I got around the problem (? maybe ?) by using a direct form I structure. I have seen Matlab scripts that run an impulse response till it stabilizes and then sum up the impulse responses and use the maximum value as a scale factor, though I don't know if this is a correct solution.
Noway2 wrote:
>>I see no feedback in the formulas you give. Is that correct? > > > The aX coeffecients should be the feedback terms and the bX > coefficients should be the feed forward terms (from drawing a direct > form II simulation diagram). The s(k) terms are the inputs to the > delay buffers, which will be a function of the input, feed forward and > feedback terms. > > I see the question he is asking, how to determine if these terms > overflow the fixed point number format in use, and how to determine a > proper scaling value to keep it from happening. Unfortunately, I don't > know how to answer this question, but in the project I am presently > working on I have encountered the same problem, so I am hoping someone > has a good answer. I got around the problem (? maybe ?) by using a > direct form I structure. > > I have seen Matlab scripts that run an impulse response till it > stabilizes and then sum up the impulse responses and use the maximum > value as a scale factor, though I don't know if this is a correct > solution.
I expect that the b's are the denominator terms. Input samples are s[n], output and feedback samples are y[n]. I see no coefficients operating on any y[n]. I see what he's asking too. His problem lies with internal states, and I don't know how to deal with that in the abstract. If there's a general case, I haven't seen it. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Jerry Avins wrote:
> > I expect that the b's are the denominator terms.
no, Jerry, the a's are in the denominator. they reversed that convention a while back. in the 70's it was a_k on top and b_k on bottom, but, i think because they think that poles are more important, most texts have it switched around now. r b-j
robert bristow-johnson wrote:
> Jerry Avins wrote: > >>I expect that the b's are the denominator terms. > > > no, Jerry, the a's are in the denominator. they reversed that > convention a while back. in the 70's it was a_k on top and b_k on > bottom, but, i think because they think that poles are more important, > most texts have it switched around now. > > r b-j
I knew that too, but old habits sometimes bubble up. The important point was that Fred N. has no y terms to the right of an equal sign, so I don't see any recursion. Somewhere along the line I wrote that. Twice, I think. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Jerry Avins wrote:
> robert bristow-johnson wrote: > > Jerry Avins wrote: > > > >>I expect that the b's are the denominator terms. > > > > no, Jerry, the a's are in the denominator. > > I knew that too, but old habits sometimes bubble up. The important point > was that Fred N. has no y terms to the right of an equal sign, so I > don't see any recursion.
there is recursion with the intermediate s[k] signal: Fred Nach wrote:
> I would like to implement a IIR Biquad filter using the fixed point > arithmetics... > Hence to reduced the intermediate states I plan to use the following trick: > s(k) = x(k) -a1*s(k-1) -a2*s(k-2) > y(n) = b0*s(k) + b1*s(k-1) + b2*s(k-2)
this is the canonical Direct Form 2. poles before zeros. problem is, if there is a high Q filter, those poles will amplify the signal so much that it will saturate s[k] before the zeros get to beat the signal back down. DF2 ain't particularly good, especially for fixed-point arithmetic. r b-j
On Wed, 30 Nov 2005 11:01:31 -0800, Noway2 wrote:
> I have seen Matlab scripts that run an impulse response till it > stabilizes and then sum up the impulse responses and use the maximum > value as a scale factor, though I don't know if this is a correct > solution.
It's pretty close. This is the main reason why these "direct form 2" implmentations are not preferred. A direct form 1 implmentation will use more memory but (a) memory is relatively cheap and (b) the values stored will be as constrained as the input and output values. -- Andrew
robert bristow-johnson wrote:
> Jerry Avins wrote: > >>robert bristow-johnson wrote: >> >>>Jerry Avins wrote: >>> >>> >>>>I expect that the b's are the denominator terms. >>> >>>no, Jerry, the a's are in the denominator. >> >>I knew that too, but old habits sometimes bubble up. The important point >>was that Fred N. has no y terms to the right of an equal sign, so I >>don't see any recursion. > > > there is recursion with the intermediate s[k] signal:
OK. Back to the books with my thinking cap on. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;