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 andnp.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?
Answer
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:
and, previously, on page 55 they define $S_{xx}$:
So the FFT-squared version is the one you want.
And it has the same definition:
No comments:
Post a Comment