PDA

View Full Version : FIR coefficients


jack kilby
11-24-2003, 08:52 AM
hello all,
I am currently working with FIR filter.Here i get the coefficients as
deciamal values like
-0.000467744403
0.000802870932
-0.000000000000
-0.001041888331
0.000768540238
0.000930750510
-0.001834127637
0.000000000000
0.002708566451.......
i have to perform the filtering with 15 bit input line and 16 bit
output line.
can anyone suggest me how to store these coefficients in memory as
binary and convert them back.
i am currently using an approach of multiplying it with 1024 and
storing the binary equivalent in memory and then after provcessing
perform 10 times left shift,but its not so accurate ,kindly help me
out
thanks and regards
jack

Wolfgang
11-24-2003, 12:29 PM
Hello Jack,

Did you look at "Scaling to prevent overflow (Fixed Point)" (Heureka, 19.11) ?
In the ansers you find two files fp & fir that may help you.

Good luck,
Wolfgang

"jack kilby" <[email protected]> schrieb im Newsbeitrag news:[email protected] om...
> hello all,
> I am currently working with FIR filter.Here i get the coefficients as
> deciamal values like
> -0.000467744403
> 0.000802870932
> -0.000000000000
> -0.001041888331
> 0.000768540238
> 0.000930750510
> -0.001834127637
> 0.000000000000
> 0.002708566451.......
> i have to perform the filtering with 15 bit input line and 16 bit
> output line.
> can anyone suggest me how to store these coefficients in memory as
> binary and convert them back.
> i am currently using an approach of multiplying it with 1024 and
> storing the binary equivalent in memory and then after provcessing
> perform 10 times left shift,but its not so accurate ,kindly help me
> out
> thanks and regards
> jack

Wolfgang
11-24-2003, 12:30 PM
Hello Jack,

Did you look at "Scaling to prevent overflow (Fixed Point)" (Heureka, 19.11) ?
In the ansers you find two files fp & fir that may help you.

Good luck,
Wolfgang

"jack kilby" <[email protected]> schrieb im Newsbeitrag news:[email protected] om...
> hello all,
> I am currently working with FIR filter.Here i get the coefficients as
> deciamal values like
> -0.000467744403
> 0.000802870932
> -0.000000000000
> -0.001041888331
> 0.000768540238
> 0.000930750510
> -0.001834127637
> 0.000000000000
> 0.002708566451.......
> i have to perform the filtering with 15 bit input line and 16 bit
> output line.
> can anyone suggest me how to store these coefficients in memory as
> binary and convert them back.
> i am currently using an approach of multiplying it with 1024 and
> storing the binary equivalent in memory and then after provcessing
> perform 10 times left shift,but its not so accurate ,kindly help me
> out
> thanks and regards
> jack

Vic
11-25-2003, 11:41 AM
Hi,
u can to use scaling 2**15:
to memory Ks[j]=(short)(Kfloat*0x8000);
to calculate y+=(...*Ks[j])>>15;

Cheers

Randy Yates
11-25-2003, 01:05 PM
Vic wrote:
> Hi,
> u can to use scaling 2**15:
> to memory Ks[j]=(short)(Kfloat*0x8000);
> to calculate y+=(...*Ks[j])>>15;
>
> Cheers

For these particular coefficients, Q15 isn't
very appropriate. Even the largest coefficient
would only be the integer value 89 - a very
high coefficient quantization error.

Try Q23, i.e., multiply all real coefficients by
2^23 to get the integer-valued coefficients.
--
% Randy Yates % "...the answer lies within your soul
%% Fuquay-Varina, NC % 'cause no one knows which side
%%% 919-577-9882 % the coin will fall."
%%%% <[email protected]> % 'Big Wheels', *Out of the Blue*, ELO
http://home.earthlink.net/~yatescr

Jim Thomas
11-25-2003, 03:16 PM
Randy Yates wrote:
> For these particular coefficients, Q15 isn't
> very appropriate. Even the largest coefficient
> would only be the integer value 89 - a very
> high coefficient quantization error.
>
> Try Q23, i.e., multiply all real coefficients by
> 2^23 to get the integer-valued coefficients.

Randy,

