使用MATLAB中的FFT命令计算信号的功率谱。
使用以下方法计算功率谱密度
对$ [0,1] $之间的功率谱密度进行归一化,以便可以将其视为概率密度函数$ p_i $。
计算熵$ H(s)=-\ sum p_i \ log_2 \ left(p_i \ right)$
#1 楼
从技术上讲,这不是MATLAB风格的论坛,但是我可以为您详细解释这些步骤:假设您的输入信号为$ x [n] $,其DFT为$ X(f)$。对于真实信号,您可以使用单面DFT,因为当您查看其功率谱密度时,另一半将是多余的。 (PSD)。一旦计算出信号的DFT,PSD就是$ | X(f)| ^ 2 $。也就是说,您需要对DFT结果的绝对大小取平方。
现在您需要规范化PSD,以便可以将其视为概率密度函数(PDF)。因此,归一化的PSD(我们称其为$ PSD_n $)将为:
$$
$$
最后,您的光谱熵将是:
$$
E =-\ sum_ {f = \ frac {-fs} {2}} ^ {f = \ frac {f_s} {2}} PSD_n(f )log_2 [PSD_n(f)]
$$
#2 楼
我只是在这里做我的源代码:
[x, Fs, nbits] = wavread('ederwander.wav');
winSize = 2048;
n_samples = length(x);
%50% overlap or 0 to not use overlap
OverlapStep = 50;
if OverlapStep > 0
Overlap = floor((OverlapStep*winSize) / 100);
nFrames=floor(n_samples/Overlap)-1;
else
Overlap= winSize;
nFrames=floor(n_samples/Overlap)-1;
end
Entropy = zeros(nFrames,1);
k=1;
inc=1;
while ( (k+winSize-1) <= n_samples )
FrameSignal = x(k:k+winSize-1);
v = FrameSignal .* hann(length(FrameSignal));
N = length(v);
Y=fft(v);
% Compute the Power Spectrum
sqrtPyy = ((sqrt(abs(Y).*abs(Y)) * 2 )/N);
sqrtPyy = sqrtPyy(1:winSize/2);
%Normalization
d=sqrtPyy(:);
d=d/sum(d+ 1e-12);
%Entropy Calculation
logd = log2(d + 1e-12);
Entropy(inc) = -sum(d.*logd)/log2(length(d));
k=k+Overlap;
inc=inc+1;
end
此源代码从每个框架块进行光谱熵计算...
评论
至于Matlab代码,请尝试在此处询问dsprelated.com/code.php这与频谱平坦度或维纳熵相同吗? dsp.stackexchange.com/q/2045/29