IIR

Filters a source vector through an IIR filter.

Syntax

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

IppStatus ippsIIR32s_16s_Sfs(const Ipp16s* pSrc, Ipp16s* pDst, int len, IppsIIRState32s_16s* pState, int scaleFactor);

IppStatus ippsIIR32f_16s_Sfs(const Ipp16s* pSrc, Ipp16s* pDst, int len, IppsIIRState32f_16s* pState, int scaleFactor);

IppStatus ippsIIR64f_16s_Sfs(const Ipp16s* pSrc, Ipp16s* pDst, int len, IppsIIRState64f_16s* pState, int scaleFactor);

IppStatus ippsIIR64f_32s_Sfs(const Ipp32s* pSrc, Ipp32s* pDst, int len, IppsIIRState64f_32s* pState, int scaleFactor);

IppStatus ippsIIR32sc_16sc_Sfs(const Ipp16sc* pSrc, Ipp16sc* pDst, int len, IppsIIRState32sc_16sc* pState, int scaleFactor);

IppStatus ippsIIR32fc_16sc_Sfs(const Ipp16sc* pSrc, Ipp16sc* pDst, int len, IppsIIRState32fc_16sc* pState, int scaleFactor);

IppStatus ippsIIR64fc_16sc_Sfs(const Ipp16sc* pSrc, Ipp16sc* pDst, int len, IppsIIRState64fc_16sc* pState, int scaleFactor);

IppStatus ippsIIR64fc_32sc_Sfs(const Ipp32sc* pSrc, Ipp32sc* pDst, int len, IppsIIRState64fc_32sc* pState, int scaleFactor);

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

IppStatus ippsIIR_32f(const Ipp32f* pSrc, Ipp32f* pDst, int len, IppsIIRState_32f* pState);

IppStatus ippsIIR_64f(const Ipp64f* pSrc, Ipp64f* pDst, int len, IppsIIRState_64f* pState);

IppStatus ippsIIR64f_32f(const Ipp32f* pSrc, Ipp32f* pDst, int len, IppsIIRState64f_32f* pState);

IppStatus ippsIIR_32fc(const Ipp32fc* pSrc, Ipp32fc* pDst, int len, IppsIIRState_32fc* pState);

IppStatus ippsIIR_64fc(const Ipp64fc* pSrc, Ipp64fc* pDst, int len, IppsIIRState_64fc* pState);

IppStatus ippsIIR64fc_32fc(const Ipp32fc* pSrc, Ipp32fc* pDst, int len, IppsIIRState64fc_32fc* pState);

Case 3: In-place operation on integer samples

IppStatus ippsIIR32s_16s_ISfs(Ipp16s* pSrcDst, int len, IppsIIRState32s_16s* pState, int scaleFactor);

IppStatus ippsIIR32f_16s_ISfs(Ipp16s* pSrcDst, int len, IppsIIRState32f_16s* pState, int scaleFactor);

IppStatus ippsIIR64f_16s_ISfs(Ipp16s* pSrcDst, int len, IppsIIRState64f_16s* pState, int scaleFactor);

IppStatus ippsIIR64f_32s_ISfs(Ipp32s* pSrcDst, int len, IppsIIRState64f_32s* pState, int scaleFactor);

IppStatus ippsIIR32fc_16sc_ISfs(Ipp16sc* pSrcDst, int len, IppsIIRState32fc_16sc* pState, int scaleFactor);

IppStatus ippsIIR32sc_16sc_ISfs(Ipp16sc* pSrcDst, int len, IppsIIRState32sc_16sc* pState, int scaleFactor);

IppStatus ippsIIR64fc_16sc_ISfs(Ipp16sc* pSrcDst, int len, IppsIIRState64fc_16sc* pState, int scaleFactor);

IppStatus ippsIIR64fc_32sc_ISfs(Ipp32sc* pSrcDst, int len, IppsIIRState64fc_32sc* pState, int scaleFactor);

Case 4: In-place operation on floating point samples

IppStatus ippsIIR_32f_I(Ipp32f* pSrcDst, int len, IppsIIRState_32f* pState);

IppStatus ippsIIR_64f_I(Ipp64f* pSrcDst, int len, IppsIIRState_64f* pState);

