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
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
All txt files I have used. Thanks
I can't see anything wrong with the code you posted aside from it be rather cumbersome. Here is the same idea using
wentropy
:So long as you use of
wentropy
orshannon_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 yourshannon-entro
function