Intel® Integrated Performance Primitives (Intel® IPP) Developer Guide and Reference

ID 790148
Date 10/31/2024
Public
Document Table of Contents

Examples of Using FIR Functions

The code examples below demonstrate how to use the ippsFIRSR function:

Standard FIR Filtering with a Not-in-place Destination

Type of FIR Filter

Destination

Source Delay Line

Threading

standard

not-in-place

zero

none

    #define LEN 1024
    #define TAPS_LEN 8
 
    IppsFIRSpec_32f *pSpec;
    float           *src, *dst, *dly, *taps;
    Ipp8u           *buf;
    int             specSize, bufSize;
    IppStatus status;
    //get sizes of the spec structure and the work buffer
    status = ippsFIRSRGetSize (TAPS_LEN,  ipp32f ,  &specSize,  &bufSize );
 
    src   = ippsMalloc_32f(LEN);
    dst   = ippsMalloc_32f(LEN);
    dly   = ippsMalloc_32f(TAPS_LEN-1);
    taps  = ippsMalloc_32f(TAPS_LEN);
    pSpec = (IppsFIRSpec_32f*)ippsMalloc_8u(specSize);
    buf   = ippsMalloc_8u(bufSize);
 
    //initialize the spec structure
    ippsFIRSRInit_32f( taps, TAPS_LEN, ippAlgDirect, pSpec );
    //apply the FIR filter
    ippsFIRSR_32f(src, dst, LEN,  pSpec,  NULL, dly,  buf);

Standard FIR Filtering with an In-place Destination

Type of FIR Filter

Destination

Source Delay Line

Threading

standard

in-place

zero

none

    #define LEN 1024
    #define TAPS_LEN 8
 
    IppsFIRSpec_32f *pSpec;
    float           *src, *dst, *dly, *taps;
    Ipp8u           *buf;
    int             specSize, bufSize;
 
    //get sizes of the spec structure and the work buffer
    ippsFIRSRGetSize(TAPS_LEN, ipp32f, &specSize, &bufSize );
 
    src   = ippsMalloc_32f(LEN);
    dst   = src;
    dly   = ippsMalloc_32f(TAPS_LEN-1);
    taps  = ippsMalloc_32f(TAPS_LEN);
    pSpec = (IppsFIRSpec_32f*)ippsMalloc_8u(specSize);
    buf   = ippsMalloc_8u(bufSize);
 
    //initialize the spec structure
    ippsFIRSRInit_32f( taps, TAPS_LEN, ippAlgDirect, pSpec );
    //apply the FIR filter
    ippsFIRSR_32f(src, dst, LEN,  pSpec,  NULL, dly,  buf);

Stream FIR Filtering with a Not-in-place Destination

Type of FIR Filter

Destination

Source Delay Line

Threading

stream

not-in-place

src

none

    #define LEN 1024
    #define TAPS_LEN 8
 
    IppsFIRSpec_32f *pSpec;
    float           *src, *dst,  *taps;
    Ipp8u           *buf;
    int             specSize, bufSize;
 
    //get sizes of the spec structure and the work buffer
    ippsFIRSRGetSize(TAPS_LEN, ipp32f, &specSize, &bufSize );
 
    src   = ippsMalloc_32f(LEN+TAPS_LEN-1);
    dst   = ippsMalloc_32f(LEN);
    taps  = ippsMalloc_32f(TAPS_LEN);
    pSpec = (IppsFIRSpec_32f*)ippsMalloc_8u(specSize);
    buf   = ippsMalloc_8u(bufSize);
 
    //initialize the spec structure
    ippsFIRSRInit_32f( taps, TAPS_LEN, ippAlgDirect, pSpec );
    //apply the FIR filter
    ippsFIRSR_32f(src+TAPS_LEN-1, dst, LEN,  pSpec,  src, NULL,  buf);

Stream FIR Filtering with an In-place Destination

Type of FIR Filter

Destination

Source Delay Line

Threading

stream

in-place

src

none

    #define LEN 1024
    #define TAPS_LEN 8
 
    IppsFIRSpec_32f *pSpec;
    float           *src, *dst, *taps;
    Ipp8u           *buf;
    int             specSize, bufSize;
 
    //get sizes of the spec structure and the work buffer
    ippsFIRSRGetSize(TAPS_LEN, ipp32f, &specSize, &bufSize );
 
    src   = ippsMalloc_32f(LEN+TAPS_LEN-1);
    dst   = src;
    taps  = ippsMalloc_32f(TAPS_LEN);
    pSpec = (IppsFIRSpec_32f*)ippsMalloc_8u(specSize);
    buf   = ippsMalloc_8u(bufSize);
 
    //initialize the spec structure
    ippsFIRSRInit_32f( taps, TAPS_LEN, ippAlgDirect, pSpec );
    //apply the FIR filter
    ippsFIRSR_32f(src+TAPS_LEN-1, dst, LEN,  pSpec,  src, NULL,  buf);

