/*************************************************************************/ /* fir.c /*************************************************************************/ #include #include #include "math.h" #include "fir.h" #include "firinterp.h" /*************************************************************************/ /* Global Variables /*************************************************************************/ int FIfilter(struct _sFIRIP *pObj, float *pX, float *pY, int len) { int n, len2, k, i, j, nIp, firLen, kL; float *pSxt, *pBt, sum; kL = pObj->kL; nIp = pObj->nCoefPerPhase; firLen = pObj->firLen; pBt = &pObj->pB[0]; pSxt = &pObj->pX[0]; len2 = 0; for (n=0; n < len; n++) { for (i=nIp; i > 0; i--) pSxt[i] = pSxt[i-1]; pSxt[0] = pX[n]; for (k=0; k < kL; k++) { sum = 0.0; i=0; for (j=k; j < firLen; j += kL) { sum += pSxt[i] * pBt[j]; i++; } *(pY++) = sum; len2++; } } return len2; } void FIinit(struct _sFIRIP *pObj, int kL, int nCoefPerPhase) { int n; pObj->kL = kL; pObj->firLen = kL*nCoefPerPhase; pObj->nCoefPerPhase = nCoefPerPhase; if ((pObj->firLen%2) == 0) pObj->firLen++; pObj->pB = (float*)malloc(pObj->firLen*sizeof(float)); pObj->pX = (float*)malloc((pObj->nCoefPerPhase+1)*sizeof(float)); for(n=0; n <= pObj->nCoefPerPhase; n++) { pObj->pX[n] = 0; } Sinc(pObj->pB, kL, 1.f, 1.f/kL, pObj->firLen); } void FIfree(struct _sFIRIP *pObj) { free(pObj->pB); free(pObj->pX); }