DSPRelated.com
Forums

FIR & IIR : design,filtering

Started by akin...@hotmail.com April 23, 2008
Hello

I am using some FIR and IIR filters. I use coefficients from Dsptutor's java applets. First of all , have you ever experienced Dpstutor's designs on projects ?

I am using fir and iir filtering functions from Paul Embree's book. I am building a PC\Windows application using Directshow and Winapi.

In my application , I use these filtering functions with coefficients I already got , but unfortunately they seem not working. I mean , you can't hear any sound after a few seconds. I am pasting my filtering functions , if it is possible can you check them for any errors ?

/*
INPUT fInput input for filter
INPUT pCoefficients address of filter coefficients
INPUT nCoefficientNumber number of coefficients
INPUT\OUTPUT pMemory address of past values
*/

float FIRFilterEvaluate (float fInput,float* pCoefficients,int nCoefficientNumber,float* pMemory)
{
int i ;
float *pMemoryPositioner,*pMemoryPositionerTemp,*pCoefficientPositioner ;
float fOutput ;

pMemoryPositioner = pMemory ; // We get address of pMemory to make processes on it
pMemoryPositionerTemp = pMemoryPositioner ; // To update original history , we need a temp pointer
pCoefficientPositioner = pCoefficients + nCoefficientNumber - 1 ; // We move the pointer to last coefficient

// WE WILL MAKE SUMMATION OF "nCoefficientNumber" MULTIPLICATIONS

fOutput = *pMemoryPositioner++ * (*pCoefficientPositioner--); // We gave first multiplication to summation

for(i=2 ; i {
*pMemoryPositionerTemp++ = *pMemoryPositioner ;
fOutput += (*pMemoryPositioner++) * (*pCoefficientPositioner--) ;
}

fOutput += fInput * (*pCoefficientPositioner) ; // We gave last multiplication to summation

*pMemoryPositionerTemp = fInput ;

return fOutput ;
}

float IIRFilterEvaluate ( float fInput,float* pCoefficients ,int n,
float * pMemory)
{
int i ;
float *pMemoryPositionerTemp1 ,*pMemoryPositionerTemp2,*pCoefficientPositioner ;
float fOutput,new_hist,history1,history2 ;

pCoefficientPositioner = pCoefficients ;
pMemoryPositionerTemp1 = pMemory ;
pMemoryPositionerTemp2 = pMemoryPositionerTemp1 + 1 ;

fOutput = fInput * (*pCoefficientPositioner++);

for(i=0 ; i {

history1 = *pMemoryPositionerTemp1 ;
history2 = *pMemoryPositionerTemp2 ;

fOutput = fOutput - history1 * (*pCoefficientPositioner++);
new_hist = fOutput - history2 * (*pCoefficientPositioner++); // poles

fOutput = new_hist + history1 * (*pCoefficientPositioner++);
fOutput = fOutput + history2 * (*pCoefficientPositioner++ ) ; // zeros

*pMemoryPositionerTemp2++ = *pMemoryPositionerTemp1 ;
*pMemoryPositionerTemp1++ = new_hist ;

pMemoryPositionerTemp1++ ;
pMemoryPositionerTemp2++ ;
}

return fOutput ;
}