simple Low pass filter code

Discussion in 'Embedded Systems and Microcontrollers' started by gary1wang, Oct 25, 2011.

  1. gary1wang

    Thread Starter Member

    Sep 18, 2008
    23
    0
    Hi, This is a simple low pass filter code, i am not sure how well it works, it seems really depends on value of first input in the input array input[0]. and value of u. i am not sure what is the best value for the constant in u = t / (t +constant); and also do you have any recommandation to improve it. Thanks.

    #include <iostream>
    #include<math.h>
    using namespace std;

    int main()
    {
    double t=10;
    double u=0;
    u = t / (t +constant);

    double input[10]={1, 1.05, 1.11, 1.2, 1, 1.21, 1.01, 1.02, 1, 1.44};
    double output[10]={0 ,0, 0 ,0 ,0, 0, 0, 0, 0, 0 };
    double o;
    o=(1.2+1.05+1.11+1.2+ 1+1.21+1.01+1.02+ 1+ 1.44)/10;
    output[0] = input[0];
    cout<<u <<endl;
    for(int i=1;i<10;i++)
    {

    output =u*(input - output[i-1]) + output[i-1];
    cout<<i<<" i "<<output<<endl;

    }
    cout<<output[9]<<endl;
    cout<<o<<endl;


    return 0;
    }
     
Loading...