包络熵matlab代码
时间: 2023-10-11 17:04:26 浏览: 56
包络谱熵matlab代码-Automatic-High-Frequency-Oscillation-Detector:自动高频振荡检测器
以下是包络熵(Envelope Entropy)的 MATLAB 代码:
```matlab
function ee = envelope_entropy(x,m,r)
% x: signal vector
% m: embedding dimension
% r: tolerance
N = length(x);
x_matrix = zeros(m,N-m+1);
for i=1:m
x_matrix(i,:) = x(i:N-m+i);
end
% Calculate the Euclidean distance matrix
D_matrix = zeros(N-m+1,N-m+1);
for i=1:N-m+1
for j=i:N-m+1
D_matrix(i,j) = norm(x_matrix(:,i)-x_matrix(:,j),2);
D_matrix(j,i) = D_matrix(i,j);
end
end
% Calculate the ratio matrix
R_matrix = D_matrix / r;
% Calculate the probability matrix
P_matrix = exp(1-R_matrix);
P_matrix(R_matrix>=1) = 0;
% Calculate the entropy
ee = -sum(sum(P_matrix.*log(P_matrix))) / ((N-m+1)*(N-m)/2);
end
```
使用方法:
输入一个信号向量 `x`,以及嵌入维度 `m` 和容差 `r`,函数将返回该信号的包络熵值 `ee`。
例子:
```matlab
x = rand(1,1000); % Generate a random signal
m = 2; % Embedding dimension
r = 0.2; % Tolerance
ee = envelope_entropy(x,m,r); % Calculate the envelope entropy
```
阅读全文