Re: FIR filter in 8051 micro



webmasterpdx wrote:
First, filtering using an embedded 8-bit micro is possible. Ignore people
who are talking double precision, etc, etc....they aren't embedded people
with experience in this area. I have invented an algorithm that works well
on a PIC (8-bit also). I call it the "tri-band filter". I had a situation
where I had to generate a measure of the power spectrum in 3 bands in an
audio spectrum of a piano (about 4.5KHz). So, I took 32 samples at a time
(I was limted by memory) and ran a FIR filter on the data. I basically
chose a FIR filter of the form ax0+bx1+cx2 and centered it at the midpoint
of my frequency range. My sample rate was twice the highest frequency (by
Nyquist).
Now, I used some online filter coefficient generator. What I noticed is
the LPF coefficients were the same as the HPF coefficients just swapping
signs here and there, so as long as I calculated ax0, bx1 and cx2, I could
use the same calculations for both filters. The second trick I used was to
round any floating point values to the nearest powers of two. For example,
one term was 0.3664, and I rounded it to 0.375 (3/8*x), which can be
calculated as ((x << 2) + x) >> 3, which involves no multiplies (my PIC
didn't have a multiply) and only involves integer calculations. Note that
the frequency response of the filter (if you choose your coefficients
carefully) was almost identical to the non-altered one and my results were
very accurate (much better than my older state variable filter that I used
to use). If you combine the touching of coords to be combinations of power
of two so you can do your calculations using shifts and adds and reuse
coefficients to give you both High and Low pass results simultaneously. The
band pass was obtained by subtracting the LPF and HPF values from the
original data. You will need to use a 16 bit accumulator (assuming you are
using 8-bit sampled data) and remember to shift left and add BEFORE
shifting right as you'll get more accurate results that way.
This algorithm works very well for 8-bit processors.
Enjoy...

You do realize that this is a year-old thread? Whatever, you seem like the kind of pragmatic programmer I admire.

Jerry
--
Engineering is the art of making what you want from things you can get.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
.