├── FuzEn_MFs.m └── README.md /FuzEn_MFs.m: -------------------------------------------------------------------------------- 1 | function entr = FuzEn_MFs(ts, m, mf, rn, local,tau) 2 | % This function calculates fuzzy entropy (FuzEn) of a univariate 3 | % signal ts, using different fuzzy membership functions (MFs)% 4 | % Inputs: 5 | % ts --- time-series - a vector of size 1 x N (the number of sample points) 6 | % m --- embedding dimension 7 | % mf --- membership function, chosen from the follwing 8 | % 'Triangular', 'Trapezoidal', 'Z_shaped', 'Bell_shaped', 9 | % 'Gaussian', 'Constant_Gaussian', 'Exponential' 10 | % rn --- threshold r and order n (scalar or vector based upon mf) 11 | % scalar: threshold 12 | % vector: [threshold r, order n] 13 | % local --- local similarity (1) or global similarity (0) 14 | % tau --- time delay 15 | % 16 | % Ref.: 17 | % [1] H. Azami, P. Li, S. Arnold, J. Escudero, and A. Humeau-Heurtier, "Fuzzy Entropy Metrics for the Analysis 18 | % of Biomedical Signals: Assessment and Comparison", IEEE ACCESS, 2019. 19 | % 20 | % +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 21 | % If you use the code, please make sure that you cite Reference [1] 22 | % +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 23 | % 24 | % Authors: Peng Li and Hamed Azami 25 | % Emails: pli9@bwh.harvard.edu and hmd.azami@gmail.com 26 | % 27 | % 28 | % For Cr=0.1, the threshold r and order n should be selected as follows: 29 | % 30 | % 'Triangular'------ rn=0.3 31 | % 'Trapezoidal'------ rn=0.1286 32 | % 'Z_shaped'------ rn=0.1309 33 | % 'Bell_shaped'------ rn=[0.1414 2] % means r=0.1414 and n=2 34 | % 'Bell_shaped'------ rn=[0.1732 3] % means r=0.1732 and n=3 35 | % 'Gaussian'------ rn=0.1253 36 | % 'Constant_Gaussian'------ rn=0.0903 37 | % Exponential------ rn=[0.0077 3] % means r=0.0077 and n=3 38 | % Exponential------ rn=[0.0018 4] % means r=0.0018 and n=4 39 | % 40 | % 41 | % Example x=rand(1,1000);FuzEn_MFs(x, 2, 'Bell_shaped', [0.1414*std(x) 2], 0,1) 42 | 43 | 44 | if nargin == 5, tau = 1; end 45 | if nargin == 4, local = 0; tau=1; end 46 | if nargin == 3, rn=0.2*std(ts);local = 0; tau=1; end 47 | 48 | % parse inputs 49 | narginchk(6, 6); 50 | N = length(ts); 51 | 52 | % normalization 53 | %ts = zscore(ts(:)); 54 | 55 | % reconstruction 56 | indm = hankel(1:N-m*tau, N-m*tau:N-tau); % indexing elements for dim-m 57 | indm = indm(:, 1:tau:end); 58 | ym = ts(indm); 59 | 60 | inda = hankel(1:N-m*tau, N-m*tau:N); % for dim-m+1 61 | inda = inda(:, 1:tau:end); 62 | ya = ts(inda); 63 | 64 | if local 65 | ym = ym - mean(ym, 2)*ones(1, m); 66 | ya = ya - mean(ya, 2)*ones(1, m+1); 67 | end 68 | 69 | % inter-vector distance 70 | % if N < 1e4 71 | cheb = pdist(ym, 'chebychev'); % inf-norm 72 | cm = feval(mf, cheb, rn); 73 | 74 | cheb = pdist(ya, 'chebychev'); 75 | ca = feval(mf, cheb, rn); 76 | % else % allocating space takes longer than loop, still debugging 77 | % for k = N-m*tau:-1:1 78 | % ymrow = ym(k, :); 79 | % xmrowmt = ones(N-m*tau, 1)*ymrow; 80 | % dmtemp = max(abs(ym - xmrowmt), [], 2)'; 81 | % cm(k) = sum(feval(mf, dmtemp, cr)); 82 | % 83 | % yarow = ya(k, :); 84 | % xarowmt = ones(N-m*tau, 1)*yarow; 85 | % datemp = max(abs(ya - xarowmt), [], 2)'; 86 | % ca(k) = sum(feval(mf, datemp, cr)); 87 | % end 88 | % end 89 | 90 | 91 | % output 92 | entr = -log(sum(ca) / sum(cm)); 93 | end 94 | 95 | % membership functions 96 | function c = Triangular(dist, rn) 97 | c = zeros(size(dist)); 98 | c(dist <= rn) = 1 - dist(dist <= rn) ./ rn; 99 | end 100 | 101 | function c = Trapezoidal(dist, rn) 102 | c = zeros(size(dist)); 103 | c(dist <= rn) = 1; 104 | c(dist <= 2*rn & dist > rn) = 2 - dist(dist <= 2*rn & dist > rn) ./ rn; 105 | end 106 | 107 | function c = Z_shaped(dist, rn) 108 | c = zeros(size(dist)); 109 | r1 = dist <= rn; 110 | r2 = dist > rn & dist <= 1.5*rn; 111 | r3 = dist > 1.5*rn & dist <= 2*rn; 112 | c(r1) = 1; 113 | c(r2) = 1 - 2.*((dist(r2)-rn)./rn).^2; 114 | c(r3) = 2.*((dist(r3)-2*rn)./rn).^2; 115 | end 116 | 117 | function c = Bell_shaped(dist, rn) 118 | c = 1 ./ (1 + abs(dist ./ rn(1)).^(2*rn(2))); 119 | end 120 | 121 | function c = Gaussian(dist, rn) 122 | c = exp(-(dist./(sqrt(2)*rn)).^2); 123 | end 124 | 125 | function c = Constant_Gaussian(dist, rn) 126 | c = ones(size(dist)); 127 | c(dist>rn) = exp(-log(2).*((dist(dist>rn) - rn)./rn).^2); 128 | end 129 | 130 | function c = Exponential(dist, rn) 131 | c = exp(-dist.^rn(2) ./ rn(1)); 132 | end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FuzzyEntropy_Matlab 2 | Here are the Matlab codes used in "Fuzzy Entropy Metrics for the Analysis of Biomedical Signals: Assessment and Comparison, IEEE ACCESS, 2019", including fuzzy entropy with triangular, trapezoidal, Z-shaped, bell-shaped, Gaussian, constant-Gaussian, and exponential functions. 3 | --------------------------------------------------------------------------------