码迷,mamicode.com
首页 > 其他好文 > 详细

matlab计算样本熵

时间:2020-04-18 14:17:08      阅读:314      评论:0      收藏:0      [点我收藏+]

标签:阈值   nes   向量   sam   amp   end   for   val   function   

计算14通道得脑电数据吗,将得出的样本熵插入Excel表格

a = zeros(1,14);
b = a‘;
  for i =1:14
      b(i) = SampEn(d1_1(i,1:3000),2,0.2*std(d1_1(i,1:3000)));
  end
xlswrite(‘C:\Users\25626\Desktop\滤波后数据\14\样本熵\样本熵.xlsx‘,b,‘Sheet1‘,‘J‘);%数据写入A列

  调用的SampEn函数

function SampEnVal = SampEn(data, m, r)
% SampEn  计算时间序列data的样本熵
% 输入:data是数据一维行向量
%      m重构维数,一般选择1或2,优先选择2,一般不取m>2
%      r 阈值大小,一般选择r=0.1~0.25*Std(data) 数据偏差
% 输出:SampEnVal样本熵值大小

data = data(:)‘;
N = length(data);
Nkx1 = 0;
Nkx2 = 0;

for k = N - m:-1:1
    x1(k, :) = data(k:k + m - 1);
    x2(k, :) = data(k:k + m);
end

for k = N - m:-1:1
    x1temprow = x1(k, :);
    x1temp    = ones(N - m, 1)*x1temprow;   
    dx1(k, :) = max(abs(x1temp - x1), [], 2)‘;   
    Nkx1 = Nkx1 + (sum(dx1(k, :) < r) - 1)/(N - m - 1);    
    x2temprow = x2(k, :);
    x2temp    = ones(N - m, 1)*x2temprow;
    dx2(k, :) = max(abs(x2temp - x2), [], 2)‘;
    Nkx2      = Nkx2 + (sum(dx2(k, :) < r) - 1)/(N - m - 1);
end
Bmx1 = Nkx1/(N - m);
Bmx2 = Nkx2/(N - m);
SampEnVal = -log(Bmx2/Bmx1);
end

  

matlab计算样本熵

标签:阈值   nes   向量   sam   amp   end   for   val   function   

原文地址:https://www.cnblogs.com/andrew-address/p/12725457.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!