Spectral Entropy Calculation in MATLAB How do I calculate the Spectral Entropy of a signal in MATLAB ? I know the basic steps but it would be nice if someone can help,


Calculate the power spectrum of the signal using FFT command in MATLAB.
Calculate the Power Spectral Density using the power spectrum or using any other technique.
Normalize the Power Spectral Density  between $[0, 1]$, so that it can be treated as a probability density function $p_i $.
Calculate the Entropy $H(s) = -\sum p_i\log_2\left(p_i\right)$
Technically this is not a MATLAB-esque forum, but I can explain the steps in more detail for you: Suppose your input signal is $x[n]$, and its DFT is $X(f)$. For real signals you may use the one-sided DFT, since the other half would be redundant when you look at its Power Spectral Density. (PSD). 

Once you compute the DFT of your signal, the PSD is simply $|X(f)|^2$. That is, you need to take the absolute magnitude of your DFT result, squared. 

You now need to normalize the PSD such that it can be viewed as a Probability Density Function, (PDF). Thus, a normalized PSD, (let us call it $PSD_n$) will simply be:

$$
PSD_n(f) = \frac{PSD(f)}{\sum_{f=\frac{-fs}{2}}^{f = \frac{f_s}{2}} PSD(f)}
$$

Finally, your spectral entropy will be: 

$$
E = -\sum_{f=\frac{-fs}{2}}^{f = \frac{f_s}{2}} PSD_n(f) log_2[PSD_n(f)]
$$