PDA

View Full Version : FIR filter / how to do efficient math


Jcadwell
06-01-05, 08:00 PM
Greetings.

My current question revolves around implementing a 21 term FIR filter on a sampled input from the A/D on the MINPOD.

I've created 21 variables (primarily because I don't understand stacks) and am trying to find a way to sum each of those variables multiplied by a scalar. The system refreshes each variable with the one before it every time the A/D is sampled.


This looks like...

DATA20@
.
.
.
DATA2 @
DATA3 !
DATA1 @
DATA2 !
DATA0 @
DATA1 !

I need a sum of all terms, each multiplied by a scalar. I don't want to alter the value of each term.

Ouput = (DATA0 @)*(n) + (DATA1 @)*(n-1) ..... + (DATA20 @)*(n-20)

Is there a convenient way to do this or do I have to do it one term at a time?

Thanks.

Pacetech
06-28-05, 03:14 PM
Do loops are your friend.

You probably want to implement a circular buffer so you are not moving the data all the time, just incrementing the buffer pointer, looking for over-runs, etc.

You can do a sum like this

: SUMITUP ( -- single )
0 \ Put zero on stack so we can add to it for running total
21 0 DO \ Loop from 0 to 20
\ Fetch the data value from circular buffer
\ Fetch the scalar
* \ Multiply the data value with the scalar
+ \ Keep running total
LOOP
;

You will have to fill in the blanks, depending on how you do the circular buffer and the scaler array.