#include "FIR_LTE.h"

void fir(idata_t in_real, idata_t in_imag, odata_t *out_real, odata_t *out_imag)
{
    static const Coeff coeff[] =
    {
        #include "LTE_coeff.dat"
    };

    //Clear values.
    static idata_t shift_reg_real[N];
    static idata_t shift_reg_imag[N];
    Acc_real acc_real = 0;
    Acc_imag acc_imag = 0;

    //Get input data.
    shift_reg_real[0] = in_real;
    shift_reg_imag[0] = in_imag;

    //Multiply through. Take advantage of symmetry.
    AccumLoop:
    for (int i = 0; i < N/2; i++)
    {
        acc_real += coeff[i]*(shift_reg_real[i] + shift_reg_real[N-1-i]);
        acc_imag += coeff[i]*(shift_reg_imag[i] + shift_reg_imag[N-1-i]);
    }

    //Need the middle value.  Its coefficient is 1.
    acc_real += shift_reg_real[N/2];
    acc_imag += shift_reg_imag[N/2];

    //Shift all values.
     MemUpdate:
    for (int i = N - 1; i > 0; i--)
    {
        shift_reg_real[i] = shift_reg_real[i-1];
        shift_reg_imag[i] = shift_reg_imag[i-1];
    }

    //Output values.
     *out_real = acc_real;
     *out_imag = acc_imag;
}