[R] cannot reproduce matlab wavelet results with R

Martin Ivanov tramni at abv.bg
Fri Mar 27 15:30:29 CET 2009


Dear R users,
I want to get the D1 details reconstructed
to the level of my time series. My original time series is NH$annual[,]
and it has 118 elements. This is the code I use and the results:
library(wavelets)
NHj <- extend.series(X=NH$annual[,], method="reflection",
length="powerof2", j=7);
detach(package:wavelets)
attributes(mra(X=NHj, filter="d4", n.levels=7, boundary="reflection",
fast=TRUE, method="dwt"))$D[[1]][1:20]
[1] -0.0363166651  0.0793856487  0.0229855716 -0.0863862067  0.0586129763
 [6] -0.0552697096  0.0049741291  0.0327406169  0.0006990289 -0.0150729128
[11] -0.0203610433  0.0424490289 -0.0103379856 -0.0072504717 -0.0310480084
[16]  0.0543716287  0.0491613932 -0.1187032803  0.0317373320  0.0132924682
detach(package:wavelets)
library(waveslim)
mra(x=NHj, wf = "d4", J = 7, method = "dwt", boundary =
"reflection")$D1[1:20]
 [1] -0.0363166651  0.0793856487  0.0229855716 -0.0863862067  0.0586129763
 [6] -0.0552697096  0.0049741291  0.0327406169  0.0006990289 -0.0150729128
[11] -0.0203610433  0.0424490289 -0.0103379856 -0.0072504717 -0.0310480084
[16]  0.0543716287  0.0491613932 -0.1187032803  0.0317373320  0.0132924682
detach(package:waveslim)
library(wmtsa)
wavMRDSum(x=NHj, wavelet="d4",levels=1, xform="dwt", reflect=FALSE,
keep.smooth=FALSE, keep.details=TRUE)[1:20]
          t=0           t=1           t=2           t=3           t=4
-0.1449234169  0.0166815113  0.0229855716 -0.0863862067  0.0586129763
          t=5           t=6           t=7           t=8           t=9
-0.0552697096  0.0049741291  0.0327406169  0.0006990289 -0.0150729128
         t=10          t=11          t=12          t=13          t=14
-0.0203610433  0.0424490289 -0.0103379856 -0.0072504717 -0.0310480084
         t=15          t=16          t=17          t=18          t=19
 0.0543716287  0.0491613932 -0.1187032803  0.0317373320  0.0132924682

detach(package:wmtsa)
library(wavethresh)
NHwd.obj <- wd(data=NHj, filter.number=4, family="DaubExPhase",
type="wavelet", bc="symmetric", verbose=TRUE);
NHwd.objA0 <- putC(wd=NHwd.obj, level=6, v=rep(0,2^6), boundary=FALSE,
index=FALSE);
D1 <- accessC(wd=wr(wd=NHwd.objA0, start.level = 6, return.object = TRUE,
verbose = TRUE),level=7,boundary=FALSE);
D1[1:20]
 [1] -0.25283845  0.06657357  0.03389600 -0.04797488  0.05665413 -0.09317851
 [7]  0.06466827  0.06839502 -0.07792329 -0.06458924  0.07678030  0.04101479
[13] -0.08070069  0.06491276 -0.02459910 -0.05140745  0.07088627 -0.03537575
[19]  0.01366095 -0.01599816

As you can see, with wavethresh the results are quite different. Have I
messed something up? Is this the correct way of getting the D1 details? I
am a former matlab user, and the results I get with it are only
reproducible in R with the other 3 packages and the "d2" or "haar"
wavelets. With any other wavelet, e.g. "d4" I get different results.I
would be very thankful to you if you give me some clue.

I really apologize for taking some of your precious time. I wish you fruitful work.

Regards,
Martin
27.03.2009




More information about the R-help mailing list