Question

I have been using R packages wavethresh in order to get wavelet transforms and packet wavelet transforms. I can easily get coefficients of the wavelet transform on the wavelet basis. However, I can't manage getting the wavelet basis.

I'm using standard wavelet filters for the moment : Daubechies Least Asymmetric.

Here is a sample of my code for wavelet transform :

data <- cos(1:512/(10*pi))
wave <- wd(data)

and for wavelet packets transform :

wave <- wp(Temperature[,1])
coeffs <- MaNoVe(wave.th)
l <- print(coeffs)

I have tried a few things for wavelet packet transform :

basis <- matrix(NA,length(l$level),512)
for (i in 1:length(l$level))
    basis[i,] <- drawwp.default(l$level[i],l$pkt[i],resolution=512)

but I get only a few functions and not the entire basis. Furthermore, I am not sure these functions are the ones I want.

Here is the link to the package documentation : wavethresh.pdf. But If you have solutions to my problem in an other R package, it would be perfect too ;)

Thanks a lot for your help !

Was it helpful?

Solution 2

My problem is solved ! I have used the package wmtsa instead of wavethresh.

To construct the basis, in both cases (wavelet transform and packets wavelet transform), you can use the reconstruct method to a certain wavelet w. This one has all coefficients set to 0 except one which is set to 1.

basis <- matrix(NA,2^lvl,2^lvl)
compt <- 1
w$data$s9 <- 0
for (i in 1:lvl)
    w$data[[i]]<-rep(0,2^(lvl-i))
for (i in 1:lvl){
    for (j in 1:2^(lvl-i)){
            w$data[[i]][j] <- 1
        basis[,compt] <- reconstruct(b)
        w$data[[i]][j] <- 0
        compt <- compt + 1
    }
}

lvl is the wavelet resolution level.

One can do the same for the wavelet packets transform.

OTHER TIPS

Just for the record: I'm the primary author of wavethresh and I also think wmtsa is a fine package.

The code that you originally wrote for wavethresh should work. I just tried it on an arbitrary data set of length 512 (because I don't have access to your data!) and it seemed to work ok and the `basis' array containing 215 elements. The function plot(coeffs) also produced a time-frequency plot so one can see the particular tiling of the time-frequency plane.

Referring to your two posts. The function `drawwp.default' actually does precisely what you mention in your second post. To get a picture (or vector of values) of the particular wavelet packet a sequence containing all zeros and one one is inverted. This is a well-known trick generally and has been in wavethresh since 1993 for wavelets (in the function draw()).

What draw and drawwp.default won't do is get the translate right. It tries to pick a nice value of the translate so you get a nice picture. That's why the argument to drawwp.default contains the scale level, the `number of oscillations parameter' but not the translate value. However, it is simple to translate the wavelet up or down the axis and how you do it will depend on what boundary conditions you're assuming.

There did appear (to me at least) to be one typo in your original post. The object wave' in line 3 becomeswave.th' in line 4. However, I ignored this and took them to be the same object. I guess you might have been doing some thresholding which was not relevant to this discussion :)

All the best, Guy Nason

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top