Ok, the spectral flatness (also called Wiener entropy) is defined as the ratio of the geometric mean of a spectrum to its arithmetic mean.

Wikipedia and other references say the power spectrum. Isn't that the square of the Fourier transform? The FFT produces an "amplitude spectrum" and then you square that to get a "power spectrum"?

Basically what I want to know is, if spectrum = abs(fft(signal)), which of these is correct?

  • spectral_flatness = gmean(spectrum)/mean(spectrum)
  • spectral_flatness = gmean(spectrum^2)/mean(spectrum^2)

Wikipedia's definition seems to use the magnitude directly:

$$ \mathrm{Flatness} = \frac{\sqrt[N]{\prod_{n=0}^{N-1}x(n)}}{\frac{\sum_{n=0}^{N-1}x(n)}{N}} = \frac{\exp\left(\frac{1}{N}\sum_{n=0}^{N-1} \ln x(n)\right)}{\frac{1}{N} \sum_{n=0}^{N-1}x(n)} $$ where $x(n)$ represents the magnitude of bin number $n$.

SciPy docs define power spectrum as:

When the input a is a time-domain signal and A = fft(a), np.abs(A) is its amplitude spectrum and np.abs(A)**2 is its power spectrum.

This source agrees about the definition of "power spectrum" and calls it $S_{f}(\omega)$:

We can define $F_{T}(\omega) $ which is the fourier transform of the signal in period T, and define the power spectrum as the following: $\displaystyle S_{f}(\omega) = \lim_{T \rightarrow \infty} \frac{1}{T}{\mid F_{T}(\omega)\mid}^2.$

This source defines Wiener entropy in terms of $S(f)$.

But I don't see the squaring in equations like this, which seems to be based on the magnitude spectrum:

$$ S_{flatness} = \frac{\exp\left(\frac{1}{N} \sum_k \log (a_k)\right)}{\frac{1}{N} \sum_k a_k} $$

Likewise, another source defines the spectral flatness in terms of the power spectrum, but then uses the magnitude of the FFT bins directly, which would seem to conflict with the above definition of "power spectrum".

Does "power spectrum" mean different things to different people?

  • $\begingroup$ according to Wikipedia: Spectral flatness ak represents the magnitude of bin number k. $\endgroup$ – Hamed Gholami Aug 6 '18 at 12:50
  • $\begingroup$ Hi @endolith, did you get a satisfactory answer that you are willing to accept? $\endgroup$ – jojek Aug 6 '18 at 15:13
  • $\begingroup$ @jojek No, not yet $\endgroup$ – endolith Aug 6 '18 at 16:05
  • 1
    $\begingroup$ @endolith, I believe that Peter just hit the nail in the head ;) $\endgroup$ – jojek Aug 8 '18 at 17:29
  • $\begingroup$ @jojek I tried to punch the nail through the board. πŸ˜‚ $\endgroup$ – Peter K. Aug 9 '18 at 1:12

The most authoritative reference I can come up with is from Jayant & Noll, Digital Coding Of Waveforms, (c) Bell Telephone Laboratories, Incorporated 1984, published by Prentice-Hall, Inc.

On page 57, they define the spectral flatness:

Spectral flatness

and, previously, on page 55 they define $S_{xx}$:

Definition of power spectrum

So the FFT-squared version is the one you want.

It looks like Makhoul & Wolf, Linear Prediction and the Spectral Analysis of Speech, Bolt, Beranek, and Newman, Inc. Technical Report, 1972 is also available.

And it has the same definition:

enter image description here

enter image description here


If the definition of the flatness dictates that you use a power spectrum, then yes, you should square the magnitudes as the reference from the SciPy documentation indicates. In the equation that you referenced where you didn't see a squaring, I don't think you can read much into it; it says that

$$ S_{flatness} = \frac{\exp\left(\frac{1}{N} \sum_k \log (a_k)\right)}{\frac{1}{N} \sum_k a_k} $$

but I don't see a definition for $a_k$ anywhere. If you want the spectrum to be proportional to the power in each bin, you need to square.

  • $\begingroup$ I guess this is a question about what the definition actually is, then $\endgroup$ – endolith Apr 13 '12 at 20:19
  • $\begingroup$ according to A Segmental Spectral Flatness Measure for Harmonic-Percussive Discrimination $a_k$ represents the amplitude spectrum of bin number k. $\endgroup$ – Hamed Gholami Aug 6 '18 at 12:50
  • $\begingroup$ @HamedGholami Please do not enter your comment as an answer again. Your comment does not provide an answer to the question, but tries to be helpful here. $\endgroup$ – Peter K. Aug 8 '18 at 16:29
  • $\begingroup$ @PeterK. I think new users can't post comments, but can post answers. $\endgroup$ – endolith Aug 9 '18 at 13:46
  • 1
    $\begingroup$ @endolith Understood. But even after jojek moved his first answer to being a comment on the question, Hamed reposted the same comment as an answer. That is the behavior I am wanting to dissuade: reposting again after their "answer" was moved. $\endgroup$ – Peter K. Aug 9 '18 at 13:52

Definitions vary, don't they? The first thing that has to be settled is whether we agree that the power spectral density is equivalent to the power spectrum, or else define what we mean by both. Proakis and Salehi use them synonymously. Moving on, I think the discrepancies are due to differing definitions, for signals that have one, of the power spectrum. The usual definition of that is the magnitude squared of the Fourier transformed data. The Wiener-Khinchin theorem provides another route to the power spectrum for WSS signals through the Fourier transform of the autocorrelation. Depending on whether or not you define the power spectrum with a square, you get a square in the spectral flatness.

Others use the magnitude of the Fourier transform. Some call this the "power spectrum", and reserve the name "power spectrum density" for the derivative of the "power spectrum" while others reserve the term "power spectrum" for the integral of the Fourier transform of the autocorrelation (what others call the power spectrum). As you can see, definitions abound; feel free to invent you own :) Or stick to the Wiener-Khinchin standard.

Related question: Difference between Power spectral density, spectral power and power ratios?

  • $\begingroup$ That says "power spectrum", too. $\endgroup$ – endolith Apr 13 '12 at 21:24
  • 1
    $\begingroup$ ΰ² _ΰ²  ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ $\endgroup$ – endolith May 16 '12 at 16:17

Its a good question, one that I was wondering myself as well. The spectral flatness (also known as Weiner Entropy) is simply a measure of the 'peakiness' of a vector.

This source seems to indicate that the vector under consideration is the power spectral density, in which case you have to square. If you square the magnitude spectrum, you are accentuating peaks over the case where you don't square obviously, and I think this also makes more intuitive sense.


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.