This part isn't correct:
float filter( float x) {
float v[6];
for(int i=0; i <= 5; i++)
v[i]=0.0;
You declare new array each time when you passing new value, so all history is lost. I think you should declare v[6] as global and remove "for" initializing loop.