piclist 2002\09\20\014057a >
Thread: Challenge: FIR Filter on an 18f series device
face BY : Scott Dattalo email (remove spam text)

An FIR filter, or finite impulse response filter, is a fancy name for a
dot product between two vectors. Or in C:

 sum = 0;
 for(i=0; i<LENGTH; i++)
   sum = sum + weights[i] * data[i];

In other words, you have two arrays "weights" and "data". They're
multiplied together element by element and the resulting products are
added together.

Now the challenge is this:

 Suppose the filter weights and the data samples are 8-bit numbers stored
in RAM. The filter weights started off as constants, but since you were
clever, you mixed the calibration data with filter weights. The data
resides in a circular buffer. Suppose the FIR filter has 8 taps (i.e.
there are 8 elements in the Weights vector) and that the circular data
buffer can hold 16 samples.

How efficiently can this be implemented in assembly:

#define FIR_WEIGHTS       8
#define MAX_DATA_SAMPLES  16

char weights[FIR_WEIGHTS];
char data_buffer[MAX_DATA_SAMPLES];
char data_index; /* points to most recently received data sample */

int fir(void)
 char i,j;

 j  = data_index - FIR_WEIGHTS;
 if(j < 0)
   j = j + MAX_DATA_SAMPLES;

 sum = 0;
 for(i=0; i<FIR_WEIGHTS; i++) {

   sum = sum + weights[i] * data_buffer[j];
   j = j + 1;
   if(j >= MAX_DATA_SAMPLES)
     j = 0;


 return sum;



PS. I see 8 instructions for initialization and 12 for a loop and about 128
cycles total.

http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


See also: www.piclist.com/techref/microchip/math/filter.htm?key=filter
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Challenge: FIR Filter on an 18f series device

month overview.

new search...