FIR

Filters a source vector through a single-rate or multi-rate FIR filter.

Syntax

Case 1: Not-in-place operation on integer samples

IppStatus ippsFIR_16s_Sfs(const Ipp16s* pSrc, Ipp16s* pDst, int numIters, IppsFIRState_16s* pState, int scaleFactor);

IppStatus ippsFIR_32s_Sfs(const Ipp32s* pSrc, Ipp32s* pDst, int numIters, IppsFIRState_32s* pState, int scaleFactor);

IppStatus ippsFIR32s_16s_Sfs(const Ipp16s* pSrc, Ipp16s* pDst, int numIters, IppsFIRState32s_16s* pState, int scaleFactor);

IppStatus ippsFIR32f_16s_Sfs(const Ipp16s* pSrc, Ipp16s* pDst, int numIters, IppsFIRState32f_16s* pState, int scaleFactor);

IppStatus ippsFIR64f_16s_Sfs(const Ipp16s* pSrc, Ipp16s* pDst, int numIters, IppsFIRState64f_16s* pState, int scaleFactor);

IppStatus ippsFIR64f_32s_Sfs(const Ipp32s* pSrc, Ipp32s* pDst, int numIters, IppsFIRState64f_32s* pState, int scaleFactor);

IppStatus ippsFIR32sc_16sc_Sfs(const Ipp16sc* pSrc, Ipp16sc* pDst, int numIters, IppsFIRState32sc_16sc* pState, int scaleFactor);

IppStatus ippsFIR32fc_16sc_Sfs(const Ipp16sc* pSrc, Ipp16sc* pDst, int numIters, IppsFIRState32fc_16sc* pState, int scaleFactor);

IppStatus ippsFIR64fc_16sc_Sfs(const Ipp16sc* pSrc, Ipp16sc* pDst, int numIters, IppsFIRState64fc_16sc* pState, int scaleFactor);

IppStatus ippsFIR64fc_32sc_Sfs(const Ipp32sc* pSrc, Ipp32sc* pDst, int numIters, IppsFIRState64fc_32sc* pState, int scaleFactor);

Case 2 Not-in-place operation on floating point samples

IppStatus ippsFIR_32f(const Ipp32f* pSrc, Ipp32f* pDst, int numIters, IppsFIRState_32f* pState);

IppStatus ippsFIR_64f(const Ipp64f* pSrc, Ipp64f* pDst, int numIters, IppsFIRState_64f* pState);

IppStatus ippsFIR_32fc(const Ipp32fc* pSrc, Ipp32fc* pDst, int numIters, IppsFIRState_32fc* pState);

IppStatus ippsFIR_64fc(const Ipp64fc* pSrc, Ipp64fc* pDst, int numIters, IppsFIRState_64fc* pState);

IppStatus ippsFIR64f_32f(const Ipp32f* pSrc, Ipp32f* pDst, int numIters, IppsFIRState64f_32f* pState);

IppStatus ippsFIR64fc_32fc(const Ipp32fc* pSrc, Ipp32fc* pDst, int numIters, IppsFIRState64fc_32fc* pState);

Case 3 In-place operation on integer samples

IppStatus ippsFIR_16s_ISfs(Ipp16s* pSrcDst, int numIters, IppsFIRState_16s* pState, int scaleFactor);

IppStatus ippsFIR_32s_ISfs(Ipp32s* pSrcDst, int numIters, IppsFIRState_32s* pState, int scaleFactor);

IppStatus ippsFIR32s_16s_ISfs(Ipp16s* pSrcDst, int numIters, IppsFIRState32s_16s* pState, int scaleFactor);

IppStatus ippsFIR32f_16s_ISfs(Ipp16s* pSrcDst, int numIters, IppsFIRState32f_16s* pState, int scaleFactor);

IppStatus ippsFIR64f_16s_ISfs(Ipp16s* pSrcDst, int numIters, IppsFIRState64f_16s* pState, int scaleFactor);

IppStatus ippsFIR64f_32s_ISfs(Ipp32s* pSrcDst, int numIters, IppsFIRState64f_32s* pState, int scaleFactor);

IppStatus ippsFIR32sc_16sc_ISfs(Ipp16sc* pSrcDst, int numIters, IppsFIRState32sc_16sc* pState, int scaleFactor);

IppStatus ippsFIR32fc_16sc_ISfs(Ipp16sc* pSrcDst, int numIters, IppsFIRState32fc_16sc* pState, int scaleFactor);

IppStatus ippsFIR64fc_16sc_ISfs(Ipp16sc* pSrcDst, int numIters, IppsFIRState64fc_16sc* pState, int scaleFactor);

