Spectral Analysis math

Feedback and Reviews for Audacity 2.x
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
jean-eric
Posts: 18
Joined: Mon May 20, 2013 1:14 pm
Operating System: Please select

Spectral Analysis math

Post by jean-eric » Mon May 20, 2013 1:22 pm

Hello,
I'm sure this question has been answered already but I cannot fionf it... So please can you tell me the following thing.
I'am using version 2.03
And I plot the Spectrum Analysis using Blackman-Harris Windows, 4096 samples, 8000Hz sampling rate over 1sec resord.
I would like to know what is the mathematical formula that give the result?

I have exported the track into wav format, read it with Mathematica 9 using
20*Log10[PeriodogramArray[data,4096,4096,BlackmanHarrisWindow]]

but the plot does not match the Audacity one.

I have tried diffrent FFT parameter definition wo success.

SO please can someone help me?

Thanks

steve
Site Admin
Posts: 80677
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Spectral Analysis math

Post by steve » Mon May 20, 2013 5:28 pm

The peak amplitude is normalized such that a 0 dB sine wave will show (approximately) 0 dB.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

jean-eric
Posts: 18
Joined: Mon May 20, 2013 1:14 pm
Operating System: Please select

Re: Spectral Analysis math

Post by jean-eric » Mon May 20, 2013 5:50 pm

steve wrote:The peak amplitude is normalized such that a 0 dB sine wave will show (approximately) 0 dB.
I have just generate sin 440Hz freq. with Amplitude=1 and with Blackman-Harris window 1024 sample size I get 0dB at peak value. Ok

By the way is the windowing follow Welch rule with 50% overlapping ? (ie. 512 overlap between consecutive windows)?

jean-eric
Posts: 18
Joined: Mon May 20, 2013 1:14 pm
Operating System: Please select

Re: Spectral Analysis math

Post by jean-eric » Mon May 20, 2013 6:04 pm

steve wrote:The peak amplitude is normalized such that a 0 dB sine wave will show (approximately) 0 dB.
Do you mean also that the
spectrum 20*Log10[PeriodogramArray[data,4096,2048,BlackmanHarrisWindow]]
is shifted such that the max is set to 0dB even if "data" are not from a sin func with amplitude = 1 ???

steve
Site Admin
Posts: 80677
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Spectral Analysis math

Post by steve » Mon May 20, 2013 6:24 pm

jean-eric wrote:By the way is the windowing follow Welch rule with 50% overlapping ? (ie. 512 overlap between consecutive windows)?
I think that it is (but not for "Rectangular" window.)

jean-eric wrote:Do you mean also that the
spectrum 20*Log10[PeriodogramArray[data,4096,2048,BlackmanHarrisWindow]]
is shifted such that the max is set to 0dB even if "data" are not from a sin func with amplitude = 1 ???
No. The "shift" (normalization) is such that a sine wave with amplitude = 1 (0 dB) will be displayed as (about) 0 dB. The amount of shift is the same regardless of the actual audio content.

The spectrum shows the sum of all selected channels / tracks (the track data is mixed down to one mono audio selection prior to analysis).
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

jean-eric
Posts: 18
Joined: Mon May 20, 2013 1:14 pm
Operating System: Please select

Re: Spectral Analysis math

Post by jean-eric » Mon May 20, 2013 7:02 pm

Ok
But does this shift is independant of sampling rate AND/OR sample length ?

I get -24dB for 8000Hz sampling rate, 2048 sample length and Blackman-Harris windowing & 50% overlaping.

Robert J. H.
Posts: 3633
Joined: Thu May 31, 2012 8:33 am
Operating System: Windows 10

Re: Spectral Analysis math

Post by Robert J. H. » Mon May 20, 2013 11:18 pm

It may be that the blackman-harris Windows have different coefficients.
The General structure is
A - B*cos2 + C*cos4 (blackman)
The FLAC library uses the following:

Code: Select all

window[n] = (0.35875f - 0.48829f * cos(2.0f *PI * n / N) + 0.14128f * cos(4.0f * PI * n / N) - 0.01168f * cos(6.0f * PI * n / N));
It is called Blackman-Harris 4term 92 dB sidelob, so it would actually have 4 coefficients.

Do the more trivial Windows match?

steve
Site Admin
Posts: 80677
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Spectral Analysis math

Post by steve » Tue May 21, 2013 12:46 am

For implementation details, please refer to Spectrum.cpp in the source code http://code.google.com/p/audacity/sourc ... ectrum.cpp
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

jean-eric
Posts: 18
Joined: Mon May 20, 2013 1:14 pm
Operating System: Please select

Re: Spectral Analysis math

Post by jean-eric » Tue May 21, 2013 5:53 am

steve wrote:For implementation details, please refer to Spectrum.cpp in the source code http://code.google.com/p/audacity/sourc ... ectrum.cpp
Thanks a lot I have dived to the code and now I'm looking for the
WindowFunc
and
PowerSpectrum
definition but I cannot managed to catch them in SVN source code ???

jean-eric
Posts: 18
Joined: Mon May 20, 2013 1:14 pm
Operating System: Please select

Re: Spectral Analysis math

Post by jean-eric » Tue May 21, 2013 5:58 am

steve wrote:For implementation details, please refer to Spectrum.cpp in the source code http://code.google.com/p/audacity/sourc ... ectrum.cpp
ha! I find my way in FFT.h/cpp sorry for previous post...

Post Reply