TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
sampenc.m
Go to the documentation of this file.
1 function [e,A,B]=sampenc(y,M,r);
2 %function [e,A,B]=sampenc(y,M,r);
3 %
4 %Input
5 %
6 %y input data
7 %M maximum template length
8 %r matching tolerance
9 %
10 %Output
11 %
12 %e sample entropy estimates for m=0,1,...,M-1
13 %A number of matches for m=1,...,M
14 %B number of matches for m=1,...,M excluding last point
15 %code from physionet
16 n=length(y);
17 lastrun=zeros(1,n);
18 run=zeros(1,n);
19 A=zeros(M,1);
20 B=zeros(M,1);
21 p=zeros(M,1);
22 e=zeros(M,1);
23 for i=1:(n-1)
24  nj=n-i;
25  y1=y(i);
26  for jj=1:nj
27  j=jj+i;
28  if abs(y(j)-y1)<r
29  run(jj)=lastrun(jj)+1;
30  M1=min(M,run(jj));
31  for m=1:M1
32  A(m)=A(m)+1;
33  if j<n
34  B(m)=B(m)+1;
35  end
36  end
37  else
38  run(jj)=0;
39  end
40  end
41  for j=1:nj
42  lastrun(j)=run(j);
43  end
44 end
45 N=n*(n-1)/2;
46 p(1)=A(1)/N;
47 e(1)=-log(p(1));
48 for m=2:M
49  p(m)=A(m)/B(m-1);
50  e(m)=-log(p(m));
51 end
sampenc
function sampenc(in y, in M, in r)