Skip to content

Conversation

@wfg666
Copy link

@wfg666 wfg666 commented Mar 1, 2019

This tool helped me a lot. But the generated ANSI C code is like this:

/* Digital filter designed by mkfilter/mkshape/gencode   A.J. Fisher
   Command line: /www/usr/fisher/helpers/mkfilter -Bu -Lp -o 4 -a 8.0000000000e-02 0.0000000000e+00 -l */

#define NZEROS 4
#define NPOLES 4
#define GAIN   4.474489752e+02

static float xv[NZEROS+1], yv[NPOLES+1];

static void filterloop()
  { for (;;)
      { xv[0] = xv[1]; xv[1] = xv[2]; xv[2] = xv[3]; xv[3] = xv[4]; 
        xv[4] = next input value / GAIN;
        yv[0] = yv[1]; yv[1] = yv[2]; yv[2] = yv[3]; yv[3] = yv[4]; 
        yv[4] =   (xv[0] + xv[4]) + 4 * (xv[1] + xv[3]) + 6 * xv[2]
                     + ( -0.2644548164 * yv[0]) + (  1.4034846714 * yv[1])
                     + ( -2.8673991091 * yv[2]) + (  2.6926109870 * yv[3]);
        next output value = yv[4];
      }
  }

which is not compilable. I edited the ANSI C generator and the code is like this:

/* Digital filter designed by mkfilter/mkshape/gencode   A.J. Fisher
   Command line: ./mkfilter -Bu -Lp -o 4 -a 8.0000000000e-02 0.0000000000e+00 -l */

static float filterloop(float next_input_value)
{
    const int NZEROS = 4;
    const int NPOLES = 4;
    const float GAIN = 4.474489752e+02;

    static float xv[NZEROS+1], yv[NPOLES+1];

    xv[0] = xv[1]; xv[1] = xv[2]; xv[2] = xv[3]; xv[3] = xv[4]; 
    xv[4] = next_input_value / GAIN;
    yv[0] = yv[1]; yv[1] = yv[2]; yv[2] = yv[3]; yv[3] = yv[4]; 
    yv[4] =   (xv[0] + xv[4]) + 4 * (xv[1] + xv[3]) + 6 * xv[2]
                     + ( -0.2644548164 * yv[0]) + (  1.4034846714 * yv[1])
                     + ( -2.8673991091 * yv[2]) + (  2.6926109870 * yv[3]);
    return yv[4];
}

Copy link
Owner

@MikeCurrington MikeCurrington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for the fix - much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants