Ask Your Question
1

Find the high frequency part of the 1D haar wavelet transform

asked 2014-01-04 02:46:49 -0600

stereomatching gravatar image

updated 2014-01-04 10:33:18 -0600

I have two question

1 : what is the high pass filter of 1D haar wavelet transform?

2 : Is this a correct way to apply wavelet transform?

According to the wikipedia, 1D wavelet transform can be done by simple convolution.

dwt

Ex : x[] = {1 2 3 4}, hfilter[] = {1, -1}, hfilter_inv[] = {-1, 1}

y[0] = x[0] * 1; y[1] = x[0] * -1 + x[1] * 1; y[2] = x[2] * -1 + x[2] * 1; y[3] = x[3] * -1 + x[3] * 1;

after down sampling, y[0] = x[0] * 1; y[1] = x[1] * -1 + x[2] * 1;

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-01-05 08:35:10 -0600

Nghia gravatar image

This post will hopefully answer 1), but not 2), since I'm not familiar with that formulation.

The 1D Haar transform is incredibly simple to code (yet I always see complex explanation). Here is one way to do it:

// Unormalized version
// assumes width is a power of 2
void Haar1D(float *A, int width)
{
    float tmp[width]; // some compilers might not like this

    while(width > 1) {
        width /= 2;

        for(int i=0; i < width; i++) {
            tmp[i] = (A[2*i] + A[2*i+1]) * 0.5;
            tmp[width + i] = (A[2*i] - A[2*i+1]) * 0.5;
        }

        memcpy(A, tmp, width*2*sizeof(float));
    }
}

The value at A[0] is the average of the 1D array, every other value are the detail coefficients. They are the "edge" information at different resolutions, so they might be the high frequency values you are interested in.

The normalized version is similar to the above

void Haar1D(float *A, int width)
{
    float norm = 1.0f/sqrt(width);

    for(int i=0; i < width; i++)
        A[i] *= norm;    

    float tmp[width];

    while(width > 1) {
        width /= 2;

        for(int i=0; i < width; i++) {
            tmp[i] = (A[2*i] + A[2*i+1]) * sqrt(2);
            tmp[width + i] = (A[2*i] - A[2*i+1]) * sqrt(2);
        }

        memcpy(A, tmp, width*2*sizeof(float));
    }
}

I've used these functions in the past based on material from http://www.multires.caltech.edu/teaching/courses/waveletcourse/

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-01-04 02:46:49 -0600

Seen: 1,309 times

Last updated: Jan 05 '14