计算模糊熵
function [Out_FuzEn,P] = FuzEn(x,m,r,n,tau)
%
% This function calculates fuzzy entropy (FuzEn) of a univariate signal x
%
% Inputs:
%
% x: univariate signal - a vector of size 1 x N (the number of sample points)
% m: embedding dimension
% r: threshold (it is usually equal to 0.15 of the standard deviation of a signal - because we normalize signals to have a standard deviation of 1, here, r is usually equal to 0.15)
% n: fuzzy power (it is usually equal to 2)
% tau: time lag (it is usually equal to 1)
if nargin == 4, tau = 1; end
if nargin == 3, n = 2; tau=1; end
if tau > 1, x = downsample(x, tau); end
N = length(x);
P = zeros(1,2);
xMat = zeros(m+1,N-m);
for i = 1:m+1
xMat(i,:) = x(i:N-m+i-1);
end
for k = m:m+1
count = zeros(1,N-m);
tempMat = xMat(1:k,:);
for i = 1:N-k
% calculate Chebyshev distance without counting self-matches
dist = max(abs(tempMat(:,i+1:N-m) - repmat(tempMat(:,i),1,N-m-i)));
DF=exp((-dist.^n)/r);
count(i) = sum(DF)/(N-m);
end
P(k-m+1) = sum(count)/(N-m);
end
Out_FuzEn = log(P(1)/P(2));
end
计算近似熵
function apen = ApEn( dim, r, data, tau )
%ApEn
% dim : embedded dimension
% r : tolerance (typically 0.2 * std)
% data : time-series data
% tau : delay time for downsampling
if nargin < 4, tau = 1; end
if tau > 1, data = downsample(data, tau); end
N = length(data);
result = zeros(1,2);
for j = 1:2
m = dim+j-1;
phi = zeros(1,N-m+1);
dataMat = zeros(m,N-m+1);
% setting up data matrix
for i = 1:m
dataMat(i,:) = data(i:N-m+i);
end
% counting similar patterns using distance calculation
for i = 1:N-m+1
tempMat = abs(dataMat - repmat(dataMat(:,i),1,N-m+1));
boolMat = any( (tempMat > r),1);
phi(i) = sum(~boolMat)/(N-m+1);
end
% summing over the counts
result(j) = sum(log(phi))/(N-m+1);
end
apen = result(1)-result(2);
end
计算样本熵
function entropy = SampEn(data,r)
l = length(data);
Nn = 0;
Nd = 0;
for i = 1:l-2
for j = i+1:l-2
if abs(data(i)-data(j))
计算排列熵
function [pe hist] = pec(y,m,t)
% Calculate the permutation entropy
% Input: y: time series;
% m: order of permuation entropy
% t: delay time of permuation entropy,
% Output:
% pe: permuation entropy
% hist: the histogram for the order distribution
ly = length(y);
permlist = perms(1:m);
c(1:length(permlist))=0;
for j=1:ly-t*(m-1)
[a,iv]=sort(y(j:t:j+t*(m-1)));
for jj=1:length(permlist)
if (abs(permlist(jj,:)-iv))==0
c(jj) = c(jj) + 1 ;
end
end
end
hist = c;
c=c(find(c~=0));
p = c/sum(c);
pe = -sum(p .* log(p));
Ref:
H. Azami and J. Escudero, Refined Multiscale Fuzzy Entropy based on Standard Deviation for Biomedical Signal Analysis
X Li, G Ouyang, D Richards, Predictability analysis of absence seizures with permutation entropy, Epilepsy.