Glitch in Spectrum Analysis
Forum rules
This board is ONLY for general feedback and discussion about Audacity 2.X.
If you require help, or think you have found a "bug", please post on the forum board relevant to your operating system.
Windows
Mac OS X
GNU/Linux and Unix-like
This board is ONLY for general feedback and discussion about Audacity 2.X.
If you require help, or think you have found a "bug", please post on the forum board relevant to your operating system.
Windows
Mac OS X
GNU/Linux and Unix-like
Glitch in Spectrum Analysis
Using 2.0.5 Alpha 9/8/13. With this audio sample, using Bartlett window at length = 32768, one spectrum value is around +1200 dB. The exact frequency and amplitude change a bit when saved as a wav or flac file and imported back into the project, but frequency is in the 116-118 Hz range. Track settings are 41,100Hz and 32 bit float. The line does not show up in the plot nor does it seem to affect the scaling, but peaks to the left of it cannot be found. The glitch disappears if I change window or length setting.
- Attachments
-
- FFT error (32768, Bartlett).flac
- Ambient noise sample, produces glitch in Spectrum plot with Bartlett window and length=32768. Doesn't appear in plot nor affect scaling, but peaks to the left of it cannot be found. Glitch is around 166-118 Hz, amplitude is over +1200dB.
- (76.61 KiB) Downloaded 80 times
Re: Glitch in Spectrum Analysis
How odd
I've had a look in the code and I think that I can see where it is coming from.
There is a note in the file FreqWindow.cpp
The problem seems to be that very occasionally the numbers will be such that the equation cannot be solved, and by chance you seem to have hit on such an occurrence.
A little further on in the code we have:
but with your audio sample the cubic is never calculated below 117 Hz because the discriminant is negative.
This has a knock on effect in FreqWindow::PlotPaint where the actual peak should be calculated.
It is possible that there could be an error in the equation.
I seem to get more sensible results changing lines 825 - 826 from
to
but sadly my maths is not good enough to know if that is correct or completely wrong.
The upshot is that there is definitely a "glitch", but whether it is because of an error in the code (a bug) or that the equation with that specific data has no solution, will take a better mathematician than myself to work out.
I've had a look in the code and I think that I can see where it is coming from.
There is a note in the file FreqWindow.cpp
Code: Select all
// If f(0)=y0, f(1)=y1, f(2)=y2, and f(3)=y3, this function finds
// the degree-three polynomial which best fits these points and
// returns the value of this polynomial at a value x. Usually
// 0 < x < 3
A little further on in the code we have:
Code: Select all
// Find zeroes of derivative using quadratic equation
float discriminant = db * db - 4 * da * dc;
if (discriminant < 0.0)
return float(-1.0); // error
float x1 = (-db + sqrt(discriminant)) / (2 * da);
float x2 = (-db - sqrt(discriminant)) / (2 * da);
// The one which corresponds to a local _maximum_ in the
// cubic is the one we want - the one with a negative
// second derivative
float dda = 2 * da;
float ddb = db;
This has a knock on effect in FreqWindow::PlotPaint where the actual peak should be calculated.
It is possible that there could be an error in the equation.
I seem to get more sensible results changing lines 825 - 826 from
Code: Select all
if (leftbin < 1)
leftbin = 1;
Code: Select all
if (leftbin < 1)
leftbin = -1;
The upshot is that there is definitely a "glitch", but whether it is because of an error in the code (a bug) or that the equation with that specific data has no solution, will take a better mathematician than myself to work out.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)