Skip to main content
. 2024 Feb 20;10:e1852. doi: 10.7717/peerj-cs.1852

Algorithm 2. Calculate the approximate and sample entropy.

Input: Timeseries
Output: ApEn, SampEn
x(l),l=1,2,..,M Given a time series
p Embedding dimension
z Tolerance
Stage 1: Extend x(l) to the pth vector Up(l)
Up(l)=[x(l),u(l+1),...,u(l+p1)]l=1,2,...,Mp+1
Stage 2: Calculate the distance between Up(l) and Up(j)
D[Up(l),Up(j)]=maxt=0,1,...,p1{|x(l+t)x(j+t)|}j=1,2,...,Mp+1 and jl
Stage 3: Compute approximate entropy
  • Measure the regularity and frequency of patterns within tolerance r

:
Clp(z)=NumberofjsuchthatD[Up(l),Up(j)]zMp+1
  • Compute the mean value of the logarithm of Clp(z):

ψp(z)=l=1Mp+1ln[Clp(z)]Mp+1
  • The ApEn can be defined:

ApEn(p,z)=ψp(z)ψp+1(z)
Stage 4: Compute sample entropy
  • Compute the two coefficients:

Alp(z)=j=1,jlMpnumberoftimesthatD[Up+1(l),Up+1(j)]<zMp1
Blp(z)=j=1,jlMpnumberoftimesthatD[Up(l),Up(j)]<zMp1
  • Add them as fallow:

Ap(z)=l=1MpAlp(z)Mp
Bp(z)=l=1MpBlp(z)Mp
  • The SampEn can be defined:

SampEn(p,z)=ln[Ap(z)Bp(z)]