Click to See Complete Forum and Search --> : Digital filtering help?


martini1
April 2nd, 2009, 06:51 PM
Help regarding digital signal processing...

I think I've been using an IIR instead of a FIR to filter accelerometer readings in my embedded system. The reason being that...

The filtering routine takes a new ADC reading and stores it in element[0] of the filter storage array. Then it takes the previous 9 stored elements, adds them together with element[0] and copies the resulting average back into element[0]. So, when we re-enter the filter routine, to process the next new reading we are using previously filtered outputs.

Now, it is my belief that the difference between IIR and FIR is that IIR uses previously filtered outputs in the equation. Am I correct in thinking that I'm using an IIR?

Code:

//Digital low pass filter to process X,Y and Z accel readings
Int16U filterReading(float* pFilter, Int16U adcr)
**
Int8U i; //Loop counter variable

//Shift values along to make room for new readings
for(i = 0; i < (MAX_FILTER_STORE - 1); i++)
**
pFilter[i + 1] = pFilter[i];
}
//Place the new reading in the first element of partition
pFilter[0] = (adcr * 0.1);

//Loop to process reading with an average weighting
for(i = 1; i < MAX_FILTER_STORE; i++)
**
pFilter[0] += (pFilter[i] * 0.1);
}
//Return modified reading
return (Int16U)pFilter[0];
}

mgrey
April 3rd, 2009, 09:00 AM
Somehing not related to the original question, but a warning about your code. The following
//Shift values along to make room for new readings
for(i = 0; i < (MAX_FILTER_STORE - 1); i++)
{
pFilter[i + 1] = pFilter[i];
}does not shift values along the array. It sets pFilter[0] value to all the elements of the array.

martini1
April 3rd, 2009, 10:42 AM
Good point - thanks! Can't believe I let that one slip.