# The data length is not two. Sample size is not divisible by 2 ^ J (wavelet analysis)

I have several time series of length 149 and I would like to soften them using wavelet transforms.

This is an example of my data:

t=ts(rnorm(149,5000,1000),start=1065,end=1213)

When I try to use the wavetresh and wavelim packages, they both point to the same problem:

library(wavetresh)
wd(t)
Error in wd(t) : Data length is not power of two
library(waveslim)
dwt(t)
Error in dwt(t) : Sample size is not divisible by 2^J

I understand that the length of my data should be 2 ^ x length, but I can't seem to solve this problem. I thought the function up.sample()

in wavelim was supposed to help with this, but it didn't do the trick ( up.sample(t,2^8)

gives a vector of length 38144 for example). So how to increase the length of the vector without inserting the error? I know I can superimpose null, but I want to know how to do it.

In addition, if you look at the wavelim example, it looks as if the capacity length did not satisfy this requirement (although the example certainly works):

data(ibm)
ibm.returns <- diff(log(ibm))
ibmr.haar <- dwt(ibm.returns, "haar")  #works
log2(length(ibm.returns))
[1] 8.523562

I feel like I'm missing something, but I can't figure it out. Thanks for any help.

Ps: I know I can use other methods for this, but I really want to test this approach.

+3

source to share

I looked at the code dwt

and the reason it works is that it dwt

doesn't check if the length is a cardinality of 2 , but if the length is somewhat of 2 ^ J (this is actually an error message :) Error in dwt(t) : Sample size is not divisible by 2^J

.

When the J=4

length of your time series should be a multiple of 16. As you expected, up.sample

you can use to overcome this problem as it overlaps the time series by 0. But you do not provide the final length, but the upsampling rate.

Thus,

dwt(up.sample(t, 16, 0))

must do the trick.

+3

source

All Articles