function Dj = wavmodwtdet(Wv,J,filtertype); %% Description % Computes the Jth detail given a wavelet and scaling vector. % % USAGE: Dj is the jth level detail coefficient reconstructed from the % wavelet coefficients. To get the coefficients, use taylorMODWT. The % argument filtertype is the scaling filter to be used in the % reconstruction process, same as what was used in taylorMODWT. % % Example: % Dj = invmodwt(W,5,'C6_scaling.txt'); % % Returns the jth level detail reconstructed from the wavelet coeffient % vector Wj. For a reference, consult Percivals text, Wavelet Methods for % time series analysis. % % INPUT: Wv is a vector from the wavelet output matrix from taylorMODWT. J % is the detail index to be returned, and filtertype is the .txt file % containing the scaling filter coefficients (like the C6 or Haar). % OUTPUT: The jth level detail coefficient. To get all of the detail % coefficients, loop over wavelet matrix rows, and use W(j,:) at each step % to compute the jth detail coefficient. To compute the smooth, subtract % off the sum of all details from the time series, X. N = max(size(Wv)); % if(floor(log2(N)) ~= log2(N)) % disp('Make the time series a power of 2 in length'); % end % the circular shift matrix T = spdiags(ones(N,1),-1,N,N); T(1,end) = 1; % the wavelet scaling filter g=load(filtertype); g=g./(sqrt(2)); L=length(g); % calculate the wavelet filter for l=0:L-1 h(l+1)=(-1)^(l)*g(L-1-l+1); end V=zeros(J,N); %V(J,:)=Sc; W=zeros(J,N); W(J,:)=Wv; % calculate inverse MODWT for j=2:J for j=J:-1:2 for t=0:(N-1) k=t; V(j-1,t+1)=h(0+1)*W(j,k+1)+g(0+1)*V(j,k+1); for n=1:(L-1) k=k+2^(j-1); if k>=N; k=mod(k,N); end V(j-1,t+1)=V(j-1,t+1)+h(n+1)*W(j,k+1)+g(n+1)*V(j,k+1); end end end % calculate inverse MODWT for j=1 j=1; for t=0:(N-1) k=t; V0(t+1)=h(0+1)*W(j,k+1)+g(0+1)*V(j,k+1); for n=1:(L-1) k=k+2^(j-1); if k>=N; k=mod(k,N); end V0(t+1)=V0(t+1)+h(n+1)*W(j,k+1)+g(n+1)*V(j,k+1); end end Dj=V0;