Standard FIR Filtering with a Not-in-place Destination and Threading

Type of FIR Filter

Destination

Source Delay Line

Threading

standard

not-in-place

zero

NTHREADS

    #define LEN 1024
    #define TAPS_LEN 8
    #define DLY_LEN TAPS_LEN-1
    #define NTH 4
 
    float *src,*dst;
    float *dlyOut, *taps;
    unsigned char *buf;
    IppsFIRSpec_32f* pSpec;
    int specSize, bufSize;
    int i,tlen, ttail;
 
    //get sizes of the spec structure and the work buffer
    ippsFIRSRGetSize(TAPS_LEN, ipp32f, &specSize, &bufSize );
 
    src    = ippsMalloc_32f(LEN);
    dst    = ippsMalloc_32f(LEN);
    dlyOut = ippsMalloc_32f(TAPS_LEN-1);
    taps   = ippsMalloc_32f(TAPS_LEN);
    pSpec  = (IppsFIRSpec_32f*)ippsMalloc_8u(specSize);
    buf    = ippsMalloc_8u(bufSize*NTH);
    for(i=0;i<LEN;i++){
        src[i] = i;
    }
    for(i=0;i<TAPS_LEN;i++){
        taps[i] = 1;
    }
    //initialize the spec structure
    ippsFIRSRInit_32f( taps, TAPS_LEN, ippAlgDirect, pSpec );
    tlen  = LEN / NTH;
    ttail = LEN % NTH;
    for(i=0;i< NTH;i++) {//this cycle means parallel region
        Ipp32f* s   = src+i*tlen;
        Ipp32f* d   = dst+i*tlen;
        int     len = tlen+((i==(NTH - 1))?ttail:0);
        Ipp8u*  b   = buf+i*bufSize;
        if( i == 0) 
            ippsFIRSR_32f(s, d, len, pSpec, NULL,           NULL  , b);
        else if (i == NTH - 1)
            ippsFIRSR_32f(s, d, len, pSpec, s-(TAPS_LEN-1), dlyOut, b);
        else
            ippsFIRSR_32f(s, d, len, pSpec, s-(TAPS_LEN-1), NULL  , b);
    }

Standard FIR Filtering with an In-place Destination and Threading

Type of FIR Filter

Destination

Source Delay Line

Threading

standard

in-place

zero

NTHREADS

    #define LEN 1024
    #define TAPS_LEN 8
    #define DLY_LEN TAPS_LEN-1
    #define NTHREADS 4
 
    float *src, *dst,  *dlyOut, *taps;
    float* tdly[NTHREADS];
    unsigned char *buf;
    IppsFIRSpec_32f* pSpec;
    int specSize, bufSize;
    int i,tlen, ttail;
 
    //get sizes of the spec structure and the work buffer
    ippsFIRSRGetSize(TAPS_LEN, ipp32f, &specSize, &bufSize );
 
    src    = ippsMalloc_32f(LEN);
    dst    = ippsMalloc_32f(LEN);
    dlyOut = ippsMalloc_32f(TAPS_LEN-1);
    taps   = ippsMalloc_32f(TAPS_LEN);
    pSpec  = (IppsFIRSpec_32f*)ippsMalloc_8u(specSize);
    buf    = ippsMalloc_8u(bufSize*NTHREADS);
 
    //initialize the spec structure
    ippsFIRSRInit_32f( taps, TAPS_LEN, ippAlgDirect, pSpec );
    tlen  = LEN / NTHREADS;
    ttail = LEN % NTHREADS;
    //tdly    = ippsMalloc_32f((TAPS_LEN-1)*(NTHREADS-1));
 
    for(i=1;i<NTHREADS;i++){//cycle in main thread
        tdly[i]  = ippsMalloc_32f(TAPS_LEN-1);
        ippsCopy_32f(src+i*tlen-(TAPS_LEN-1), tdly[i], TAPS_LEN-1);
    }
    for(i=0;i< NTHREADS;i++) {//this cycle means parallel region
        Ipp32f* s   = src+i*tlen;
        Ipp32f* d   = dst+i*tlen;
        int     len = tlen+((i==NTHREADS - 1)?ttail:0);
        Ipp8u*  b   = buf+i*bufSize;
        if( i == 0) 
            ippsFIRSR_32f(s, d, len, pSpec, NULL,    NULL  , b);
        else if (i == NTHREADS - 1)
            ippsFIRSR_32f(s, d, len, pSpec, tdly[i], dlyOut, b);
        else
            ippsFIRSR_32f(s, d, len, pSpec, tdly[i], NULL  , b);
    }