chybeyond 发表于 2015-4-7 21:26

matlab计算多尺度排列熵程序

function E=MPE(iSig,m,s)
% iSig: input signal; m : Embedded dimension; % s: scale number
for i=1:1:s %i : scale index
    oSig=CoarseGrain(iSig,i); E(i)=PE(oSig,m);
end
%Coarse Grain Procedure. See Equation (11) % iSig: input signal ; s : scale numbers ; oSig: output
function oSig=CoarseGrain(iSig,s)
    N=length(iSig); %length of input signal
for i=1:1:N/s
    oSig(i)=mean(iSig((i-1)*s+1:i*s));
end
% function to calculate permutation entropy % signal: input signal; m: embedded dimension
function E=PE(sig,m)
N=length(sig); %length of signal
v=; % m=3, v=; m=5, v=
all_pemu=perms(v); % generate all possible permutations
perm_num=factorial(m); % calculate m! to obtain the number of all possible permutations
for i=1:1:perm_num
    key(i)=genkey(all_pemu(i,:)); %transform a vector into an integer; ex: ==> 4321
end
pdf=zeros(1,perm_num); %initialize frequency array
for i=1:1:N-m+1
    pattern=sig(i:i+m-1); % obtain pattern vector from signal.
    =sort(pattern); % sort the pattern vector; order represents the permutation order.
    pkey=genkey(order); %transform the order vector into an integer.
    id=find(key==pkey); pdf(id)=pdf(id)+1;
end
pdf=pdf/(N-m+1); % normalize the frequency array to obtain probability density function.
%calculate the entropy
E=0;
for i=1:1:perm_num
    if (pdf(i)~=0)
      E=E-pdf(i)*log(pdf(i)); %calculate entropy.
    end
end
perm_num = min(perm_num, N-m+1);
E=E/log(perm_num); %normalize entropy.
%function to transform a vector into an integer; ex: ==> 213, ==> 4321
function key=genkey(x)
key=0;
for i=1:1:length(x)
   key=key*10+x(i);
end

schou0419 发表于 2016-3-2 09:30

很好,谢谢啦

zhangnan3509 发表于 2017-9-4 16:41

感谢您的程序和分享

chengle80 发表于 2020-11-14 09:36

非常感谢!有会用的朋友么?
页: [1]
查看完整版本: matlab计算多尺度排列熵程序