I am going through a program with zero comments. This is a signal filter, and I would like to know which type this is So far I have this: arrays (lengths = order):
- X: contains previous filter input values
- Y: contains previous filter output values
- A: contains coeficients
- B: contains coeficients
Filter steps:
formula roughly: OUT = SUM(i=0 to order)( X[i]*B[i] - Y[i]*A[i])
shifting the window: all X's and Y's move one position, removing the oldest values and the new input and output value are added.
I tried googling which kind of filter this is, but I am a bit stuck, especially the feedback of the previous outputs is something I did not see before (I only used very very simple filters before).
source:
`float_type floatFilter::addPoint(float_type P)
{
//P is sample value`
if (_pfilterCoefs == NULL) return P;
//
if (_reset)
{
for (uint16_t i=0;i<_pfilterCoefs->order;i++)
{
*(_Ys+i)= _pfilterCoefs->lowpass ? P : 0;
*(_Xs+i)= _pfilterCoefs->lowpass ? P : 0;
}
_reset=false;
}
//calculate output
float_type Y = ((*_pfilterCoefs->Bs)) * P;
for (uint16_t i=0; i<_pfilterCoefs->order; i++)
{
Y+=(*(_Xs+i)) * (*(_pfilterCoefs->Bs + (_pfilterCoefs->order-i))) -
(*(_Ys+i)) * (*(_pfilterCoefs->As + (_pfilterCoefs->order-1-i)));
}
//move filter one step (
for (uint16_t i = 0; i<(_pfilterCoefs->order-1);i++)
{
*(_Ys+i)=*(_Ys+i+1);
*(_Xs+i)=*(_Xs+i+1);
}
*(_Xs + _pfilterCoefs->order - 1) = P; //the most recent input is added in the end
*(_Ys + _pfilterCoefs->order - 1) = Y; //the most recent output is added in the end
return *(_Ys + _pfilterCoefs->order-1); //this is the most recent output.