Lynn's integer filter has a linearly increasing trend I have a PPG signal sampled at 50Hz and I want to filter the signal using Lynn's integer filter. I.e 

\begin{equation}
  H(z)=\frac{(1-1/z^m)^2}{(1-1/z)^2}
\end{equation}

Cutoff frequency is 5Hz, so this gives value of $m \approx 3 $ (it's a 3db cutoff) and hence the difference equation is 

\begin{equation}
y[n]-2y[n-1]+y[n-2]=x[n]-2x[n-3]+x[n-6] 
\end{equation}

Now applying this filter to the signal, my signal is filtered but there is some linear component that's making baseline to increase linearly.



Any suggestion where I am going wrong? 

Data is processed on cortex M0 based bluetooth module and transmitted to phone. I am plotting csv file in Matlab. 

Code of cortex M0:

float process_ppg_iir(uint16_t raw_data_ppg)
{
    int b0=1, b1=-2, b2=1, a1=-2; 
    int a2 = 1;

    if( global_sample_counter &lt;= 7-1 )
    {
        ppg_raw[global_sample_counter] = raw_data_ppg;
        if(global_sample_counter &lt;=3-1)
        ppg_processed[global_sample_counter] = raw_data_ppg;
        global_sample_counter++;
    }
    else
    {
        // sfit values to left

        int i=0;

        for(i=0 ;i &lt;=5;i++)
        {
            ppg_raw[i] = ppg_raw[i+1];
        }

        ppg_processed[0] = ppg_processed[1];
        ppg_processed[1] = ppg_processed[2];

        ppg_raw[6] = raw_data_ppg;
        ppg_processed[2] = (b0*ppg_raw[6]+b1*ppg_raw[3]+b2*ppg_raw[0])- a1*ppg_processed[1]-a2*ppg_processed[0];

    }
        return ppg_processed[2];    
}
Your lowpass filter is the cascade of two 3-point moving average filters each implemented as recursive running sum filters. (It's gain at 5 Hz is -2.4 dB.) I can't interpret your code but I'm guessing your feedback operations are incorrect. To test your code, make sure all accumulator variables are set to zero. Then apply a unit impulse to your filter and see if its impulse response is [1, 2, 3, 2, 1, 0, 0, 0, ...] as it should be.  If you change your $H(z)$ exponents from $2$ to $1$, then your filter's impulse response should be [1, 1, 1, 0, 0,0,  ...]. If your impulse responses do not agree with the above, then finding out why they don't will solve your problem.