Wavelet reconstruction of time series

前端 未结 1 586
情话喂你
情话喂你 2020-12-09 23:45

I\'m trying to reconstruct the original time series from a Morlet\'s wavelet transform. I\'m working in R, package Rwave, function cwt. The result of this function is a mat

相关标签:
1条回答
  • 2020-12-10 00:31

    I have been working on this topic currently, using the same paper. I show you code using an example dataset, detailing how I implemented the procedure of wavelet decomposition and reconstruction.

    # Lets first write a function for Wavelet decomposition as in formula (1):
    mo<-function(t,trans=0,omega=6,j=0){
      dial<-2*2^(j*.125)
      sqrt((1/dial))*pi^(-1/4)*exp(1i*omega*((t-trans)/dial))*exp(-((t-trans)/dial)^2/2)
    }
    
    # An example time series data: 
    y<-as.numeric(LakeHuron)
    

    From my experience, for correct reconstruction you should do two things: first subject the mean to get a zero-mean dataset. I then increase the maximal scale. I mostly use 110 (although the formula in the Torrence and Compo suggests 71)

    # subtract mean from data:
    y.m<-mean(y)
    y.madj<-y-y.m
    
    # increase the scale:
    J<-110
    wt<-matrix(rep(NA,(length(y.madj))*(J+1)),ncol=(J+1))
    
    # Wavelet decomposition:
    for(j in 0:J){
    for(k in 1:length(y.madj)){
      wt[k,j+1]<-mo(t=1:(length(y.madj)),j=j,trans=k)%*%y.madj
      }
    }
    
    #Extract the real part for the reconstruction:
    wt.r<-Re(wt)
    
    # Reconstruct as in formula (11):
    dial<-2*2^(0:J*.125)
    rec<-rep(NA,(length(y.madj)))
    for(l in 1:(length(y.madj))){
      rec[l]<-0.2144548*sum(wt.r[l,]/sqrt(dial))
    }
    rec<-rec+y.m
    
    plot(y,type="l")
    lines(rec,col=2)
    

    As you can see in the plot, it looks like a perfect reconstruction:

    0 讨论(0)
提交回复
热议问题