DSPRelated.com
Forums

saturation in iir filter

Started by marianne April 1, 2008
>I agree with that idea but in my present case, my filter is a high pass >filter and it doesn't seem to me that the gain is ever > 1 (i might be >wrong on this) >that's where my un-understanding lies: how can i saturate if my filter >gain is never >1...
You have an IIR which consists of two parts: * FIR -> foreward path, coefficients (matlab style) B=[0.941266298,-1.8825326, 0.941266298] * IIR -> backward path, coefficients A=[1, -1.879089, 0.885975957] Depending on your implementation you do foreward before feedback path (for example direct form 1 implementation) (or vice versa). If you own MATLAB or OCTAVE you get your filter response with: freqz(B,A) - then you see your filterresponse -- and you are right that it has no gain, only attenuation but if you have a closer look to the foreward path you have to type: freqz(B,1) then you will see that the foreward path has positive gain and for the feedback path type freqz(1,A) then you will also see positive gain (a lot!) here. Depending to your implementation (I didn´t read all the posts so I don´t know which one you choosed) you will clip the signal in the accumulation point if you do nothing and you are using that coefficents. For example you have direct form 1 implementation you have to take care that the foreward path has no gain. If the feedback path has gain it should be only there where the foreward path compensates this. Or you compensate that in the following way: dividing all coefficients by two and do a shift in left direction (=multiply by two) on the correct place in your structure (For direct form 1 this is before you split up y[n] and the delay line for the feedback path - if you have noise problems then you could do the feedback path in double precision). Check out http://en.wikipedia.org/wiki/Digital_biquad_filter if you are not sure what´s direct form. I hope that helps, greetings, Markus www.two-pi.com
Hi marianne,

"marianne" <mary1331@hotmail.com> writes:

>>If the accumulator result is q2.30, then to multiply by two, simply >>reinterpret the scaling as q3.29. you don't really do anything >>physically, it's just a reinterpretation. As a simple example, let's >>say the accumulator result was "1.0", or 0x40000000 in q(2,30). >>But 0x4000000 in q(3,29) is "2.0". Voila: we've multiplied by two, >>but we didn't overflow anything or lose any precision. >> >>What I would do, then, is first shift the accumulator right by 14 >>(since this changes the scaling to q17.15), then perform your saturation >>logic using 0x00007FFF and 0xFFFF8000 and store the least-significant 16 >>bits of the accumulator, resulting in q(17-16).15 = q1.15. In order to >>round, add 0x00002000 to the accumulator before shifting right by 14. >>If you want to protect the round operation from overflow, shift the >>accumulator right 1 first, then add 0x00001000, and then shift right by >>13 and perform the saturation logic. > > Let's take an example that really happen in my filter: > my accumulator value (in q2.30 before considering it as q3.29) is > 0x21ca49a7: it is not over the max of q2.30, fine.
Right.
> Now i do what you suggest above add 0x00002000 -> 0x21ca69a7 > shift rigth by 14 -> 0x00008729 is over 0x00007fff so my q1.15 output > result is 0x7fff => ok i am saturating
That's right. That's because you're trying to stuff a number with 2 integer digits into an output with only 0 integer digits. NB: qa.b has a-1 integer digits. See section 4 of my paper near the end where it gives the range of an A(a,b) scaling. http://digitalsignallabs.com/fp.pdf I did not address whether your choices in scaling were appropriate. I simply showed the proper way to execute the filter given those scalings. I assumed that you had chosen scalings that satisfy the requirements of your system.
>>That may be true - I'd have to examine your filter coefficients more >>closely to say for sure. > > the coefficients are b0 = 0.941266298 b1 = -1.8825326 b2 = 0.941266298 > a1 = -1.879089 a2 = 0.885975957 > [...] > I agree with that idea but in my present case, my filter is a high pass > filter and it doesn't seem to me that the gain is ever > 1 (i might be > wrong on this) > that's where my un-understanding lies: how can i saturate if my filter > gain is never >1...
Because, while my example was correct, it wasn't all-inclusive. That is, you cannot state that "An IIR filter has potential overflow problems if and only if it has a gain greater than 1 at some frequency." The situation is more complex: there are other reasons it could overflow and you've run into one. Essentially, while steady-state sine waves won't overflow your filter (I checked your coefficients and its passband gain never exceeds 1) as scaled, transients will. If you want to guarantee that your output will never overflow in this filter, then you must scale the integer output value a in qa.b as a = 3 + ceil(log_2(0.951266298 + 1.8825326 + 0.941266298 + 1.879089 + 0.885975957)) = 6, or q6.11. The system designer has to determine what is more important: avoiding overflow at all costs or preserving precision. You can preserve precision at the cost of potentially saturating a few special case input signals. -- % 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://www.digitalsignallabs.com
Randy Yates <yates@ieee.org> writes:
> [...] > or q6.11.
Sorry! q6.10. -- % Randy Yates % "Rollin' and riding and slippin' and %% Fuquay-Varina, NC % sliding, it's magic." %%% 919-577-9882 % %%%% <yates@ieee.org> % 'Living' Thing', *A New World Record*, ELO http://www.digitalsignallabs.com
Randy Yates <yates@ieee.org> writes:

> Hi marianne, > [...]
PS: I checked your original post and found out your accumulator is 64 bits wide. That means that, while the result of multipying two 16-bit q1.15 numbers is q2.30, the final result after being sign-extended into the accumulator is q34.30. I was assuming in my earlier post that the accumulator was 32 bits wide. -- % Randy Yates % "She's sweet on Wagner-I think she'd die for Beethoven. %% Fuquay-Varina, NC % She love the way Puccini lays down a tune, and %%% 919-577-9882 % Verdi's always creepin' from her room." %%%% <yates@ieee.org> % "Rockaria", *A New World Record*, ELO http://www.digitalsignallabs.com
Thanks for your help and good advices Randy.
I think i managed to work out the pb, as you said, my scaling was not
good.
I finally scaled down my inputs by 2, did all the calculation and only in
the end of the process scaled up the output by 2 again and it works: i
don't hear artifacts any more and i kept my input dynamic.
I think the problem was not really coming from having those saturated
samples at the output but rather to put them back in the feedback part of
the filter and do calculation with them.
Anyway , thanks again Randy for the time you took to answer my question
and give precious advice.What is nice with signal processing and Dsp is
that it is a never ending learning topics!
merci beaucoup ;-)