IppStatus ippsIIR64f_32f_I(Ipp32f* pSrcDst, int len, IppsIIRState64f_32f* pState);

IppStatus ippsIIR_32fc_I(Ipp32fc* pSrcDst, int len, IppsIIRState_32fc* pState);

IppStatus ippsIIR_64fc_I(Ipp64fc* pSrcDst, int len, IppsIIRState_64fc* pState);

IppStatus ippsIIR64fc_32fc_I(Ipp32fc* pSrcDst, int len, IppsIIRState64fc_32fc* pState);

Case 4: Operation with specified number of vector.

IppStatus ippsIIR_32f_P(const Ipp32f** ppSrc, Ipp32f** ppDst, int len, int nChannels, IppsIIRState_32f** ppState);

IppStatus ippsIIR_32f_IP(Ipp32f** ppSrcDst, int len, int nChannels, IppsIIRState_32f** ppState);

Parameters

pState

Pointer to the IIR filter state structure.

ppState

Pointer to the array of the pointers to the IIR filter state structures.

pSrc

Pointer to the source vector.

ppSrc

Pointer to the array of pointers to the source vectors.

pDst

Pointer to the destination vector.

pSrcDst

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

ppSrcDst

Pointer to the array of pointers to the source and destination vectors for the in-place operations.

len

Number of elements of the vector to be filtered.

nChannels

Number of vectors to be filtered.

scaleFactor

Scale factor, refer to Integer Scaling.

Description

The function ippsIIR is declared in the ipps.h file. This function filters len elements of the source vector pSrc or pSrcDst through an IIR filter, and stores the results in pDst or pSrcDst, respectively. The filter parameters are specified in pState.The output of the integer sample is scaled according to scaleFactor and can be saturated.

Do not modify the scaleFactor value unless the state structure is changed.

The filter state must be initialized before calling the function ippsIIR. Specify the number of taps tapsLen, the tap values in pTaps, the delay line values in pDlyLine, and the order or numBq value beforehand.

Function flavors described in the Case 4 filter simultaneously the nChannels source vectors. Each vector must have the len elements and is filtered with its own state structure. These state structures must be initialized beforehand.

The example below show how the Intel IPP functions for IIR filtering can be used.

Example "Using the ippsIIR_32f Function to Suppress a 60 Hz Signal" illustrates using ippsIIR_32f function.

Example "Using the ippsIIR Function to Filter a Sample" demonstrates how to use the function ippsIIR to filter a sample. The function ippsConvert_64f32s_Sfs converts floating-point taps into integer data type before calling ippsIIRInitAlloc_32s.

Return Values

ippStsNoErr

Indicates no error.

ippStsNullPtrErr

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

ippStsSizeErr

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

ippStsChannelErr

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

ippStsContextMatchErr

Indicates an error when the state identifier is incorrect.

Using the ippsIIR_32f Function to Suppress a 60 Hz Signal

IppStatus iir( void )
{
#undef NUMITERS
#define NUMITERS 150
     int n;
     IppStatus status;
     IppsIIRState_32f *ctx;
     Ipp32f *x = ippsMalloc_32f( NUMITERS ), *y = ippsMalloc_32f( NUMITERS );
     /// A second-order notch filter having notch freq at 60 Hz
     const float taps[] = {
        0.940809f,-1.105987f,0.940809f,1,-1.105987f,0.881618f
     };
     /// generate a signal having 60 Hz freq sampled with 400 Hz freq
     for(n=0;n<NUMITERS;++n)x[n]=(float)sin(IPP_2PI *n *60 /400);
     ippsIIRInitAlloc_32f( &ctx, taps, 2, NULL );
     status = ippsIIR_32f( x, y, NUMITERS, ctx );
     printf_32f( " IIR 32f output+120 =", y+120, 5, status );
     ippsIIRFree_32f( ctx );
     ippsFree( y );
     ippsFree( x );
     return status;
}
Output: 
    IIR 32f output + 120 =  -0.000094 0.000339 0.000458 0.000208 -0.000173
Matlab* Analog:
    >> B = [0.940809,-1.105987,0.940809]; A = [1,-1.105987,0.881618];
    n = 0:150; x = sin(2*pi*n*60/400); y = filter(B,A,x); y(121:125)

