Linear phase Notch filter / Band reject filter implementation in C++
You can implement a simple recursive filter to process blocks of samples like this:



void filter(const int *x, int *y, int n)
{
    static float x_2 = 0.0f;                    // delayed x, y samples
    static float x_1 = 0.0f;
    static float y_2 = 0.0f;
    static float y_1 = 0.0f;

    for (i = 0; i &lt; n; ++i)
    {
        y[i] = a0 * x[i] + a1 * x_1 + a2 * x_2  // IIR difference equation
                         + b1 * y_1 + b2 * y_2;
        x_2 = x_1;                              // shift delayed x, y samples
        x_1 = x[i];
        y_2 = y_1;
        y_1 = y[i];
    }
}


Notch filter coefficients a0, a1, a2, b1, b2 can be calculated using eq 19-8 on this page: http://dspguide.com/ch19/3.htm