1个回答
展开全部
样本熵代码
function [shang]=jss(xdate)
m=2;
n=length(xdate);
r=0.2*std(xdate);
cr=[];
gn=1;
gnmax=m;
while gn<=gnmax
x2m=zeros(n-m+1,m);%存放变换后的向量
d=zeros(n-m+1,n-m);% 存放距离结果的矩阵
cr1=zeros(1,n-m+1);%存放
k=1;
for i=1:n-m+1
for j=1:m
x2m(i,j)=xdate(i+j-1);
end
end
x2m;
for i=1:n-m+1
for j=1:n-m+1
if i~=j
d(i,k)=max(abs(x2m(i,-x2m(j,));%计算各个元素和响应元素的距离
k=k+1;
end
end
k=1;
end
d;
for i=1:n-m+1
[k,l]=size(find(d(i,<r));%将比R小的个数传送给L
cr1(1,i)=l;
end
cr1;
cr1=(1/(n-m))*cr1;
sum1=0;
for i=1:n-m+1
if cr1(i)~=0
sum1=sum1+log(cr1(i));
end
end
cr1=1/(n-m+1)*sum1;
cr(1,gn)=cr1;
gn=gn+1;
m=m+1;
end
cr;
shang=cr(1,1)-cr(1,2);
function [shang]=ybs(xdate)
m=2;
n=length(xdate);
r=0.2*std(xdate);
cr=[];
gn=1;
gnmax=m;
while gn<=gnmax
x2m=zeros(n-m+1,m);%存放变换后的向量
d=zeros(n-m+1,n-m);% 存放距离结果的矩阵
cr1=zeros(1,n-m+1);%存放
k=1;
for i=1:n-m+1
for j=1:m
x2m(i,j)=xdate(i+j-1);
end
end
x2m;
for i=1:n-m+1
for j=1:n-m+1
if i~=j
d(i,k)=max(abs(x2m(i,-x2m(j,));%计算各个元素和响应元素的距离
k=k+1;
end
end
k=1;
end
d;
for i=1:n-m+1
[k,l]=size(find(d(i,<r));%将比R小的个数传送给L
cr1(1,i)=l;
end
cr1;
cr1=(1/(n-m))*cr1;
sum1=0;
for i=1:n-m+1
sum1=sum1+cr1(i);
end
end
cr1=1/(n-m+1)*sum1;
cr(1,gn)=cr1;
gn=gn+1;
m=m+1;
end
cr;
shang=-log(cr(1,1)/cr(1,2));
function [shang]=jss(xdate)
m=2;
n=length(xdate);
r=0.2*std(xdate);
cr=[];
gn=1;
gnmax=m;
while gn<=gnmax
x2m=zeros(n-m+1,m);%存放变换后的向量
d=zeros(n-m+1,n-m);% 存放距离结果的矩阵
cr1=zeros(1,n-m+1);%存放
k=1;
for i=1:n-m+1
for j=1:m
x2m(i,j)=xdate(i+j-1);
end
end
x2m;
for i=1:n-m+1
for j=1:n-m+1
if i~=j
d(i,k)=max(abs(x2m(i,-x2m(j,));%计算各个元素和响应元素的距离
k=k+1;
end
end
k=1;
end
d;
for i=1:n-m+1
[k,l]=size(find(d(i,<r));%将比R小的个数传送给L
cr1(1,i)=l;
end
cr1;
cr1=(1/(n-m))*cr1;
sum1=0;
for i=1:n-m+1
if cr1(i)~=0
sum1=sum1+log(cr1(i));
end
end
cr1=1/(n-m+1)*sum1;
cr(1,gn)=cr1;
gn=gn+1;
m=m+1;
end
cr;
shang=cr(1,1)-cr(1,2);
function [shang]=ybs(xdate)
m=2;
n=length(xdate);
r=0.2*std(xdate);
cr=[];
gn=1;
gnmax=m;
while gn<=gnmax
x2m=zeros(n-m+1,m);%存放变换后的向量
d=zeros(n-m+1,n-m);% 存放距离结果的矩阵
cr1=zeros(1,n-m+1);%存放
k=1;
for i=1:n-m+1
for j=1:m
x2m(i,j)=xdate(i+j-1);
end
end
x2m;
for i=1:n-m+1
for j=1:n-m+1
if i~=j
d(i,k)=max(abs(x2m(i,-x2m(j,));%计算各个元素和响应元素的距离
k=k+1;
end
end
k=1;
end
d;
for i=1:n-m+1
[k,l]=size(find(d(i,<r));%将比R小的个数传送给L
cr1(1,i)=l;
end
cr1;
cr1=(1/(n-m))*cr1;
sum1=0;
for i=1:n-m+1
sum1=sum1+cr1(i);
end
end
cr1=1/(n-m+1)*sum1;
cr(1,gn)=cr1;
gn=gn+1;
m=m+1;
end
cr;
shang=-log(cr(1,1)/cr(1,2));
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询