Using the ippsIIR Function to Filter a Sample  

IppStatus iir16s( void ) {
#undef NUMITERS
#define NUMITERS 150
     int n, tapsfactor = 30;
     IppStatus status;
     IppsIIRState32s_16s *ctx;
     Ipp16s *x = ippsMalloc_16s( NUMITERS ), *y = ippsMalloc_16s( NUMITERS );
     /// A second-order notch filter having notch freq at 60 Hz
     Ipp64f taps[6] = {
        0.940809f,-1.105987f,0.940809f,1,-1.105987f,0.881618f
     };
     Ipp32s taps32s[6];
     Ipp64f tmax, tmp[6];
     ippsAbs_64f( taps, tmp, 6 );
     ippsMax_64f( tmp, 6, &tmax );
     tapsfactor = 0;
     if( tmax > IPP_MAX_32S )
        while( (tmax/=2) > IPP_MAX_32S ) ++tapsfactor;
     else
        while( (tmax*=2) < IPP_MAX_32S ) --tapsfactor;
     if(tapsfactor >0 )
        ippsDivC_64f_I( (float)(1<<(++tapsfactor)), taps, 6 );
     else if( tapsfactor < 0 )
        ippsMulC_64f_I( (float)(1<<(-(tapsfactor))), taps, 6 );
     ippsConvert_64f32s_Sfs( taps, taps32s, 6, ippRndNear, 0 );
     /// generate a signal of 60 Hz freq that is sampled with 400 Hz freq
     for(n=0; n<NUMITERS; ++n) x[n] = (Ipp16s)(1000*sin(IPP_2PI*n*60/400));
     ippsIIRInitAlloc32s_16s( &ctx, taps32s, 2, tapsfactor, NULL );
     status = ippsIIR32s_16s_Sfs( x, y, NUMITERS, ctx, 0 );
     printf_16s( " IIR 32s output+120 =", y+120, 5, status );
     ippsIIRFree32s_16s( ctx );
     ippsFree( y );
     ippsFree( x );
     return status;
}
Output: 
    IIR 32s output + 120 =  0 0 0 0 0

Using the function ippsIIR for Low Pass Filtering

#include <ipp.h>
/*
y[n] = ( 1 * x[n- 2])
+ ( 2 * x[n- 1])
+ ( 1 * x[n- 0])
+ ( -0.1958157127 * y[n- 2])
+ ( -0.3695273774 * y[n- 1])
*/
#define NZEROS 2
#define NPOLES 2
#define GAIN 2.555350342e+00f
static float xv[NZEROS+1], yv[NPOLES+1];
static void filterloop( const float* x, float* y, int len )
{ for (int i=0; i<len; i++ )
{ xv[0] = xv[1]; xv[1] = xv[2]; 
xv[2] = x[i] / GAIN;
yv[0] = yv[1]; yv[1] = yv[2]; 
yv[2] = (xv[0] + xv[2]) + 2 * xv[1]
+ ( -0.1958157127f * yv[0]) + ( -0.3695273774f * yv[1]);
y[i] = yv[2];
}
}
const int LEN = 100;
int main() {
float x[LEN], yu[LEN], yi[LEN];
for(int i=0; i<LEN; i++) x[i] = i-3;
/// customer will compute
/// -1.1740073 -2.6968584 -1.9042342 -0.33358926 
filterloop(x,yu,LEN);
/// matlab gives
///>> b=[1 2 1];a=[1 0.3695273774 0.1958157127 ];x=[-3:1:15]/2.555350342;filter(b,a,x)
/// -1.1740 -2.6969 -1.9042 -0.3336
/// IPP will compute
/// -1.1740074 -2.6968584 -1.9042342 -0.33358920
const int order = 2;
float taps[6] = {1.0f, 2.0f, 1.0f, 1.0f, 0.3695273774f, 0.1958157127f};
IppsIIRState_32f *ctx;
ippsIIRInitAlloc_32f( &ctx, taps, order, (Ipp32f*)0 );
ippsDivC_32f_I( GAIN, x, LEN);
ippsIIR_32f( x, yi, LEN, ctx );
ippsIIRFree_32f( ctx );
return 0;
}

	

Submit feedback on this help topic

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