function [SWT,POWER,Pj]=waventropy_stepen(Y,wtype,wetype,plotOn,sScale,eScale,stepen,donormalize)
if (nargin<8) donormalize=0; end
if (nargin<6) eScale=0; end
if (nargin<5) sScale=1; end
if (nargin<4) plotOn=0; end
if (nargin<3)
    return;
end

[m,n]=size(Y);
if (m<n)
    Y=Y'; [m,n]=size(Y);
end
Y=Y(:,1); [m,n]=size(Y);
maxScale=ceil(m/8);

if (wtype==1)
    Yb=Y; Yb(:,:)=Y(1);
    Ye=Y; Ye(:,:)=Y(m);
    Y2=[Yb; Y; Ye];
    [WAVE,PERIOD,SCALE,COI]=wavelet(Y2,1,0,0.1);
    
    I=find(PERIOD<maxScale);
    WAVE=WAVE(I,m+1:m+m);
    PERIOD=PERIOD(I);
    SCALE=SCALE(I);
    title_add2='DWT';
elseif (wtype==2)
    Yb=zeros(256*4,1); Yb(:,:)=Y(1);
    Ye=zeros(256*4,1); Ye(:,:)=Y(m);
    Y2=[Yb; Y; Ye];
    WAVE=cwt(Y2,1:256,'gaus8');

    WAVE=WAVE(:,256*4+1:256*4+m);
    SCALE=1:256;
    title_add2='CWT';    
else
    Yb=Y; Yb(:,:)=Y(1);
    Ye=Y; Ye(:,:)=Y(m);
    Y2=[Yb; Y; Ye];
    [WAVE,PERIOD,SCALE,COI]=wavelet_cs(Y2,1:512,'DOG',8);
    
    WAVE=WAVE(:,m+1:m+m);
    title_add2='DWT_c_s';    
end

POWER=WAVE.^stepen;
STD=std(Y);
POWER=POWER/STD;
[m,n]=size(POWER);
if ((sScale<1) || (sScale>m))
    sScale=1;
end
if ((eScale<1) || (eScale>m))
    eScale=m;
end
if (wtype~=1)
   POWER=POWER(sScale:eScale,:);
   SCALE=SCALE(sScale:eScale);
   X=[1:n];
end

if (wetype==1)
    Etot=sum(sum(abs(POWER)));
    Pij=POWER/Etot;
    Pj=sum(Pij);
    Smax=log2(m);
    SWT=-sum(Pj.*log2(Pj)/Smax);
    title_add1='Relative wavelet energy method';
else
    [ms,ns]=size(SCALE);
    [mw,nw]=size(POWER);
    SM=sum(POWER');
    Pij=POWER;
    for i=1:ns
        Pij(i,:)=Pij(i,:)/SM(i);
    end

    %Etot=sum(sum(POWER));
    %Pij=POWER/Etot;
    Pj=sum(Pij);
    Smax=log2(m);
    SWT=-sum(Pj.*log2(Pj)/Smax);
    title_add1='Points wavelet energy method';
end
if (donormalize)
    for i=1:size(POWER,1)
        POWER(i,:)=(POWER(i,:)-mean(POWER(i,:)))/std(POWER(i,:));
    end
end

if (plotOn==1)
    if (wtype==1)
       figure; mesh(POWER); title(['Power of C (' title_add2 ')']);
   else
       figure; mesh(X,SCALE,POWER); title(['Power of C (' title_add2 ')']);
   end
    figure;
    subplot(2,1,1); plot(Pj); title([title_add1 ' (' title_add2 ')']);
    subplot(2,1,2); plot(Y); title('Source TS');
end
