# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Compute the sample entropy of a time series

Contributed by:
Jessica Alfonsi (Padova, Italy)

ResourceFunction["SampleEntropy"][ computes the sample entropy of the |

Sample entropy (SampEn) was introduced as a modification of the conceptually similar approximate entropy (ApEn) to quantify the complexity and the unpredictability of fluctuations in a time series, especially in the domain of physiological time series like electroencephalograms (EEGs) for investigating brain signals and electrocardiogram (ECGs or EKGs) for diagnosing heart diseases. SampEn has two additional advantages over ApEn: input data length independence and self-matching is ignored.

A low value of SampEn indicates that the time series *timeseries* is deterministic, whereas a high value indicates randomness and chaotic behaviour.

The default value for the embedding dimension *emdim** *is set as input argument but it is frequently set to 2 in applications.

The value usually suggested for the filter factor *rfilt* is 0.2 times the standard deviation of the input series and is set as an input argument to the function.

The delay time *τ* for subsampling is set to 1 as a default optional argument.

Show the sample entropy of a time series from a uniform distribution of real numbers:

In[1]:= |

Out[3]= |

Set up a nonlinear time series in the periodic regime for the logistic map:

In[4]:= |

Show it:

In[5]:= |

Out[5]= |

Verify the SampleEntropy of the periodic time series is zero:

In[6]:= |

Out[8]= |

Change the *λ* parameter in the logistic map model to set up a chaotic time series:

In[9]:= |

Show it:

In[10]:= |

Out[10]= |

Verify the SampleEntropy of the nonlinear chaotic time series is nonzero:

In[11]:= |

In[12]:= |

Out[12]= |

Show the sample entropy of a time series from a uniform distribution of real numbers with the delay set to *τ* = 2:

In[13]:= |

Out[14]= |

Show the sample entropy results computed for two ECG signals taken from Wolfram Documentation:

In[15]:= |

Out[16]= |

In[17]:= |

Out[18]= |

Sample entropy of a linearly increasing time series is zero:

In[19]:= |

Out[20]= |

Sample entropy of a pure sine wave:

In[21]:= |

Out[15]= |

Sample entropy of a time series sampled from a normal distribution:

In[22]:= |

Out[23]= |

Sample entropy of gaussian fractional noise with Hurst exponential *H *= 0.5:

In[24]:= |

Out[25]= |

- EntropyHub. An open-source toolkit for entropic data analysis. https://www.entropyhub.xyz
- entropy: Approximate and Sample Entropy (documentation from R package pracma). https://rdrr.io/cran/pracma/man/entropy.html
- http://raphaelvallat.com/antropy/build/html/index.html

Wolfram Language 13.0 (December 2021) or above

- 1.0.0 – 22 July 2024

This work is licensed under a Creative Commons Attribution 4.0 International License