Reply by robert bristow-johnson●May 10, 20052005-05-10
in article 1115694490.392768.269540@z14g2000cwz.googlegroups.com, john at
johns@xetron.com wrote on 05/09/2005 23:08:
> Another idea is to break a1 into two pieces, a11 and a12, where a1 =
> a11+a12, and code your filter to include an extra MAC.
and it's a good idea. sometimes i've seen it where one of those a1s is 1.0
(or -1.0), which was hard coded, and the other is a1-1. that doesn't have
any loss of precision, but is not really flexible. the more flexible
solution is to have both a1s equal to a1/2 and MAC it in twice. the issue
with b1 can be dealt with a level change. (a normalized b1 could have the
same issues, or even worse since zeros don't have to be restricted to be
within the unit circle.)
--
r b-j rbj@audioimagination.com
"Imagination is more important than knowledge."
Reply by john●May 10, 20052005-05-10
robert bristow-johnson wrote:
> in article 1115656409.123478.17940@f14g2000cwb.googlegroups.com,
> tanmay.zargar@gmail.com at tanmay.zargar@gmail.com wrote on
05/09/2005
> 12:33:
>
> > Thanks for the reply Robert.
>
> FWIW.
>
> > However, I must have the coefficients in 1.15 format, since the DSP
I am
> > using has optimized instructions for 1.15 math.
>
> just for my information, which DSP is that? (some ADSP21xx series or
some
> TI chip?) but even if the chip is optimized for 1.15 (which means
you can
> multiply a 1.15 by another 1.15 and immediately get a 1.15 or perhaps
a 1.30
> result) WHERE that binary point actually is lies only in the mind of
the
> beholder. you have 16 bits, you can put the binary point wherever
you want
> as long as you deal with the scaling that such placement implies in
the
> proper manner.
>
> > I do understand that for a typical biquad, one might have
> > coefficients in the -2 to 2 range and for some of the filters I am
> > implementing, that is indeed the case. So what I have done is
scaled
> > the coefficients down by an appropriate factor so that the output
> > occupies the range 0.999969 to -1.
>
> that is where scaling the coefficients counts for anything. when you
have a
> transfer function:
>
>
> b0 + b1*z^-1 + b2*z^-2
> H(z) = ------------------------
> a0 + a1*z^-1 + a2*z^-2
>
>
> you cannot realize a discrete-time filter until you, at the very
least,
> normalize a0 to 1. you do that by dividing both numerator and
denominator
> by a0. then what you get is:
>
>
> (b0/a0) + (b1/a0)*z^-1 + (b2/a0)*z^-2
> H(z) = ---------------------------------------
> 1 + (a1/a0)*z^-1 + (a2/a0)*z^-2
>
>
> and at this point we normally just redefine the remaining 5
coefficients so
> that we have:
>
>
> b0 + b1*z^-1 + b2*z^-2
> H(z) = ------------------------
> 1 + a1*z^-1 + a2*z^-2
>
>
> now, assuming that H(z) is a stable transfer function, it's possible
that
> the a1 coefficient can have range -2 to +2 relative to the normalized
a0
> coef which is now just 1. when you implement this in the Direct Form
1
> (perhaps you're using a different form but similar scaling issues
remain),
> the difference equation is:
>
>
> y[n] = b0*x[n] + b1*x[n-1] + b2*x[n-2] - a1*y[n-1] - a2*y[n-2]
>
>
> you may not scale the a1 or a2 coefficients according to any other
criteria.
> you *may* scale the numerator coefficients (b0, b1, b2) by a common
factor
> and, except for quantizing or overflow issues, that will change only
the
> level of the output.
>
> now since a1 has a range that exceeds what you can put in a 1.15
number
> format, then what is usually done is that all 5 coefficients are
represented
> with 1/2 of their correct value and the resulting sum is doubled
(sometimes
> with an ASL instruction) before it is outputed and saved as a state.
>
>
> so the coefs you put into the DSP are b0/2, b1/2, b2/2, a1/2, a2/2,
and the
> result of the sum is 1/2 of what the output is until you multiply
that by 2
> (usually with an ASL instruction). this is not solely a scaling
issue
> because if you don't double the resulting sum, the y[n-1] and y[n-2]
states
> will not be correct and your filter will not have the shape that you
> designed for.
>
> > My question is: what effects on the output does coefficient scaling
> > have in particular?
>
> scaling is simply whatever you have to do to accomplish the
mathematics of
> computing the output. perhaps the question you are meaning to ask
is: "what
> effects on the output does coefficient *quantization* have in
particular?"
> quantization is what happens when the coefficient you want is not
precisely
> the 1.15 or 2.14 number you put into memory. that coefficient
quantization
> has very specific effects on the location of the poles and zeros
which
> define the shape of the filter's frequency response. this is in the
> textbooks, at least some of them.
>
> > Does it also imply a loss in SNR as in input scaling?
>
> scaling of the net a1 and a2 coefficient cannot be done (without
changing
> the *shape* of the frequency response of the filter). scaling the
numerator
> coefficients by a common factor will not change the shape of the
filter
> (except for increased coefficient quantization effects if you're
scaling
> down) but will change the level of the output. lowering that level
(by
> scaling b0, b1, b2 down by a common factor) will decrease S, but not
N, so
> the S/N will go down.
>
> > Are there better ways to tackle this issue?
>
> it (the coef quantization issue) has sorta been beaten do death in
Oppenhiem
> & Schafer (and other texts, Rick's book appears to only deal with the
issue
> of quantizing the _signal_, not of quantizing the coefs, not a
criticism but
> i can't offhand think of another text that does deal with this). if
you
> figgered out what i had been saying here and can reframe the
questions to be
> a little bit more applicable, i think the issue can be completely
tackled.
>
>
> --
>
> r b-j rbj@audioimagination.com
>
> "Imagination is more important than knowledge."
Another idea is to break a1 into two pieces, a11 and a12, where a1 =
a11+a12, and code your filter to include an extra MAC.
John
Reply by robert bristow-johnson●May 9, 20052005-05-09
in article 1115656409.123478.17940@f14g2000cwb.googlegroups.com,
tanmay.zargar@gmail.com at tanmay.zargar@gmail.com wrote on 05/09/2005
12:33:
> Thanks for the reply Robert.
FWIW.
> However, I must have the coefficients in 1.15 format, since the DSP I am
> using has optimized instructions for 1.15 math.
just for my information, which DSP is that? (some ADSP21xx series or some
TI chip?) but even if the chip is optimized for 1.15 (which means you can
multiply a 1.15 by another 1.15 and immediately get a 1.15 or perhaps a 1.30
result) WHERE that binary point actually is lies only in the mind of the
beholder. you have 16 bits, you can put the binary point wherever you want
as long as you deal with the scaling that such placement implies in the
proper manner.
> I do understand that for a typical biquad, one might have
> coefficients in the -2 to 2 range and for some of the filters I am
> implementing, that is indeed the case. So what I have done is scaled
> the coefficients down by an appropriate factor so that the output
> occupies the range 0.999969 to -1.
that is where scaling the coefficients counts for anything. when you have a
transfer function:
b0 + b1*z^-1 + b2*z^-2
H(z) = ------------------------
a0 + a1*z^-1 + a2*z^-2
you cannot realize a discrete-time filter until you, at the very least,
normalize a0 to 1. you do that by dividing both numerator and denominator
by a0. then what you get is:
(b0/a0) + (b1/a0)*z^-1 + (b2/a0)*z^-2
H(z) = ---------------------------------------
1 + (a1/a0)*z^-1 + (a2/a0)*z^-2
and at this point we normally just redefine the remaining 5 coefficients so
that we have:
b0 + b1*z^-1 + b2*z^-2
H(z) = ------------------------
1 + a1*z^-1 + a2*z^-2
now, assuming that H(z) is a stable transfer function, it's possible that
the a1 coefficient can have range -2 to +2 relative to the normalized a0
coef which is now just 1. when you implement this in the Direct Form 1
(perhaps you're using a different form but similar scaling issues remain),
the difference equation is:
y[n] = b0*x[n] + b1*x[n-1] + b2*x[n-2] - a1*y[n-1] - a2*y[n-2]
you may not scale the a1 or a2 coefficients according to any other criteria.
you *may* scale the numerator coefficients (b0, b1, b2) by a common factor
and, except for quantizing or overflow issues, that will change only the
level of the output.
now since a1 has a range that exceeds what you can put in a 1.15 number
format, then what is usually done is that all 5 coefficients are represented
with 1/2 of their correct value and the resulting sum is doubled (sometimes
with an ASL instruction) before it is outputed and saved as a state. that
is:
y[n] = 2*(b0/2*x[n] + b1/2*x[n-1] + b2/2*x[n-2] - a1/2*y[n-1] - a2/2*y[n-2])
so the coefs you put into the DSP are b0/2, b1/2, b2/2, a1/2, a2/2, and the
result of the sum is 1/2 of what the output is until you multiply that by 2
(usually with an ASL instruction). this is not solely a scaling issue
because if you don't double the resulting sum, the y[n-1] and y[n-2] states
will not be correct and your filter will not have the shape that you
designed for.
> My question is: what effects on the output does coefficient scaling
> have in particular?
scaling is simply whatever you have to do to accomplish the mathematics of
computing the output. perhaps the question you are meaning to ask is: "what
effects on the output does coefficient *quantization* have in particular?"
quantization is what happens when the coefficient you want is not precisely
the 1.15 or 2.14 number you put into memory. that coefficient quantization
has very specific effects on the location of the poles and zeros which
define the shape of the filter's frequency response. this is in the
textbooks, at least some of them.
> Does it also imply a loss in SNR as in input scaling?
scaling of the net a1 and a2 coefficient cannot be done (without changing
the *shape* of the frequency response of the filter). scaling the numerator
coefficients by a common factor will not change the shape of the filter
(except for increased coefficient quantization effects if you're scaling
down) but will change the level of the output. lowering that level (by
scaling b0, b1, b2 down by a common factor) will decrease S, but not N, so
the S/N will go down.
> Are there better ways to tackle this issue?
it (the coef quantization issue) has sorta been beaten do death in Oppenhiem
& Schafer (and other texts, Rick's book appears to only deal with the issue
of quantizing the _signal_, not of quantizing the coefs, not a criticism but
i can't offhand think of another text that does deal with this). if you
figgered out what i had been saying here and can reframe the questions to be
a little bit more applicable, i think the issue can be completely tackled.
--
r b-j rbj@audioimagination.com
"Imagination is more important than knowledge."
Reply by Bhaskar Thiagarajan●May 9, 20052005-05-09
<tanmay.zargar@gmail.com> wrote in message
news:1115656409.123478.17940@f14g2000cwb.googlegroups.com...
> Thanks for the reply Robert. However, I must have the coefficients in
> 1.15 format, since the DSP I am using has optimized instructions for
> 1.15 math. I do understand that for a typical biquad, one might have
> coefficients in the -2 to 2 range and for some of the filters I am
> implementing, that is indeed the case. So what I have done is scaled
> the coefficients down by an appropriate factor so that the output
> occupies the range 0.999969 to -1. My question is: what effects on the
> output does coefficient scaling have in particular?
Scaling the coeffs is going to reduce your filter performance (typically it
results in worse stop band attenuation).
You can view your scaling down operation as similar to quantizing your
coeffs to a smaller number of bits (since you are essentially restricting
it's range to a smaller set of numbers). If your filter had 100 dB stop band
rejection to start with but your signal had only 70dB SNR, and this scaling
made your stop band only 90dB, you aren't going to see any changes in your
output. So the effect on your output depends on what you had to begin with.
> Does it also imply
> a loss in SNR as in input scaling? Are there better ways to tackle this
> issue?
>
> Thanks,
> T.
>
Reply by ●May 9, 20052005-05-09
Thanks for the reply Robert. However, I must have the coefficients in
1.15 format, since the DSP I am using has optimized instructions for
1.15 math. I do understand that for a typical biquad, one might have
coefficients in the -2 to 2 range and for some of the filters I am
implementing, that is indeed the case. So what I have done is scaled
the coefficients down by an appropriate factor so that the output
occupies the range 0.999969 to -1. My question is: what effects on the
output does coefficient scaling have in particular? Does it also imply
a loss in SNR as in input scaling? Are there better ways to tackle this
issue?
Thanks,
T.
Reply by robert bristow-johnson●May 9, 20052005-05-09
in article 1115652383.374910.317390@f14g2000cwb.googlegroups.com,
tanmay.zargar@gmail.com at tanmay.zargar@gmail.com wrote on 05/09/2005
11:26:
> I am designing fixed point filters for processing audio signals and am
> faced with the following issue.
>
> I need to have the output within a range of +0.999969 and -1 or
> effectively 32767 and -32768 (range of a 1.15 signed fractional
> number). I have two options - scaling the input or scaling the filter
> coefficients. I realize that scaling the input will definitely cause a
> reduction in SNR. I am wondering what repercussions will scaling the
> coefficients have.
you will have to scale both. for biquad sections, there is at least 1
coefficient that has an intrinsic range of -2 to +2. that will have to be
scaled up by 16384 which is a 2.14 bit number.
you will need a double precision (32 bit) accumulator. and your your 1.15
signal and 2.14 bit coefficient will result in a 3.29 bit result and you
will have to round, check for overflow, and shift that left 2 bits before
taking the result out of the most significant 16 bit word.
is this done on a general purpose CPU or some kind of chip called a "DSP"?
if the latter, some of this scaling business is done for you.
--
r b-j rbj@audioimagination.com
"Imagination is more important than knowledge."
Reply by ●May 9, 20052005-05-09
People,
I am designing fixed point filters for processing audio signals and am
faced with the following issue.
I need to have the output within a range of +0.999969 and -1 or
effectively 32767 and -32768 (range of a 1.15 signed fractional
number). I have two options - scaling the input or scaling the filter
coefficients. I realize that scaling the input will definitely cause a
reduction in SNR. I am wondering what repercussions will scaling the
coefficients have.
Inputs?
Thanks,
T.