pentropy(), in the SIgnal Processing Toolbox, computes the entropy of a signal's power spectrum, or of its spectrogram (i.e. time-varying spectrum). By default, it divides the signal into segments and computes a spectrum and an entropy for each segment. This can be useful in analysis of speech signals. If you want to estimate the entropy (H) of the entire signal, without segmentation, specify 'Instantaneous',false, as shown below:
The entropy returned is normalized, by default, to the entropy of a white noise signal of equal length. You can test pentropy() by calculating H for a Gaussian white noise signal. In the following example, 100 Gaussian random signals are generated, each of length N=256. The entropy of each is computed and saved. At the end, the mean, standard deviation, minimum, amd maximum entropies are displayed.
As the signal duration becomes long, H approaches unity. See example below, which is like above, but with N=32768 this time.
A value of H less than unity represents non-Gaussianity. The smaller H is, the more non-Gaussian y is.
pentropy() is not sensitive to some important forms of non-Gaussianity. The spectral entropy of uniform random noise (in the first example above) is almost identical to Gaussian random noise. This should not happen, because in theory, a Gaussian signal has maximum entropy.
The difficulty in controlling how the spectrum is computed inside pentropy() is another potential disadvatage of pentropy(). When I turned off the automatic scaling, and varied the signal duration, the entropy of the supposedly unscaled signal did not change as I expected. I think this is because the power spectrum routine called by pentropy() has default settings for the number of frequencies in the spectrum. See examples below.
I expected H=log2(N)=12.
I expected H=log2(N)=8.
The shortcomings of pentropy() show that a time-domain entropy function is needed. This function will construct the histogram of the time-domain values of the signal, then normalize the histogram so it is a probability density, then compute the entropy of the density. A search of Matlab file exchange for negentropy returns two hits, but neither one looks like what we want.