How can I calculate the entropy of a random signal using its histogram?

26 次查看(过去 30 天)
I have a random signal X and I want to calculate the entropy. I don't know how to calculate the probability for each bin. I assigned below the code I did in order to generate the signal and also to calculate the numbers of bins.
X=rand(50,1)
k=1+log2(50) %Computing the number of bins
bins=round(k)
n=hist(X,bins)

回答(2 个)

Image Analyst
Image Analyst 2013-10-29
Don't you just add on this code:
p = n / sum(n)
entropy = -sum(p .*log(p))
or am I overlooking something???

Marcin
Marcin 2017-5-30
In Matlab R2016b (and maybe earlier) you can use entropy function. The only thing you should remember is that it is designed for image processing, therefore you have to normalize a signal before calling entropy:
x_normalized = x/max(abs(x));
e = entropy(x_normalized)

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by