⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 entropy.m

📁 英文书《Digital Signal Processing with Examples in MATLAB》附带的MATLAB实例
💻 M
字号:
function [H,Ht]=entropy(x);
% function [H,Ht]=entropy(x).
%
% x =any INTEGER vector or array. (Real values are rounded.)
%
% H = Average entropy in vector x in bits per symbol.
% Ht = Total entropy in vector x = H * length(x).
% If x is a matrix, H and Ht are vectors with each element
% equal to the entropy of the corresponding column of x.
% See also: freq
[Lx,Ncols]=size(x);
if Lx==1 & Ncols==1,
	   error('Input cannot be a scalar.');
elseif Lx==1 & Ncols>1,
	   x=x';
		[Lx,Ncols]=size(x);
end
H=zeros(1,Ncols);
Ht=zeros(1,Ncols);
for col=1:Ncols,
    f=freq(x(:,col));
    H(col)=-(f)*log2(max(1/Lx,f'));
    Ht(col)=H(col)*Lx;
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -