Click here to Skip to main content
Click here to Skip to main content

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.

ApEn

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

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

About the Author

Chesnokov Yuriy
Engineer
Russian Federation 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)

Sign Up to vote   Poor Excellent
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  
    Spacing  Noise  Layout  Per page   
QuestionUpper bound for loop question.membericestatue30 Mar '12 - 9:42 
GeneralMy vote of 4membericestatue30 Mar '12 - 8:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 17 Jun 2008
Article Copyright 2008 by Chesnokov Yuriy
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid