Forums

FIR filter using IPP

Started by Peter L August 16, 2010
Hello:

I am trying to build simple projects using the Intel's IPP audio DSP
library. Here I am trying to come up with a simple low pass filter.
I obtained the filter taps using FDATOOL in MATLAB. But I am not fully
familiar on using it.

void LPF_FIR_Filter(const Ipp32f* pSrc, Ipp32f* pDst, int numIters,
IppsFIRState_32f* pState)
{
int tapLen = 11;
float taps[11] {
-0.05986175314, -0.04497750103, 0.03207610548, 0.1499007344,
0.2568940222,
0.3000000119, 0.2568940222, 0.1499007344, 0.03207610548,
-0.04497750103,
-0.05986175314
};

ippsFIRInitAlloc_32f(&pState, taps, tapLen, NULL);
ippsFIRStreamInitAlloc_32f(&pState, taps, 11 );

//filter an input vector
ippsFIR_32f(pSrc, pDst, numIters, pState);
ippsFIRFree_32f(pState);
}

int main ()
{
FILE * pFile;
long lSize;
float * buffer;
size_t result;
Ipp32f* pDst;
int numIters = 64;
IppsFIRState_32f* pState;

pFile = fopen ("Input.bin", "rb");
if (pFile==NULL) {fputs ("File error",stderr); exit (1);}

*// obtain file size:*
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
rewind (pFile);

*// allocate memory to contain the whole file:*
buffer = (float*) malloc (sizeof(float)*lSize);
if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}

* // copy the file into the buffer:*
result = fread (buffer,1,lSize,pFile);
if (long(result) != lSize) {fputs ("Reading error",stderr); exit (3);}

fclose (pFile);

* // FIR Filter*
* LPF_FIR_Filter(buffer, pDst, numIters, pState);*

* // file write*
pFile = fopen ("Output.bin", "wb");
fwrite (pDst, 1, sizeof(pDst), pFile);
fclose (pFile);
return 0;
}
The IPP documentation asks to do the following:
1. Call ippsFIRInitAlloc or ippsFIRInit
2. ippsFIR
3. ippsFIRSetTaps
4. ippsFIRFree

Your help will be highly appreciated.

Regards,
P
On 13.08.2010 20:58, Peter L wrote:
> Hello:
>
> I am trying to build simple projects using the Intel's IPP audio DSP
> library. Here I am trying to come up with a simple low pass filter.
> I obtained the filter taps using FDATOOL in MATLAB. But I am not fully
> familiar on using it.
>
> void LPF_FIR_Filter(const Ipp32f* pSrc, Ipp32f* pDst, int numIters,
> IppsFIRState_32f* pState)
> {
> int tapLen = 11;
> float taps[11] > {
> -0.05986175314, -0.04497750103, 0.03207610548, 0.1499007344,
> 0.2568940222,
> 0.3000000119, 0.2568940222, 0.1499007344, 0.03207610548,
> -0.04497750103,
> -0.05986175314
> };
>
> ippsFIRInitAlloc_32f(&pState, taps, tapLen, NULL);
> ippsFIRStreamInitAlloc_32f(&pState, taps, 11 );
>
> //filter an input vector
> ippsFIR_32f(pSrc, pDst, numIters, pState);
> ippsFIRFree_32f(pState);
> }
>
> int main ()
> {
> FILE * pFile;
> long lSize;
> float * buffer;
> size_t result;
> Ipp32f* pDst;
> int numIters = 64;
> IppsFIRState_32f* pState;
>
> pFile = fopen ("Input.bin", "rb");
> if (pFile==NULL) {fputs ("File error",stderr); exit (1);}
>
> *// obtain file size:*
> fseek (pFile , 0 , SEEK_END);
> lSize = ftell (pFile);
> rewind (pFile);
>
> *// allocate memory to contain the whole file:*
> buffer = (float*) malloc (sizeof(float)*lSize);
> if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}
>
> * // copy the file into the buffer:*
> result = fread (buffer,1,lSize,pFile);
> if (long(result) != lSize) {fputs ("Reading error",stderr); exit (3);}
>
> fclose (pFile);
>
> * // FIR Filter*
> * LPF_FIR_Filter(buffer, pDst, numIters, pState);*
>
> * // file write*
> pFile = fopen ("Output.bin", "wb");
> fwrite (pDst, 1, sizeof(pDst), pFile);
> fclose (pFile);
> return 0;
> }
> The IPP documentation asks to do the following:
>
> 1. Call ippsFIRInitAlloc or ippsFIRInit
> 2. ippsFIR
> 3. ippsFIRSetTaps
> 4. ippsFIRFree
>
> Your help will be highly appreciated.
>
> Regards,
> P
>

If you have only one filtering you can use FIR_Direct function. It is
simpler:
ipps_FIR_Direct_32f_I(buffer, buffer_size, taps, tapLen, NULL, NULL);
and after that filtered signal will be in buffer.

If you have a lot of filterings in a row, then it would be better
(performance wise) to allocate and initialize filter state structure and
then use FIR function (you have an example IPP documentation under the
description of FIR function).

Cheers!
Igor