hi,
I want to implement 5th order butterworth 100 mHz lowpass iir filter in arduino. Firstly i ve used matlab sptool for design. Then i found transfer function coefficients of this filter. now, using this coefficients I have to implement the software filter in arduino.
But I didn't do this properly. This is the code I ve written;
float filter( float x) {
float v[6];
for(int i=0; i <= 5; i++)
v[i]=0.0;
v[0] = v[1];
v[1] = v[2];
v[2] = v[3];
v[3] = v[4];
v[4] = v[5];
v[5] = (1.282581078961e-3 * x)
+ ( 0.1254306222 * v[0])
+ ( -0.8811300754 * v[1])
+ ( 2.5452528683 * v[2])
+ ( -3.8060181193 * v[3])
+ ( 2.9754221097 * v[4]);
return
(v[0] + v[5])
+5 * (v[1] + v[4])
+10 * (v[2] + v[3]);
}
float analog=A0,output=A1;
float voltage,x,y;
void setup () {
Serial.begin(9600);
//Serial1.begin(19200);
}
void loop() {
x=0.0;
x=analogRead(analog);
voltage=(x/1023.0)*5.0;
//Serial.println(voltage);
output=filter(x);
Serial.println(output);
}