DSPRelated.com
Forums

FIR filter in 8051 micro

Started by rome...@gmail.com October 30, 2007
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. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
webmasterpdx <webmasterpdx@gmail.com> 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.
Well, a large fraction of DSP is done in 16 bit fixed point. In that case, double precision might be 32 bit fixed point, not so hard to do on an 8051. Floating point in any precision is probably not the best choice for DSP on an 8 bit processor. -- glen
glen herrmannsfeldt wrote:
> webmasterpdx <webmasterpdx@gmail.com> 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. > > Well, a large fraction of DSP is done in 16 bit fixed point. > In that case, double precision might be 32 bit fixed point, not so > hard to do on an 8051. Floating point in any precision is probably > not the best choice for DSP on an 8 bit processor.
As far as I remember, the 8051 doesn't have a carry test. (But there's always a way ...) Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
On Oct 20, 4:10&#4294967295;pm, Jerry Avins <j...@ieee.org> wrote:
> glen herrmannsfeldt wrote: > > webmasterpdx <webmaster...@gmail.com> 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. > > > Well, a large fraction of DSP is done in 16 bit fixed point. > > In that case, double precision might be 32 bit fixed point, not so > > hard to do on an 8051. &#4294967295;Floating point in any precision is probably > > not the best choice for DSP on an 8 bit processor. > > As far as I remember, the 8051 doesn't have a carry test. (But there's > always a way ...)
does it have an Add with Carry instruction? maybe the OP's sample rate is real slow. r b-j
Yeah, I know it's an old post, but I want to help anyone who might
come across that to know that this kind of stuff is possible. It does
take a pragmatic approach. One area I try to evangelize is that I see
a lot of newer engineers coming out of university with experience
using XSCALE processors and PCs with unlimited resources and often
these people never lived in the age of the slow mainframes, slow CPU
modules or even slow CPUs. Mostly it's about prices and time to
market. As a result, we often have to get very creative with what we
have, and if we can do something with a $1 uP instead of a $10 DSP or
$30 XSCALE, then we should go for the $1 uP.

Of course when you play with new algorithms you invent, by all means
simulate it. I simulated the filter before using it both on my TI-86
and then later in C (where I could simulate 8-bit calculations) and
gnuplot to plot the results. I created input signals that were
combinations of sine waves at different frequencies added up, and the
results were pretty darn accurate. Not the perfect simulation, but
good enough for me. Then in the prototype product, it worked just
fine.

Coming up with clever ways to measure and condition our signals forms
the core of innovation in small embedded projects as they usually
involve measuring some quantity to give results that can be used
elsewhere.

e.g. If using a uP with a crystal clock, the most accurate measurement
you can make is that of time (width of a pulse), so if you want to
measure capacitance or inductance, tying that to a circuit that
measures rise time will give you much better results than trying to
measure the quantity itself.
Another example, if not unusual.....I was tasked with measuring
velocity of rollerblades. The problem was that using light was a
problem due to mud, etc, being thrown up. So, instead we measured
sound and autocorrellation. The idea being that the front blades will
go over the same bumps as the back blades, so an autocorrelation
should show a bump for each wheel, so if you know the distance between
the wheels you can determine the velocity. It wasn't quite that simple
and there are faster ways of doing autocorrelations than a multiply
accumulate (average minimum differences) that only involves subtracts
and adds. Bottom line, the technique worked.

I guess what I'm saying is that you can often (more often than people
realize) do it with a PIC or 8051, just as well as with an XSCALE or
full DSP, and I encourage people to do that when possible. Thats all.
Of course, there are occasions when you do need double precisions (ill
conditioned equations, etc, etc), but these, for me, are last
resorts...

Thx
-D
On 21-10-2009 at 11:19:22 webmasterpdx <webmasterpdx@gmail.com> wrote:

What you are describing
is in my country called engineering
and so called "inventions"
are just called in my country
basic knowledge and thinking.
And what you did with coefficients is called scalling
(more or less).

There is absolutely nothing exciting
and nothing unusual
in such everyday work.
It takes 2-3 yrs to become such inventor :).

-- 
Mikolaj
Mikolaj wrote:
> On 21-10-2009 at 11:19:22 webmasterpdx <webmasterpdx@gmail.com> wrote: > > What you are describing > is in my country called engineering > and so called "inventions" > are just called in my country > basic knowledge and thinking. > And what you did with coefficients is called scalling > (more or less). > > There is absolutely nothing exciting > and nothing unusual > in such everyday work. > It takes 2-3 yrs to become such inventor :).
Nevertheless, the approach is rare enough to be admired anywhere in the world. I come from an industry where redesigning a circuit to make it a penny cheaper without reducing performance -- often performance was actually improved -- would bring a substantial bonus at year's end. Jerry -- Engineering is the art of making what you want from things you can get. &macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;