2

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.
lode
  • 504
  • 6
  • 21
  • `_pfilterCoefs->lowpass` Lowpass maybe? – HolyBlackCat Aug 17 '17 at 19:18
  • this might help https://www.dsprelated.com/freebooks/filters/Finding_Frequency_Response.html – 463035818_is_not_an_ai Aug 17 '17 at 19:21
  • 1
    Off topic: `_Xs` and `_Ys` bad idea. underscore+Capital letter is reserved for use by the implementation. More here: [What are the rules about using an underscore in a C++ identifier?](https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier) – user4581301 Aug 17 '17 at 19:29
  • 2
    A filter with feedback is called an IIR (Infinite Impulse Response) filter. See https://learn.mikroe.com/ebooks/digitalfilterdesign/chapter/introduction-iir-filter/ for example. – Mark Ransom Aug 17 '17 at 19:31
  • Thanks Marc, that's all I needed to get me started. If you add it as a solution, I will mark it solved. – lode Aug 17 '17 at 19:57

0 Answers0