git-svn-id: http://moon:8086/svn/software/trunk/libsrc/fir@1 b431acfa-c32f-4a4a-93f1-934dc6c82436
77 lines
1.5 KiB
C
Executable File
77 lines
1.5 KiB
C
Executable File
/*************************************************************************/
|
|
/* fir.c
|
|
/*************************************************************************/
|
|
#include <stdio.h>
|
|
#include <malloc.h>
|
|
#include "math.h"
|
|
#include "fir.h"
|
|
#include "firdecim.h"
|
|
|
|
/*************************************************************************/
|
|
/* Global Variables
|
|
/*************************************************************************/
|
|
int FDfilter(struct _sFIRDECIM *pObj, float *pX, float *pY, int len)
|
|
{
|
|
int len2, i, firLen, kL;
|
|
float *pSxt, *pBt, sum;
|
|
|
|
kL = pObj->kL;
|
|
firLen = pObj->firLen;
|
|
|
|
pBt = &pObj->pB[0];
|
|
pSxt = &pObj->pX[0];
|
|
len2 = 0;
|
|
while (len >= kL)
|
|
{
|
|
|
|
for (i = firLen-1; i >= kL; i--)
|
|
{
|
|
pObj->pX[i] = pObj->pX[i- kL];
|
|
}
|
|
|
|
for (i = kL-1; i >= 0; i--)
|
|
{
|
|
pObj->pX[i] = *(pX++);
|
|
}
|
|
len -= kL;
|
|
|
|
sum = 0.0;
|
|
|
|
for (i=0; i < firLen; i++)
|
|
sum += pObj->pX[i] * pObj->pB[i];
|
|
|
|
*(pY++) = sum;
|
|
len2++;
|
|
}
|
|
return len2;
|
|
}
|
|
|
|
void FDinit(struct _sFIRDECIM *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->firLen*sizeof(float));
|
|
|
|
|
|
for(n=0; n < pObj->firLen; n++)
|
|
{
|
|
pObj->pX[n] = 0;
|
|
}
|
|
|
|
Sinc(pObj->pB, kL, 1.f/kL, 1.f/kL, pObj->firLen);
|
|
|
|
}
|
|
|
|
void FDfree(struct _sFIRDECIM *pObj)
|
|
{
|
|
free(pObj->pB);
|
|
free(pObj->pX);
|
|
} |