Files
fir/firinterp.c
jens 0179c510fe Initial import
git-svn-id: http://moon:8086/svn/software/trunk/libsrc/fir@1 b431acfa-c32f-4a4a-93f1-934dc6c82436
2014-07-19 07:44:42 +00:00

75 lines
1.5 KiB
C
Executable File

/*************************************************************************/
/* fir.c
/*************************************************************************/
#include <stdio.h>
#include <malloc.h>
#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);
}