matlab entropy,关于entropy和wentropy
function ent = wentropy(x,t_ent,in3)%WENTROPY Entropy (wavelet packet).% E = WENTROPY(X,T,P) returns the entropy E of the% vector or matrix X.% In both cases, output E is a real number.%% T is...
function ent = wentropy(x,t_ent,in3)
%WENTROPY Entropy (wavelet packet).
% E = WENTROPY(X,T,P) returns the entropy E of the
% vector or matrix X.
% In both cases, output E is a real number.
%
% T is a string containing the type of entropy:
% T = 'shannon', 'threshold', 'norm',
% 'log energy' (or 'logenergy'), 'sure', 'user'.
% or
% T = FunName (which is any other string except those
% previous Entropy Type Name listed above).
% FunName is the MATLAB file name of your own
% entropy function.
%
% P is an optional parameter depending on the value of T:
% If T = 'shannon' or 'log energy', P is not used.
% If T = 'threshold' or 'sure', P is the threshold
% and must be a positive number.
% If T = 'norm', P is the power and must be such that 1 <= P.
% If T = 'user', P is a string containing the MATLAB file name
% of your own entropy function, with a single input X.
% If T = FunName, P is an optional parameter with no constraints.
%
% E = WENTROPY(X,T) is equivalent to E = WENTROPY(X,T,0).
% M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
% Last Revision 16-Aug-2012.
% Copyright 1995-2012 The MathWorks, Inc.
% $Revision: 1.13.4.9 $
% Check arguments.
narginchk(2,3);
x = double(x(:));
switch t_ent
case 'shannon' % in3 not used.
x = x(x~=0).^2;
ent = -sum(x.*log(eps+x));
case 'threshold' % in3 is the threshold.
if nargin==2 || isempty(in3) || ischar(in3) || in3<0 , errStop; end
x = abs(x);
ent = sum(x > in3);
case 'sure' % in3 is the threshold.
if nargin==2 || isempty(in3) || ischar(in3) || in3<0 , errStop; end
n = length(x);
x2 = x.^2; t2 = in3.^2;
xgt = sum(x2 > t2); xlt = n - xgt;
ent = n - (2*xlt) + (t2*xgt) + sum(x2.*(x2 <= t2));
case 'norm' % in3 = p , ent = (lp_norm)^p.
if nargin==2 || isempty(in3) || ischar(in3) || in3<1 , errStop; end
x = abs(x);
ent = sum(x.^in3);
case {'energy','log energy','logenergy'} % in3 not used.
x = x(x~=0).^2;
ent = sum(log(x));
case 'user' % in3 = '' , user entropy.
if nargin==2 || isempty(in3) || ~ischar(in3) , errStop; end
ent = feval(in3,x);
otherwise
%-----------------------------------------------------------%
% Bug & Generalization: temporary Patch (M.M. 20 June 2001) %
% For user defined entropy. %
%-----------------------------------------------------------%
try
k = find(t_ent=='&');
entFunct = t_ent(k+1:end);
ent = feval(entFunct,x);
catch %#ok
try
if nargin==2 ,
ent = feval(t_ent,x);
else
ent = feval(t_ent,x,in3);
end
catch
errStop;
end
end
end
prec = 1.0E-10;
if abs(ent)
% Internal Function
function errStop
errargt(mfilename,...
getWavMSG('Wavelet:FunctionArgVal:Invalid_ArgVal'),'msg');
error(message('Wavelet:FunctionArgVal:Invalid_ArgVal'));
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)