How can I calculate the entropy of a random signal using its histogram?
20 views (last 30 days)
Show older comments
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)
1 Comment
shafiqah yusoff
on 17 Dec 2017
just want to ask. can you please elaborate more the function of X, bins ,and n.? thank you
Answers (2)
Image Analyst
on 29 Oct 2013
Don't you just add on this code:
p = n / sum(n)
entropy = -sum(p .*log(p))
or am I overlooking something???
0 Comments
Marcin
on 30 May 2017
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)
0 Comments
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!