# Figure of merit for 'locality of power'

I have a raw signal which, if interpreted correctly with various 'tuning' parameters set to their optimum values, can be seen to consist of a relatively small (but a priori unknown) set of discrete frequency components. With the tuning parameters set at sub-optimum values, the power spectrum is spread out - each frequency component is broader or, in the very poorly-tuned case, there can be many 'false' frequency peaks. Some example plots would be:

Good tuning: Poor tuning: Awful tuning: What I'd like is to be to able to auto-tune by identifying a figure-of-merit which is highest for the 'good tuning' case, lowest for the 'awful tuning' case, and somewhere in the middle for the 'poor tuning' case. If I knew a priori that there was a single frequency component, this would be fairly straightforwrad but I haven't been able to think of a good appraoch when the number of components is unknown.

Is there a standard approach to this problem that I'm unaware of?

You could try calculating Shannon entropy of the spectrum. Normalize the Fourier transform $f(x)$ of your signal so that $\int_{-\infty}^\infty |f(x)|^2\, dx = 1$ and calculate Shannon entropy as $- \int_{-\infty}^\infty |f(x)|^2 \log |f(x)|^2\, dx$. You can clamp $|f(x)|^2 \log |f(x)|^2$ to zero for very small values of $f(x)$ if its logarithm blows up and ruins the calculations. Zero-padding before windowing & FFT will give you more frequency resolution and a better approximation, especially if you have narrow peaks in the spectrum.