I have multiple time-series of length 149 and I would like to denoise them by using wavelet transformations.
This is an example of my data:
t=ts(rnorm(149,5000,1000),start=1065,end=1213)
When I try using the packages wavetresh and waveslim, they both point me 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 my data length should be of lenght 2^x, but I can't overcome this problem. I thought the function up.sample() in waveslim was supposed to help with this, but it didn't do the trick (e.g. up.sample(t,2^8) gives a vector of length 38144). So how do I increase my vector length without inserting an error? I know I could pad with zero's,... but I want to know the best way to do this.
Also, when looking at the example of waveslim, it looks as if the length of the imput serie doesn't fulfill this requirement either (although the example of course does work):
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 basic, but I can't figure it out. Thanks for any help.
Ps: I know I can use other techniques to do this, but I really want to test this approach.
I had a look into the code of dwt and the reason why it works, is that dwtdoes not check whether the length is a power of 2 but whether the length is a multiple of 2^J (actually that is what the error message says: Error in dwt(t) : Sample size is not divisible by 2^J).
With J=4 the length of your time series must thus be a multiple of 16. As you were asuming, up.sample can be used to overcome this issue as it pads the time series with 0's. But you you don't provide the final length but the frequency of upsampling.
Thus
dwt(up.sample(t, 16, 0))
should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With