IppStatus ippsFIR64fc_32sc_ISfs(Ipp32sc* pSrcDst, int numIters, IppsFIRState64fc_32sc* pState, int scaleFactor);

Case 4 In-place operation on floating point samples

IppStatus ippsFIR_32f_I(Ipp32f* pSrcDst, int numIters, IppsFIRState_32f* pState);

IppStatus ippsFIR_64f_I(Ipp64f* pSrcDst, int numIters, IppsFIRState_64f* pState);

IppStatus ippsFIR64f_32f_I(Ipp32f* pSrcDst, int numIters, IppsFIRState64f_32f* pState);

IppStatus ippsFIR_32fc_I(Ipp32fc* pSrcDst, int numIters, IppsFIRState_32fc* pState);

IppStatus ippsFIR_64fc_I(Ipp64fc* pSrcDst, int numIters, IppsFIRState_64fc* pState);

IppStatus ippsFIR64fc_32fc_I(Ipp32fc* pSrcDst, int numIters, IppsFIRState64fc_32fc* pState);

Parameters

pState

Pointer to the FIR filter state structure.

pSrc

Pointer to the source vector.

pDst

Pointer to the destination vector.

pSrcDst

Pointer to the source and destination vector for the in-place operation.

numIters

Number of iterations.

scaleFactor

Scale factor, refer to Integer Scaling.

Description

The function ippsFIR is declared in the ipps.h file. This function filters a source vector pSrc or pSrcDst through a FIR or stream FIR filters, and stores the results in pDst or pSrcDst, respectively. Both filters can be single-rate or multi-rate. The filter state structure pState defines the type of the filter and specifies its parameters. It must be initialized before calling the function ippsFIR using one of the initializing functions (ippsFIRInitAlloc, ippsFIRStreamInitAlloc, ippsFIRInit, ippsFIRStreamInit for single-rate filters, or ippsFIRMRInitAlloc, ippsFIRMRStreamInitAlloc, ippsFIRMRInit, ippsFIRMRStreamInit for multi-rate filters).

The parameter numIters specifies the number of iterations associated with the number of samples to be filtered by the function. The length of the source and destination vectors depends on this parameter.

For single-rate FIR filters, the length of the pSrc (pSrcDst) and pDst (pSrcDst) is equal to numIters.

For single-rate stream FIR filters, the length of the pSrc (pSrcDst) is equal to numIters+tapLen -1, and length of the pDst (pSrcDst) is equal to numIters.

For multi-rate FIR filters, the length of the pSrc is equal to numIters*downFactor, the length of the pDst is equal tonumIters*upFactor.

For multi-rate stream FIR filters, the length of the pSrc is equal to numIters*downFactor + (tapLen-1)/ upFactor+ 1, the length of the pDst is equal to numIters *upFactor.

In the following definition of the FIR filter, the sample to be filtered is denoted x(n), the taps are denoted h(i), and the return value is y(n).

The return value y(n) is defined by the formula for a single-rate filter:

For a single-rate filter the return value y(n) is defined by the following formula:



The results are identical to numIters consecutive calls to the function ippsFIROne.

When the function completes calculation, it updates the delay line values stored in the state structure (for structures with delay line only).

The multi-rate filtering is considered as a sequence of three operations: upsampling, filtering with a single-rate FIR filter, and downsampling. The algorithm is implemented as a single operation including the above-mentioned three steps. Thus, the function does not create an internal (upFactor*numIters*downFactor)-size buffer to store the upsampling result.

The code examples below illustrate single-rate filtering with the function ippsFIR_32f and using of multi-rate filter functions for vector interpolation (resizing).

Return Values

ippStsNoErr

Indicates no error.

ippStsNullPtrErr

Indicates an error when one of the specified pointers is NULL.

ippStsSizeErr

Indicates an error when numIters is less or equal to 0.

ippStsContextMatchErr

Indicates an error when the state identifier is incorrect.

Single-Rate Filtering with the ippsFIR Function

