Entropy calculation on a time serie moving window

1.3k views Asked by At

I have just started playing with Matlab and I would like to get the entropy value for a moving window.

I have a time serie ts 1432x1 and I would like to get the entropy value for a moving window length= N, so if N = 40 I should get first entropy value for the ts(1:40), then ts(2:41) and so on up to the latest ts point.

The output should be an array 1392x1 (N points shorter than the input time serie).

I am interested in any different entropy method.

Edit I have tried this example found in Matlab central, but it doesn't work

function [vectorout]=entropy_moving(vectorin,eFave)

    l_vectorin=length(vectorin);
    l_half_interval=eFave;

    ifor1=1;
    for ifor1=1:l_vectorin

        if ifor1>l_half_interval&&ifor1<(l_vectorin-l_half_interval)
            vectorout(ifor1)=shannon_entro(vectorin(ifor1-l_half_interval:ifor1+l_half_interval));

        elseif ifor1>=(l_vectorin-l_half_interval)
            vectorout(ifor1)=shannon_entro(vectorin(ifor1:l_vectorin));

        end
    end

where I have used shannon_entro instead of wentropy. Any help really appreciated.

PS posted here also since got no answer in Matlab central.

Update: To better explain what I should get, I have created 5 different 40 point length series, and calculate for each one the wentropy.

Result is shown here

enter image description here

The for loop should return an array 861x1 whose first 5 values must be out1_40, out2_41, out3_42 and so on.

I have uploded here

Full serie

1_40

2_41

3_42

4_43

5_44

All txt files I have used. Thanks

1

There are 1 answers

0
Dan On

I can't see anything wrong with the code you posted aside from it be rather cumbersome. Here is the same idea using wentropy:

vectorout = zeros(numel(vectorin),1)
for e = 1:numel(vectorin)
    vectorout(e) = wentropy(vectorin(e:min(e+eFave-1, end)), 'shannon');
end

So long as you use of wentropy or shannon_entro is correct, this aught to work (and is really the same as the code you posted). If your code doesn't work, I would suspect the problem lies within your shannon-entro function