# Approximate and Sample Entropies Complexity Metrics

By , 17 Jun 2008

## Introduction

There are myriads of signals to analyse with spectral analysis methods: medical (HRV, ECG, EEG, EMG), geological, musical, etc... Among different analysis methods, there is a group of complexity metrics aimed to estimate how complex the signal is. Consider sine wave and random noise. Obviously the sine wave is a simple form of signal while noisy more complex. There are approximate (`ApEn`) and sample (`SmEn`) entropies metrics which provide such quantitative estimation of degree of complexity of the signal. `ApEn `and `SmEn `are better suited for complexity estimation of short-term noisy signals. They have the advantage that they analyse the original signal, as some complexity metrics need the original signal to be quantized to considerably small alphabet. So they are widely used in medicine for HRV data analysis. For EEG data analysis, they are applicable for estimation of some complex neuronal activity.

## Background

You should read my article on the application of `ApEn `and `SmEn `for analysis of HRV data for prediction of paroxismal atrial fibrillation. There, more detailed explanation is presented. Here are just the formulas for `ApEn `and `SmEn`.

## Using the Code

The `ApEn `code is shown below:

```double ApEn(const double* data, unsigned int m, double r, unsigned int N, double std)
{
int Cm = 0, Cm1 = 0;
double err = 0.0, sum = 0.0;

err = std * r;

for (unsigned int i = 0; i < N - (m + 1) + 1; i++) {
Cm = Cm1 = 0;
for (unsigned int j = 0; j < N - (m + 1) + 1; j++) {
bool eq = true;
//m - length series
for (unsigned int k = 0; k < m; k++) {
if (abs(data[i+k] - data[j+k]) > err) {
eq = false;
break;
}
}
if (eq) Cm++;

//m+1 - length series
int k = m;
if (eq && abs(data[i+k] - data[j+k]) <= err)
Cm1++;
}

if (Cm > 0 && Cm1 > 0)
sum += log((double)Cm / (double)Cm1);
}

return sum / (double)(N - m);
}```

The `SmEn `code is shown next:

```double SmEn(const double* data, unsigned int m, double r, unsigned int N, double std)
{
int Cm = 0, Cm1 = 0;
double err = 0.0, sum = 0.0;

err = std * r;

for (unsigned int i = 0; i < N - (m + 1) + 1; i++) {
for (unsigned int j = i + 1; j < N - (m + 1) + 1; j++) {
bool eq = true;
//m - length series
for (unsigned int k = 0; k < m; k++) {
if (abs(data[i+k] - data[j+k]) > err) {
eq = false;
break;
}
}
if (eq) Cm++;

//m+1 - length series
int k = m;
if (eq && abs(data[i+k] - data[j+k]) <= err)
Cm1++;
}
}

if (Cm > 0 && Cm1 > 0)
return log((double)Cm / (double)Cm1);
else
return 0.0;

}```

N is the size of signal pointed by data, std is dispersion of the signal, r is typically used as 0.2. `SmEn `and `ApEn `measure the ratio of how many similar patterns (within error r * std) there are for length m to length m+1.

## History

• 17th June, 2008: Initial post

## About the Author

 Chesnokov Yuriy Engineer Russian Federation Member
Former Cambridge University postdoc (http://www-ucc-old.ch.cam.ac.uk/research/yc274-research.html), Department of Chemistry, Unilever Centre for Molecular Informatics, where I worked on the problem of complexity analysis of cardiac data.

As a subsidiary result we achieved 1st place in the annual PhysioNet/Computers in Cardiology Challenge 2006: QT Interval Measurement (http://physionet.org/challenge/2006/)

My research intrests are: digital signal processing in medicine, image and video processing, pattern recognition, AI, computer vision.

My recent publications are:

Complexity and spectral analysis of the heart rate variability dynamics for distant prediction of paroxysmal atrial fibrillation with artificial intelligence methods. Artificial Intelligence in Medicine. 2008. V43/2. PP. 151-165 (http://dx.doi.org/10.1016/j.artmed.2008.03.009)

Face Detection C++ Library with Skin and Motion Analysis. Biometrics AIA 2007 TTS. 22 November 2007, Moscow, Russia. (http://www.dancom.ru/rus/AIA/2007TTS/ProgramAIA2007TTS.html)

Screening Patients with Paroxysmal Atrial Fibrillation (PAF) from Non-PAF Heart Rhythm Using HRV Data Analysis. Computers in Cardiology 2007. V. 34. PP. 459–463 (http://www.cinc.org/archives/2007/pdf/0459.pdf)

Distant Prediction of Paroxysmal Atrial Fibrillation Using HRV Data Analysis. Computers in Cardiology 2007. V. 34. PP. 455-459 (http://www.cinc.org/archives/2007/pdf/0455.pdf)

Individually Adaptable Automatic QT Detector. Computers in Cardiology 2006. V. 33. PP. 337-341 http://www.cinc.org/archives/2006/pdf/0337.pdf)

Add a reason or comment to your vote: x
Votes of 3 or less require a comment

## Comments and Discussions

Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
 Search this forum Profile popups    Spacing RelaxedCompactTight   Noise Very HighHighMediumLowVery Low   Layout Open AllThread ViewNo JavascriptPreview   Per page 102550
 First Prev Next
 Upper bound for loop question. icestatue 30 Mar '12 - 9:42
 My vote of 4 icestatue 30 Mar '12 - 8:46
 Last Visit: 31 Dec '99 - 18:00     Last Update: 18 May '13 - 6:47 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Rant    Admin

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 17 Jun 2008
Article Copyright 2008 by Chesnokov Yuriy