I'm not sure the OP listed all the coefficients. In the original post,
the list of coefs was followed by something akin to an ellipsis:

> -0.000467744403
> 0.000802870932
> -0.000000000000
> -0.001041888331
> 0.000768540238
> 0.000930750510
> -0.001834127637
> 0.000000000000
> 0.002708566451.......

Those coefs struck me as oddly small too, which is what led me to look
for symmetry - instead of symmetry, I saw the dots. Presumably, he has
more coefs, and they get larger.

--
Jim Thomas Principal Applications Engineer Bittware, Inc
[email protected] http://www.bittware.com (703) 779-7770
To mess up a Linux box, you need to work at it; to mess up your Windows
box, you just need to work on it. - Scott Granneman

Randy Yates
11-26-2003, 01:17 AM
Jim Thomas <[email protected]> wrote in message news:<[email protected]>...
> Randy Yates wrote:
> > For these particular coefficients, Q15 isn't
> > very appropriate. Even the largest coefficient
> > would only be the integer value 89 - a very
> > high coefficient quantization error.
> >
> > Try Q23, i.e., multiply all real coefficients by
> > 2^23 to get the integer-valued coefficients.
>
> Randy,
>
> I'm not sure the OP listed all the coefficients. In the original post,
> the list of coefs was followed by something akin to an ellipsis:
>
> > -0.000467744403
> > 0.000802870932
> > -0.000000000000
> > -0.001041888331
> > 0.000768540238
> > 0.000930750510
> > -0.001834127637
> > 0.000000000000
> > 0.002708566451.......
>
> Those coefs struck me as oddly small too, which is what led me to look
> for symmetry - instead of symmetry, I saw the dots. Presumably, he has
> more coefs, and they get larger.

Hey Jim,

Good point - I hadn't noticed the dots or the "values like" phrase.

Hey Jack, can you give us all your coefficients?

Actually, we need to know your machine architecture (especially
the accumulator length) as well if you want to avoid overflow
while accumulating. Or, better yet, read my paper on the subject
and you can learn how to do it yourself.

http://home.earthlink.net/~yatescr/fir.pdf

--Randy

jack kilby
11-26-2003, 11:40 AM
Hello all,
Thanks for all of your responses.Kindly look in to the coeefficients
and help me cross the river.a of now i work like this
datain = 15 bits
1 input to multiplier (from the data)= 15 bits
2 input to multiplier (from coeff) = 10 bits (i multiply by 2 power
10)
output of multiplier = 25 bits
input to accumulato =25 bits
i finally take the last 16 bits out....



input ----> multiplier ----> accumulator ----- > output

-5.190235e-004
7.013896e-004
4.266952e-004
-1.029301e-003
-2.968241e-004
1.574129e-003
-2.264815e-005
-2.327546e-003
7.114860e-004
3.198614e-003
-1.948620e-003
-4.004581e-003
3.880218e-003
4.471644e-003
-6.589314e-003
-4.243290e-003
1.007195e-002
2.889538e-003
-1.422408e-002
9.683918e-005
1.884194e-002
-5.346749e-003
-2.363674e-002
1.377756e-002
2.826236e-002
-2.710135e-002
-3.235257e-002
4.962334e-002
3.556310e-002
-9.729160e-002
-3.761264e-002
3.153014e-001
5.383093e-001
3.153014e-001
-3.761264e-002
-9.729160e-002
3.556310e-002
4.962334e-002
-3.235257e-002
-2.710135e-002
2.826236e-002
1.377756e-002
-2.363674e-002
-5.346749e-003
1.884194e-002
9.683918e-005
-1.422408e-002
2.889538e-003
1.007195e-002
-4.243290e-003
-6.589314e-003
4.471644e-003
3.880218e-003
-4.004581e-003
-1.948620e-003
3.198614e-003
7.114860e-004
-2.327546e-003
-2.264815e-005
1.574129e-003
-2.968241e-004
-1.029301e-003
4.266952e-004
7.013896e-004
-5.190235e-004


thanks
jack


