Is there an error with my sample entropy estimator for 3D multivariate signal?

26 Views Asked by At

I wrote a Matlab function to calculate sample entropy of a multivariate time signal (X,Y,Z positions) similarly to the approximateEntropy built-in function from Matlab. I tried to check my answers using some of the available entropy estimators on the Mathworks File Exchange, but I'm getting slightly different answers. As far as I know, the ones on the File Exchange are only meant to be used with a 1D signal, which is why I wanted to write my own. Any help with fixing the implementation would be greatly appreciated.

function value = mysampen(signal, m, r)
    % Error detection and defaults
    if nargin < 3, error('Not enough parameters.'); end
    if m > length(signal)
        error('Embedding dimension must be smaller than the signal length (m<N).');
    end
    N = length(signal);
    lag = 1;

    % construct embedding dimension for a 3D signal of m and m+1
    X = phaseSpaceReconstruction(signal,lag,m);
    Xp = phaseSpaceReconstruction(signal,lag,m+1);

    % compute distance 
    d_m = pdist(X, 'chebychev');
    d_m1 = pdist(Xp, 'chebychev');

        
        % Compute A and B 
        % sum the number of matches that are within r
        
        B = sum(d_m  <= r);
        A = sum(d_m1 <= r);
        % Sample entropy value
        value = -log(A/B);
 
end
0

There are 0 best solutions below