title: How to implement an FIR filter in C to process one sample at a time
body: <p>The following code is for the implementation of a real-time FIR filter was taken from a DSP textbook. However, I would like to process one sample at a time, produce the corresponding output then move on to the next sample in real-time. Should I append each new sample to the input array or is there another way to do this?</p>
  
  <pre><code>        /*====================================================
        Dig_FIR_Filt_RT() - filters input array using FIR
        coefs (uses real-time code)
        Prototype: void Dig_FIR_Filt_RT(int *X,int *Y,
        double *M,double *C,int numb_coefs,int N);
        Return: error value.
        Arguments: X - ptr to input array
        Y - ptr to output array
        M - ptr to memory array
        C - ptr to coefs array
        numb_coefs - number of coefficients
        N - number of values in array
        ====================================================*/
        void Dig_FIR_Filt_RT(int *X,int *Y,double *M,double *C
        ,int numb_coefs,int N)
        { int *x,*y, /* ptrs to in/out arrays */
            i,j; /* loop counters */
            double *c,*m1,*m2, /* ptrs to coef/memory array */
            o; /* output value */
            /* Make copies of input and output pointers */
            x = X;
            y = Y;
            /* Start loop for number of data values */
            for(i = 0; i &lt; N ;i++)
            { /* Make copy of pointers and start loop */
            M[numb_coefs-1] = *x++;
            c = C;
            m1 = m2 = M;
            o = *m1++ * *c++;
            /* Use convolution method for computation */
            for(j = 1; j &lt; numb_coefs ;j++)
            { *m2++ = *m1;
            o += *m1++ * *c++;
            }
            /* Multiply by gain, convert to int and store */
            o *= *c;
            *y++ = (int)ceil(o-0.5);
            }
        }
  </code></pre>