#undef NUMITERS
#define NUMITERS 150
     int n;
     IppStatus status;
     IppsIIRState_32f *ictx;
     IppsFIRState_32f *fctx;
     IppsFIRState_32f *fsctx;
     Ipp32f *x = ippsMalloc_32f(NUMITERS+10),
            *y = ippsMalloc_32f(NUMITERS),
            *z = ippsMalloc_32f(NUMITERS);
     const float taps[] = {
         0.0051f, 0.0180f, 0.0591f, 0.1245f, 0.1869f, 0.2127f, 0.1869f,
         0.1245f, 0.0591f, 0.0180f, 0.0051f, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
     };
     for (n =0;n<NUMITERS;++n)x[n]=(float)sin(IPP_2PI *n *0.2);
     ippsIIRInitAlloc_32f( &ictx, taps, 10, NULL );
     ippsFIRInitAlloc_32f( &fctx, taps, 11, NULL );
     ippsFIRStreamInitAlloc_32f( &fsctx, taps, 11 );
     status = ippsIIR_32f( x, y, NUMITERS, ictx);
     printf_32f("IIR 32f output + 120 =", y + 120, 5, status);
     ippsIIRFree_32f(ictx);
     status = ippsFIR_32f( x, z, NUMITERS, fctx );
     printf_32f("FIR 32f output + 120 =", z + 120, 5, status);
     ippsFIRFree_32f(fctx);
     status = ippsFIR_32f( x, z, NUMITERS, fsctx );
     printf_32f("FIR 32f output + 110 =", z + 110, 5, status);
     ippsFIRFree_32f(fsctx);
     ippsFree(z);
     ippsFree(y);
     ippsFree(x);
     return status;
}
Output: 
    IIR 32f output + 120 = 0.000000 0.049896 0.030838 -0.030838 -0.049896
    FIR 32f output + 120 = 0.000000 0.049896 0.030838 -0.030838 -0.049896
Matlab* Analog: 
    >> F = 0.2; N = 150; n = 0:N-1; x = sin(2*pi*n*F); 
    y = filter(fir1(10,0.15),1,x); y(121:125)

		

	

Using Multi-Rate FIR Functions

Input
vector (src) is:
x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,....

		
Taps are (tapsLen=8 for example):
t0,t1,t2,t3,t4,t5,t6,t7

		
We want to resize the input vector in 2/3 proportion, so upsample factor
for MR FIR is equal to 2 and downsample factor is equal to 3:

		
Upsample operation:
x0,0,x1,0,x2,0,x3,0,x4,0,x5,0,x6,0,x7,0,x8,0,x9,0,....

		
Interpolation (filtering):
y0 = x0*t0+0*t1+x1*t2+0*t3+x2*t4+0*t5+x3*t6+0*t7 = (optimized) = x0*t0+x1*t2+x2*t4+x3*t6
y1 = 0*t0+x1*t1+0*t2+x2*t3+0*t4+x3*t5+0*t6+x4*t7 = (optimized) = x1*t1+x2*t3+x3*t5+x4*t7
y2 = x1*t0+0*t1+x2*t2+0*t3+x3*t4+0*t5+x4*t6+0*t7 = (optimized) = x1*t0+x2*t2+x3*t4+x4*t6
y3 = 0*t0+x2*t1+0*t2+x3*t3+0*t4+x4*t5+0*t6+x5*t7 = (optimized) = x2*t1+x3*t3+x4*t5+x5*t7
y4 = x2*t0+0*t1+x3*t2+0*t3+x4*t4+0*t5+x5*t6+0*t7 = (optimized) = x2*t0+x3*t2+x4*t4+x5*t6
y5 = 0*t0+x3*t1+0*t2+x4*t3+0*t4+x5*t5+0*t6+x6*t7 = (optimized) = x2*t1+x3*t3+x4*t5+x5*t7
as a result after this operation y vector is 2x times longer than x

		
Downsample operation:
dst = y0, y3, y6,...  (optimized version doesn't calculate y1,y2,etc.) - 	
                            so dst will have 2/3 length in comparison with src with interpolation
                             that is defined by taps coefficients ( so it can be cubic, supersampling,
                              lanczos or any other spline polynomial)

		
"C" analogue:

		
#define n 99

		
IppsFIRState_32f *pState;
Ipp32f pTaps[8] = { t0,t1,t2,t3,t4,t5,t6,t7};
int tapsLen = 8;
int upFactor = 2;
int upPhase = 0;
int downFactor = 3;
int downPhase = 0;
Ipp32f *pDlyLine = NULL;
Ipp32f pSrc[n] = { x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,....};
Ipp32f pDst[2*n/3] ;
int numIters = n;
IppStatus status;

		
status = ippsFIRMRInitAlloc_32f ( &pState, pTaps, tapsLen, upFactor, upPhase,
                                    downFactor, downPhase, pDlyLine);
if( ippStsNoErr != status) return error;
status = ippsFIR_32f( pSrc, pDst, numIters, pState); 
// pDst will contain y0, y3, y6,... according to the above formulas;
if( ippStsNoErr != status) return error;
status = ippsFIRFree_32f(
pState );
if( ippStsNoErr != status) return error;
.......

Submit feedback on this help topic

Copyright © 2000 - 2011, Intel Corporation. All rights reserved.