DSPRelated.com
Forums

[Fwd: Re: [Fwd: Re: code working on simulator but not on device?]]

Started by Jeff Brower May 23, 2006
Megha-

Here is another way to think about it. If you start with simple 2-pole filter time
domain equation:

y[n] = b0x[n] + b1x[n-1] + b2x[n-2] +a1y[n-1] + a2y[n-2]

Let's say your largest a or b coefficient is 3.5. Then you can think of quantizing
coefficients to Q13 format -- 2 digits to left of decimal point, or maximum values of
-4 and +3.9995 represented by each 16-bit word. This means:

-to quantize a and b, multiply by 8192

-every y[n] output and delay element will also be in
Q13 format

-ADC input (x[n] values) should be limited to Q13 also
(-8192 to 8191), so keep the input level low

-if you apply gain factor before final DAC output, then
it has to be in Q13 also

-be careful to watch for overflow after additions -- if
you see it, try further reducing your input

-Jeff
-------- Original Message --------
Subject: Re: [Fwd: Re: [c54x] code working on simulator but not on device?]
Date: Mon, 22 May 2006 20:05:24 -0700 (PDT)
From: megha daga
To: Jeff Brower ,c54group

Dear Jeff
I had a question regarding normalization.
IIR filter function is as follows:

[y(n) = b_{0} x(n) + b_{1} x(n-1) + \cdots + b_{P} x(n-P) + a_{1} y(n-1) + a_{2} y(n-2) + \cdots + a_{Q} y(n-Q)]

We convert these into biquads (as we need to trasfer biquads to DSP). We convert with
command
[sos,g] = tf2sos(b,a)
A biquad is as shown:

b0 + b1 * z-1 + b2 * z-2
H(z) = ——————————————
1 + a1 * z-1 + a2 * z-2

and sos is:

* [Image]

Now i need to pass these values bo,b,b2,a1 and a2 to DSP and a0 should be 1. What I
want is these coeff should be betwen 1 and -1 for DSP. But from MATLAB I am getting
them outside the limit. Hence i need to normalize. So Thats the problem. If I
normalize then a0 also gets normalize.
Should I normalize only b0,b1,b2,a1 and a2. If I do that will it effect the filter?
I hope my doubt is clear.
Kindly reply
thanking You
Megha Daga

Jeff Brower wrote:

Megha-

> I had one question regadring the normalization and I just thought
> if you can help. When I normalize the sos matrix (by diving it by
> a factor), what should I do with value of "g". I guess that is also
> suppose to be normalized.

I assume that "g" is the gain factor for the overall filter. In that case,
you don't
have to do anything to it. When you have DAC value ready to output, then
you take
your most recent y[n] output (should be in Q15 format):

DAC output = y[n] * k * g

where k is the scaling factor to allow Q15 to work, and g is the filter
gain. It
might be a good idea to pre-calculate k*g so you can use it in Q15 format.

-Jeff