Wavelet Transforms Example

The delay line paradigm is well-known interface solution for functions that require some pre-history in the streaming processing. In such application the use of the Intel IPP wavelet transform functions is similar to the use of the FIR, IIR, or multi-rate filters. (See also the discussion on the synchronization of low-pass and high-pass filter delays in this chapter.) But very often the wavelet transforms are used to process entire non-streaming data by extending with borders that are suitable for filter bank type that are used in transforms.

The following code example demonstrates how to implement this approach using the Intel IPP functions. It performs forward and inverse wavelet transforms of a short vector containing 12 elements. It uses Daubechies filter bank of the order 2 (that allows the perfect reconstruction) and periodical data extension by wrapping.

It is also may be useful as an illustration of how to fill delay line, if you need non-zero pre-history of signal in streaming applications.

Using Wavelet Transforms Functions

#include <stdio.h>
#include "ipp.h"

//   Filter bank for Daubechies, order 2

static const int fwdFltLenL = 4;
static const int fwdFltLenH = 4;

static const float fwdFltL[4] =
{
   -1.294095225509215e-001f,
    2.241438680418574e-001f,
    8.365163037374690e-001f,
    4.829629131446903e-001f
};

static const float fwdFltH[4] =
{
   -4.829629131446903e-001f,
    8.365163037374690e-001f,
   -2.241438680418574e-001f,
   -1.294095225509215e-001f
};


static const int invFltLenL = 4;
static const int invFltLenH = 4;

static const float invFltL[4] =
{
    4.829629131446903e-001f,
    8.365163037374690e-001f,
    2.241438680418574e-001f,
   -1.294095225509215e-001f
};

static const float invFltH[4] =
{
   -1.294095225509215e-001f,
   -2.241438680418574e-001f,
    8.365163037374690e-001f,
   -4.829629131446903e-001f
};

// minimal values
static const int fwdFltOffsL = -1;
static const int fwdFltOffsH = -1;

// minimal values, that corresponds to perfect reconstruction
static const int invFltOffsL = 0;
static const int invFltOffsH = 0;
void main(void)
{
    Ipp32f src[] = {1, -10, 324, 48, -483, 4, 7, -5532, 34, 8889, -57, 54};

    Ipp32f low[7];
    Ipp32f high[7];

    int i;

    printf("original:\n");
    for(i = 0; i < 12; i++) printf("%.0f; ", src[i]);
    printf("\n");

    {
    IppsWTFwdState_32f* state;

    ippsWTFwdInitAlloc_32f (&state, fwdFltL, fwdFltLenL, fwdFltOffsL,
                                    fwdFltH, fwdFltLenH, fwdFltOffsH);

    // We substitute wrapping extension in "the beginning of stream"
    // Here should be the same pointers for this offsets,
    // but in the general case it may be different

    ippsWTFwdSetDlyLine_32f( state, &src[10], &src[10]);

    // Forward transform

    ippsWTFwd_32f
         (src, low, high, 6, state);

    ippsWTFwdFree_32f      (state);

    // print decomposition result
    
    printf("approx:\n");
    for(i = 0; i < 6; i++) printf("%.4f; ", low[i]);
    printf("\n");

    printf("details:\n");
    for(i = 0; i < 6; i++) printf("%.4f; ", high[i]);
    printf("\n");

    }
   {
    Ipp32f dst[12];

    IppsWTInvState_32f* state;

    ippsWTInvInitAlloc_32f (&state,
        invFltL, invFltLenL, invFltOffsL,
        invFltH, invFltLenH, invFltOffsH);

    // For this particular case (non-shifted reconstruction)
    // here is first data itself,
    // that we need to place to delay line
    // [(invFltLenL + invFltOffsL - 1) / 2] elements for l. filtering
    // [(invFltLenH + invFltOffsH - 1) / 2] elements for h. filtering

    ippsWTInvSetDlyLine_32f( state, low, high);




    // Inverse transform
    ippsWTInv_32f          (&low[1], &high[1], 5, dst, state);

    // Here are the substitution of the wrapping extension 
    // at the "end of stream" and calculation of last samples of reconstruction
    // We do not use additional buffer and do not copy any data externally,
    // just substitute beginning of input data itself to simulate wrapping

    ippsWTInv_32f          (low, high, 1, &dst[10], state);

    ippsWTInvFree_32f      (state);

    // print reconstruction result
    printf("reconstruction:\n");
    for(i = 0; i < 12; i++) printf("%.0f; ", dst[i]);
    printf("\n");
    }
}

After compiling and running it gives the following console output:

original:
1; -10; 324; 48; -483; 4; 7; -5532; 34; 8889; -57; 54;
approx:
19.1612; 58.5288; 87.8536; 487.5375; -5766.9277; 7432.4502;
details:
0.9387; 249.9611; -458.6568; 2739.2146; -3025.5576; -2070.5762;
reconstruction:
1; -10; 324; 48; -483; 4; 7; -5532; 34; 8889; -57; 54;

The program prints on console the original data, approximation, and details components after forward transform and perfect reconstruction of original data after inverse transform.



Submit feedback on this help topic

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