function decomp=levels_plot_new(x,L,wvlt)
%
% Called like wavedec, this function computes and plots
% the L+1 levels of the resulting decomposition, all
% levels being represented at the original input signal
% sample rate
%
% Observe that since waverec drops any part of
% its results for n < 1, there may be non-zero
% parts of each output level which are not
% computed or displayed, but these sum to zero
% over the levels.
%
% The returned decomp is a matrix with L+2 rows and length(x)
% columns. The first row is the input signal x, reconsructed
% by summing the L+1 levels of the wavelet decomposition. The
% second row is the L+1 (lowest frequency) level of the
% decomposition, sometimes called the "approximation". The
% subsequent rows follow an obvious order, the (L+2)th being
% the first (highest frequency) level of the decomposition.
%
%
[W,Mr]=wavedec(x,L,wvlt);
Lp1=L+1;
ind=0;
decomp=zeros(1,length(x));
for k = 1:Lp1
    Wplot=zeros(1,length(W));
    indt=ind+Mr(k);
    Wplot((ind+1):indt)=W((ind+1):indt);
    xl=waverec(Wplot,Mr,wvlt);
    decomp(k+1,:)=xl;
    ind=indt;
    decomp(1,:)=decomp(1,:)+xl;
end
Lp2=L+2;
figure
for k = 1:Lp2
    subplot(Lp2,1,k), plot(decomp(k,:))
end
return

