ted:
Hello
How to implement this program to stm32f103#define NZEROS 16
#define NPOLES 16
#define GAIN 2.733054109e+10static 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] = xv[5]; xv[5] = xv[6]; xv[6] = xv[7]; xv[7] = xv[8]; xv[8] = xv[9]; xv[9] = xv[10]; xv[10] = xv[11]; xv[11] = xv[12]; xv[12] = xv[13]; xv[13] = xv[14]; xv[14] = xv[15]; xv[15] = xv[16];
xv[16] = next input value / GAIN;
yv[0] = yv[1]; yv[1] = yv[2]; yv[2] = yv[3]; yv[3] = yv[4]; yv[4] = yv[5]; yv[5] = yv[6]; yv[6] = yv[7]; yv[7] = yv[8]; yv[8] = yv[9]; yv[9] = yv[10]; yv[10] = yv[11]; yv[11] = yv[12]; yv[12] = yv[13]; yv[13] = yv[14]; yv[14] = yv[15]; yv[15] = yv[16];
yv[16] = (xv[0] + xv[16]) - 8 * (xv[2] + xv[14]) + 28 * (xv[4] + xv[12])
- 56 * (xv[6] + xv[10]) + 70 * xv[8]
- ( -0.9999996903 * yv[0]) + ( 15.0671415160 * yv[1])
- (-107.3207279400 * yv[2]) + (479.5899447000 * yv[3])
- (-1504.6930028000 * yv[4]) + (3514.0764694000 * yv[5])
- (-6318.5794832000 * yv[6]) + (8922.2254164000 * yv[7])
- (-9998.7316198000 * yv[8]) + (8922.2257618000 * yv[9])
- (-6318.5799724000 * yv[10]) + (3514.0768775000 * yv[11])
- (-1504.6932358000 * yv[12]) + (479.5900375300 * yv[13])
- (-107.3207528700 * yv[14]) + ( 15.0671455990 * yv[15]);
next output value = yv[16];
}
}
couple of things:
you may want to change "#define GAIN 2.733054109e+10" to "const double GAIN 2.733054109e+10"
//double - >8 byte -> 2.3E-308 to 1.7E+308 ->15 decimal places
//define is usually 2 bytes long max value of 65 535 (unsigned)
secondly, I'm assuming that "next input value" will be be likely a analog read.
so ignoring PaulS not so helpful comment, you can implement this code as follows for in arduino sketch:
void setup(){
// initailise you inputs/ serial comms etc
}
void loop(){
//put the content of the for loop here. replace "next input value" with analogRead(1) for example if you a reading from A1 (assuming arduino UNO here)
}
Also may be sensible to put all the decimal constants you are using as const double global variables (just in case the complier does something funny with them)