[email protected] (Randy Yates) wrote in message news:<[email protected]>...
> Jim Thomas <[email protected]> wrote in message news:<[email protected]>...
> > Randy Yates wrote:
> > > For these particular coefficients, Q15 isn't
> > > very appropriate. Even the largest coefficient
> > > would only be the integer value 89 - a very
> > > high coefficient quantization error.
> > >
> > > Try Q23, i.e., multiply all real coefficients by
> > > 2^23 to get the integer-valued coefficients.
> >
> > Randy,
> >
> > I'm not sure the OP listed all the coefficients. In the original post,
> > the list of coefs was followed by something akin to an ellipsis:
> >
> > > -0.000467744403
> > > 0.000802870932
> > > -0.000000000000
> > > -0.001041888331
> > > 0.000768540238
> > > 0.000930750510
> > > -0.001834127637
> > > 0.000000000000
> > > 0.002708566451.......
> >
> > Those coefs struck me as oddly small too, which is what led me to look
> > for symmetry - instead of symmetry, I saw the dots. Presumably, he has
> > more coefs, and they get larger.
>
> Hey Jim,
>
> Good point - I hadn't noticed the dots or the "values like" phrase.
>
> Hey Jack, can you give us all your coefficients?
>
> Actually, we need to know your machine architecture (especially
> the accumulator length) as well if you want to avoid overflow
> while accumulating. Or, better yet, read my paper on the subject
> and you can learn how to do it yourself.
>
> http://home.earthlink.net/~yatescr/fir.pdf
>
> --Randy

Randy Yates
11-27-2003, 01:46 AM
jack kilby wrote:
> Hello all,
> Thanks for all of your responses.Kindly look in to the coeefficients
> and help me cross the river.a of now i work like this
> datain = 15 bits
> 1 input to multiplier (from the data)= 15 bits
> 2 input to multiplier (from coeff) = 10 bits (i multiply by 2 power
> 10)
> output of multiplier = 25 bits
> input to accumulato =25 bits
> i finally take the last 16 bits out....

Hi Jack,

If the coefficients are only 10 bits long, then multiplying the
real coefficients below by 1024 (2^10) will overflow the largest
one:

round(0.538 * 1024) = 551.

The largest value you can represent with a signed, two's complement
10-bit number is 511.

Perhaps this is your problem?

--Randy

>
>
>
> input ----> multiplier ----> accumulator ----- > output
>
> -5.190235e-004
> 7.013896e-004
> 4.266952e-004
> -1.029301e-003
> -2.968241e-004
> 1.574129e-003
> -2.264815e-005
> -2.327546e-003
> 7.114860e-004
> 3.198614e-003
> -1.948620e-003
> -4.004581e-003
> 3.880218e-003
> 4.471644e-003
> -6.589314e-003
> -4.243290e-003
> 1.007195e-002
> 2.889538e-003
> -1.422408e-002
> 9.683918e-005
> 1.884194e-002
> -5.346749e-003
> -2.363674e-002
> 1.377756e-002
> 2.826236e-002
> -2.710135e-002
> -3.235257e-002
> 4.962334e-002
> 3.556310e-002
> -9.729160e-002
> -3.761264e-002
> 3.153014e-001
> 5.383093e-001
> 3.153014e-001
> -3.761264e-002
> -9.729160e-002
> 3.556310e-002
> 4.962334e-002
> -3.235257e-002
> -2.710135e-002
> 2.826236e-002
> 1.377756e-002
> -2.363674e-002
> -5.346749e-003
> 1.884194e-002
> 9.683918e-005
> -1.422408e-002
> 2.889538e-003
> 1.007195e-002
> -4.243290e-003
> -6.589314e-003
> 4.471644e-003
> 3.880218e-003
> -4.004581e-003
> -1.948620e-003
> 3.198614e-003
> 7.114860e-004
> -2.327546e-003
> -2.264815e-005
> 1.574129e-003
> -2.968241e-004
> -1.029301e-003
> 4.266952e-004
> 7.013896e-004
> -5.190235e-004
>
>
> thanks
> jack
>
>
> [email protected] (Randy Yates) wrote in message news:<[email protected]>...
>
>>Jim Thomas <[email protected]> wrote in message news:<[email protected]>...
>>
>>>Randy Yates wrote:
>>>
>>>>For these particular coefficients, Q15 isn't
>>>>very appropriate. Even the largest coefficient
>>>>would only be the integer value 89 - a very
>>>>high coefficient quantization error.
>>>>
>>>>Try Q23, i.e., multiply all real coefficients by
>>>>2^23 to get the integer-valued coefficients.
>>>
>>>Randy,
>>>
>>>I'm not sure the OP listed all the coefficients. In the original post,
>>>the list of coefs was followed by something akin to an ellipsis:
>>>
>>> > -0.000467744403
>>> > 0.000802870932
>>> > -0.000000000000
>>> > -0.001041888331
>>> > 0.000768540238
>>> > 0.000930750510
>>> > -0.001834127637
>>> > 0.000000000000
>>> > 0.002708566451.......
>>>
>>>Those coefs struck me as oddly small too, which is what led me to look
>>>for symmetry - instead of symmetry, I saw the dots. Presumably, he has
>>>more coefs, and they get larger.
>>
>>Hey Jim,
>>
>>Good point - I hadn't noticed the dots or the "values like" phrase.
>>
>>Hey Jack, can you give us all your coefficients?
>>
>>Actually, we need to know your machine architecture (especially
>>the accumulator length) as well if you want to avoid overflow
>>while accumulating. Or, better yet, read my paper on the subject
>>and you can learn how to do it yourself.
>>
>>http://home.earthlink.net/~yatescr/fir.pdf
>>
>>--Randy


