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:

Example with good tuning parameters

Poor tuning:

Example with poor tuning parameters

Awful tuning:

Example with awful tuning parameters

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.

If you want something more standard, have a look at spectral flatness. But it seems even less stable numerically.

| improve this answer | |
  • $\begingroup$ On the data that I gave as an example (which is pretty representative), spectral flatness was very cheap to calculate and worked well. Its main drawback seems to be the need to ensure that none of the frequency bins are empty. My calculation of the Shannon Entropy gave a better figure-of-merit for the 'good' case than for the 'poor' case, but the best figure-of-merit overall was for the 'awful' case, which isn't what I wanted! Maybe I calculated it wrong; in any case, the spectral flatness (which I've since learned is also called the Wiener entropy) looks like a good way forward. $\endgroup$ – Eos Pengwern Apr 13 '15 at 21:03
  • $\begingroup$ You can add a small constant value to all |f(x)| to stabilize Wiener entropy. The value can be about the same as your noise floor. $\endgroup$ – Olli Niemitalo Apr 14 '15 at 7:16

I don't know if there is a standard approach, but if your graphs are representative you could simply use peak amplitude (you would need to perform peak detection) or [ peak amplitude / power ] where power would be the area under your graph.

| improve this answer | |
  • $\begingroup$ I'd thought of identifying the peaks one-by-one and finding the FWHM of each, and then applying some formula based on the inverse of the number of peaks and their FWHMs. I'd prefer to use a more standard criterion if one exists, and spectral flatness/Wiener entropy looks like the favourite at the moment. $\endgroup$ – Eos Pengwern Apr 13 '15 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.