Page 1 of 2

Spectral Analysis math

Posted: Mon May 20, 2013 1:22 pm
by jean-eric
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

Re: Spectral Analysis math

Posted: Mon May 20, 2013 5:28 pm
by steve
The peak amplitude is normalized such that a 0 dB sine wave will show (approximately) 0 dB.

Re: Spectral Analysis math

Posted: Mon May 20, 2013 5:50 pm
by jean-eric
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)?

Re: Spectral Analysis math

Posted: Mon May 20, 2013 6:04 pm
by jean-eric
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 ???

Re: Spectral Analysis math

Posted: Mon May 20, 2013 6:24 pm
by steve
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).

Re: Spectral Analysis math

Posted: Mon May 20, 2013 7:02 pm
by jean-eric
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.

Re: Spectral Analysis math

Posted: Mon May 20, 2013 11:18 pm
by Robert J. H.
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?

Re: Spectral Analysis math

Posted: Tue May 21, 2013 12:46 am
by steve
For implementation details, please refer to Spectrum.cpp in the source code http://code.google.com/p/audacity/sourc ... ectrum.cpp

Re: Spectral Analysis math

Posted: Tue May 21, 2013 5:53 am
by jean-eric
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 ???

Re: Spectral Analysis math

Posted: Tue May 21, 2013 5:58 am
by jean-eric
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...