--
% Randy Yates % "...the answer lies within your soul
%% Fuquay-Varina, NC % 'cause no one knows which side
%%% 919-577-9882 % the coin will fall."
%%%% <[email protected]> % 'Big Wheels', *Out of the Blue*, ELO
http://home.earthlink.net/~yatescr

Fred Marshall
11-27-2003, 04:36 AM
"Randy Yates" <[email protected]> wrote in message
news:[email protected] link.net...
> jack kilby wrote:
> > Hello all,
> > Thanks for all of your responses.Kindly look in to the coeefficients
> > and help me cross the river.a of now i work like this
> > datain = 15 bits
> > 1 input to multiplier (from the data)= 15 bits
> > 2 input to multiplier (from coeff) = 10 bits (i multiply by 2 power
> > 10)
> > output of multiplier = 25 bits
> > input to accumulato =25 bits
> > i finally take the last 16 bits out....
>
> Hi Jack,
>
> If the coefficients are only 10 bits long, then multiplying the
> real coefficients below by 1024 (2^10) will overflow the largest
> one:
>
> round(0.538 * 1024) = 551.
>
> The largest value you can represent with a signed, two's complement
> 10-bit number is 511.
>
> Perhaps this is your problem?

So, scale the coefficients by 511/0.538 = 949.8141264 or some other similar
number that might minimize the error in the coefficients or to directly
minimize the error in the filter response.

Fred

Randy Yates
11-27-2003, 02:17 PM
Fred Marshall wrote:

> "Randy Yates" <[email protected]> wrote in message
> news:[email protected] link.net...
>
>>jack kilby wrote:
>>
>>>Hello all,
>>> Thanks for all of your responses.Kindly look in to the coeefficients
>>>and help me cross the river.a of now i work like this
>>>datain = 15 bits
>>>1 input to multiplier (from the data)= 15 bits
>>>2 input to multiplier (from coeff) = 10 bits (i multiply by 2 power
>>>10)
>>>output of multiplier = 25 bits
>>>input to accumulato =25 bits
>>>i finally take the last 16 bits out....
>>
>>Hi Jack,
>>
>>If the coefficients are only 10 bits long, then multiplying the
>>real coefficients below by 1024 (2^10) will overflow the largest
>>one:
>>
>> round(0.538 * 1024) = 551.
>>
>>The largest value you can represent with a signed, two's complement
>>10-bit number is 511.
>>
>>Perhaps this is your problem?
>
>
> So, scale the coefficients by 511/0.538 = 949.8141264 or some other similar
> number that might minimize the error in the coefficients or to directly
> minimize the error in the filter response.

Ayup - that would fix it.
--
% Randy Yates % "...the answer lies within your soul
%% Fuquay-Varina, NC % 'cause no one knows which side
%%% 919-577-9882 % the coin will fall."
%%%% <[email protected]> % 'Big Wheels', *Out of the Blue*, ELO
http://home.earthlink.net/~yatescr