声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 8083|回复: 3

[共享资源] matlab计算多尺度排列熵程序

[复制链接]
发表于 2015-4-7 21:26 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
  1. function E=MPE(iSig,m,s)
  2. % iSig: input signal; m : Embedded dimension; % s: scale number
  3. for i=1:1:s %i : scale index
  4.     oSig=CoarseGrain(iSig,i); E(i)=PE(oSig,m);
  5. end
  6. %Coarse Grain Procedure. See Equation (11) % iSig: input signal ; s : scale numbers ; oSig: output
  7. function oSig=CoarseGrain(iSig,s)
  8.     N=length(iSig); %length of input signal
  9. for i=1:1:N/s
  10.     oSig(i)=mean(iSig((i-1)*s+1:i*s));
  11. end
  12. % function to calculate permutation entropy % signal: input signal; m: embedded dimension
  13. function E=PE(sig,m)
  14. N=length(sig); %length of signal
  15. v=[1:m]; % m=3, v=[1 2 3]; m=5, v=[1 2 3 4 5]
  16. all_pemu=perms(v); % generate all possible permutations
  17. perm_num=factorial(m); % calculate m! to obtain the number of all possible permutations
  18. for i=1:1:perm_num
  19.     key(i)=genkey(all_pemu(i,:)); %transform a vector into an integer; ex: [4 3 1 2] ==> 4321
  20. end
  21. pdf=zeros(1,perm_num); %initialize frequency array
  22. for i=1:1:N-m+1
  23.     pattern=sig(i:i+m-1); % obtain pattern vector from signal.
  24.     [Y,order]=sort(pattern); % sort the pattern vector; order represents the permutation order.
  25.     pkey=genkey(order); %transform the order vector into an integer.
  26.     id=find(key==pkey); pdf(id)=pdf(id)+1;
  27. end
  28. pdf=pdf/(N-m+1); % normalize the frequency array to obtain probability density function.
  29. %calculate the entropy
  30. E=0;
  31. for i=1:1:perm_num
  32.     if (pdf(i)~=0)
  33.         E=E-pdf(i)*log(pdf(i)); %calculate entropy.
  34.     end
  35. end
  36. perm_num = min(perm_num, N-m+1);
  37. E=E/log(perm_num); %normalize entropy.
  38. %function to transform a vector into an integer; ex: [2 1 3]==> 213, [4 3 1 2] ==> 4321
  39. function key=genkey(x)
  40. key=0;
  41. for i=1:1:length(x)
  42.    key=key*10+x(i);
  43. end
复制代码


回复
分享到:

使用道具 举报

发表于 2016-3-2 09:30 | 显示全部楼层
很好,谢谢啦
发表于 2017-9-4 16:41 | 显示全部楼层
感谢您的程序和分享
发表于 2020-11-14 09:36 | 显示全部楼层
非常感谢!有会用的朋友么?
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-12-23 07:54 , Processed in 0.055343 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表