Thread: [Audacity-devel] Bug in "Plot Spectrum"
A free multi-track audio editor and recorder
Brought to you by:
aosiniao
From: Piotr M. <pi...@ma...> - 2004-09-20 16:04:19
|
Hi *, There is a bug calculating amplitude spectrum function in the menu View/Plot Spectrum (FFT): Analysing a simple harmonic I see some spikes in the amplitude spectrum, where they shouldn't be. They get bigger extending the resolution of the FFT or using more complicated analysis windows. To reproduce this bug: - Create a track with a single sine tone: Generate/Tone, Frequency: 1000, OK - Select some seconds of the track - Go to View/Plot Spectrum - Change settings to: Spectrum | 16384 Rectangular window | Linear Freq. You should see this: http://iem.at/~majdak/temp/spect16384.jpg If you change the analysis window to hanning, the situation gets even worse (in terms of SNR). Look at that: http://iem.at/~majdak/temp/spect16384hanning.jpg Decreasing the number of bins to 2048, you still can see the distortions in spectrum: http://iem.at/~majdak/temp/spect2048hanning.jpg Can anyone confirm this? It looks like sloppy cast conversions in the windowing/FFT algorithms (do you _really_ use float numbers everywhere?) Piotr Majdak PS: OS: Win2000 SP5, Audacity 1.2.2 |
From: Dominic M. <do...@au...> - 2004-09-21 19:45:49
|
Piotr, I will take a closer look at some point, but my suspicion is the fact that Audacity is using single-precision floating point FFT calculations, with accumulations in doubles in just a few key places. I did a few brief experiments and discovered that the difference between single-precision and double-precision FFT is minimal up to 2048; for 4096 there are occasional deviations but overall it's stable, and beyond that there are significant deviations. Is that consistent with your observations? Perhaps we could add a double-precision FFT routine and switch to using that for FFT sizes of 8192 and higher? Then we could allow much larger FFTs, too, if you're willing to wait. - Dominic On Sep 20, 2004, at 9:08 AM, Piotr Majdak wrote: > Hi *, > > There is a bug calculating amplitude spectrum function in the menu > View/Plot Spectrum (FFT): Analysing a simple harmonic I see some > spikes in the amplitude spectrum, where they shouldn't be. They get > bigger extending the resolution of the FFT or using more complicated > analysis windows. > > To reproduce this bug: > - Create a track with a single sine tone: Generate/Tone, Frequency: > 1000, OK > - Select some seconds of the track > - Go to View/Plot Spectrum > - Change settings to: > Spectrum | 16384 > Rectangular window | Linear Freq. > > You should see this: http://iem.at/~majdak/temp/spect16384.jpg > > If you change the analysis window to hanning, the situation gets even > worse (in terms of SNR). Look at that: > http://iem.at/~majdak/temp/spect16384hanning.jpg > Decreasing the number of bins to 2048, you still can see the > distortions in spectrum: > http://iem.at/~majdak/temp/spect2048hanning.jpg > > Can anyone confirm this? > > It looks like sloppy cast conversions in the windowing/FFT algorithms > (do you _really_ use float numbers everywhere?) > > > > Piotr Majdak > > PS: OS: Win2000 SP5, Audacity 1.2.2 > > > ------------------------------------------------------- > This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 > Project Admins to receive an Apple iPod Mini FREE for your judgement on > who ports your project to Linux PPC the best. Sponsored by IBM. > Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php > _______________________________________________ > Audacity-devel mailing list > Aud...@li... > https://lists.sourceforge.net/lists/listinfo/audacity-devel |
From: Piotr M. <pi...@ma...> - 2004-09-22 09:19:26
|
Hi Dominic, Dominic Mazzoni wrote: > Piotr, > > I will take a closer look at some point, but my suspicion is the fact > that Audacity is using single-precision floating point FFT calculations, > with accumulations in doubles in just a few key places. I did a few > brief experiments and discovered that the difference between > single-precision and double-precision FFT is minimal up to 2048; for > 4096 there are occasional deviations but overall it's stable, and beyond > that there are significant deviations. > > Is that consistent with your observations? I haven't tested single vs. double. All I can tell you, is that increasing the FFT-length the distortions get worse. Assuming that the problem is a too small range of numbers, the behaviour should looks like that you found out. (Computing FFT over longer frames, you must build a sum over more samples) > Perhaps we could add a double-precision FFT routine and switch to using > that for FFT sizes of 8192 and higher? Then we could allow much larger > FFTs, too, if you're willing to wait. Why not using a double-precision FFT at all? I think, the computation time for frames with 8192 samples or less should be in range of single miliseconds. Consequently, performance difference comparing "double" with "single" should be negligible. If it's not, then we have some problems computing FFT ;-) (Do you use LAPACK or own libraries?) And, yes: I think audacity is a *great* thing, so I'm willing to wait :-) I use audacity with files with 64 channels that are really huge (>5GB). I already have adapted audacity for our purposes, I hope I get round to write you some code changes I made... Piotr Majdak |
From: Dominic M. <do...@au...> - 2004-09-22 19:01:06
|
Piotr, > Why not using a double-precision FFT at all? I think, the computation > time for frames with 8192 samples or less should be in range of single > miliseconds. Consequently, performance difference comparing "double" > with "single" should be negligible. Audacity shares a single FFT routine throughout its code, including many effects. However many milliseconds, double-precision fft is 2-3x slower than single-precision, which makes a big difference when doing noise removal, for example. > If it's not, then we have some > problems computing FFT ;-) (Do you use LAPACK or own libraries?) We're using our own FFT currently. I'm not aware of an LAPACK FFT library, can you point me to it? The best FFT library I'm aware of is FFTW, but unfortunately the license is not compatible with Audacity's - though both are GPL, the FFTW authors do not agree with linking FFTW to a program that has plug-in support. I think there may be another way around this, though: on Linux, we can allow the user to optionally compile with FFTW support, though it wouldn't be required - on Mac OS X we can link to Apple's VecLib, which provides its own optimized FFT routine - and perhaps there is something similar in new versions of Windows? Anyone know? > And, yes: I think audacity is a *great* thing, so I'm willing to wait :-) > I use audacity with files with 64 channels that are really huge (>5GB). > I already have adapted audacity for our purposes, I hope I get round to > write you some code changes I made... Great! - Dominic |
From: <xip...@xi...> - 2004-09-22 20:09:09
|
I will point out that my own Spectrum Analyzer app is a single-precision FFT and has no precision problems to a depth of over 140dB. Either this is just a legitimate bug (likely), a very faulty FFT (in terms of noise behavior; possible but less likely), or the data itself really does have those pseudo-harmonic distortions in it and the spectral tool isn't lying. Have you checked the waveform in a trusted spectral analyzer? I'll throw mine in SVN now if you don't have any others. Monty |
From: Piotr M. <pi...@ma...> - 2004-09-23 09:47:39
|
Hi Monty and Dominic, Monty wrote: > Either this is just a legitimate bug (likely), a very faulty FFT (in > terms of noise behavior; possible but less likely), or the data itself > really does have those pseudo-harmonic distortions in it and the > spectral tool isn't lying. > > Have you checked the waveform in a trusted spectral analyzer? I'll > throw mine in SVN now if you don't have any others. Since I've generated the wave form in audacity we either have a problem in Generate/Tone or in View/Plot Spectrum. What I did to check this problem: In Audacity I've generated and saved a sine tone: - Generate/Tone, Frequency: 1000Hz, Amplitude: 0.5 - File/Export As WAV... (In Preferences: 16-bit PCM) First, let's see the amplitude spectrum in audacity. We must reload the audio track to be sure, that we're goning compare the same audio data in each program: - File/New - File/Open Analysis: - Select a range > 16384 samples - View/Plot Spectrum - Settings: Spectrum, 16384, Rect. window, Lin. Freq - Result: http://iem.at/~majdak/temp/audacity16384.jpg - We see distortions :-( Assuming the distortions lie in the audio file, I've used CoolEdit to cross-check the amplitude spectrum of this tone: - File/Open - Select a sample in the middle of the track - Result: http://iem.at/~majdak/temp/cool16384.jpg - No distortions at all. Ok, we don't trust CoolEdit, do we? Let's try some really proofed method: I used MATLAB (http://www.mathworks.com) to calculate the FFT and then the amplitude spectrum. These basic functions of MATLAB were proofed many times by many scientists world-wide, so we can trust them: - Load WAV-File as a vector: a=wavread('sine.wav'); - Plot the amplitude spectrum in dB of the first 16384 samples: plot(20*log10(abs(fft(a(1:16384))))); - Result: http://iem.at/~majdak/temp/matlab16384.png - No distortions at all, so we have a problem with audacity... @Monty, please tell me, if I have done a mistake in my analysis procedure. @Dominic: I think about FFTPACK (http://www.netlib.org/fftpack/) and not LAPACK. There is no FT in LAPACK (http://www.netlib.org/lapack/) :-( Piotr Majdak |
From: <xip...@xi...> - 2004-09-23 16:53:11
|
On Thu, Sep 23, 2004 at 11:50:49AM +0200, Piotr Majdak wrote: > @Monty, please tell me, if I have done a mistake in my analysis procedure. Nope, looks pretty thorough. We can be pretty sure it is the spectral view in Audacity. > @Dominic: I think about FFTPACK (http://www.netlib.org/fftpack/) and not > LAPACK. There is no FT in LAPACK (http://www.netlib.org/lapack/) :-( Dominic: The 'smallft' I gave you a few months back to play with is a partial C implementation of the FFTPACK routine. By 'partial' I mean that it only includes to optimized butterflies for various powers of two. (I think you already knew that, but just in case) BTW, I'm going to have to write an FFTW3-like wrapper for it so I can plug it into libpostfish for non-GPL uses. Monty |