近似熵的一种快速实用算法
Pincus提出的近似熵算法中有很多冗余的计算,效率低,速度慢,不利于实际应用,洪波等人在定义的基础上引入二值距离矩阵的概率,提出了一种实用快速的算法。
function ApEn=EntropyCompute(sig,m,r0)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 计算一维信号的近似熵,采用快速算法
% sig: 待求近似熵的源信号
% m: 一般取 2
% r0: 一般取0.1 ~ 0.25
% Ref: 近似熵:一种应用于短数据的的复杂性度量,杨福生
% 近似熵及其在机械设备故障诊断中的应用,胥永刚
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N = size(sig,1);
r=r0*std(sig);
d=zeros(N,N);
%%% 计算距离矩阵 %%%
for i=1:N
d(i,:)=abs(sig(i)-sig) < r;
end
%%% 计算C2 %%%
c2=zeros(1,N-m+1);
for i=1:N-m+1
for j=1:N-1;
buf = d(i,j) & d(i+1,j+1);
c2(i)=c2(i)+buf;
end
end
Fi(1)=sum(log(c2))/(N-m+1);
m=m+1;
%%% 计算C3 %%%
c3=zeros(1,N-m+1);
for i=1:N-m+1
for j=1:N-2;
c3(i)=c3(i)+(d(i,j) & d(i+1,j+1) & d(i+2,j+2));
end
end
Fi(2)=sum(log(c3))/(N-m+1);
ApEn=Fi(1)-Fi(2);
return;