时间序列移动窗口的熵计算

时间:2014-11-13 14:29:05

标签: matlab entropy

我刚开始玩Matlab,我想获得移动窗口的熵值。

我有一个1432x1的时间系列,我想获得移动窗口长度= N的熵值,所以如果N = 40,我应该获得ts的第一个熵值(1:40),然后是ts( 2:41)等等到最新的ts点。

输出应为1392x1数组(N点比输入时间系列短)。

我对任何不同的熵方法感兴趣。

编辑我试过在Matlab中心找到这个例子,但它不起作用

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

我使用过shannon_entro而不是wentropy。任何帮助真的很感激。

由于在Matlab中心没有得到答案,PS也发布在这里。

更新:为了更好地解释我应该得到什么,我创建了5个不同的40点长度系列,并为每个系列计算了熵。

结果显示在这里

enter image description here

for循环应返回一个数组861x1,其前5个值必须为out1_40,out2_41,out3_42,依此类推。

我已经在这里上传

Full serie

1_40

2_41

3_42

4_43

5_44

我用过的所有txt文件。感谢

1 个答案:

答案 0 :(得分:0)

我看不出你发布的代码有什么问题是相当麻烦的。以下是使用wentropy

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

只要您使用wentropyshannon_entro是正确的,这就可以了(并且与您发布的代码完全相同)。如果您的代码不起作用,我会怀疑问题出在您的shannon-entro函数

相关问题