DSPRelated.com
Forums

FFT normalization/scaling to db

Started by AmitS October 28, 2003
Hi,
   I need help in order to convert a 512 sample FFT to dB values.
Here is the flow process of what I do.

1) Get 512 sample of data
2) Apply A window function (Hanning | Backman_Harris)
3) Do FFT
4) Calculate power by re*re+img*img, note I'am not taking square root
as I have
   to convert it to DB anyway
5) I then use 10Log(power) to get the db. 

The problem is I'am not getting the right db values. I need to scale
them but I do not know the scaling factors.

I need the scaling factors for the following windowing functions and
where to apply them in my above mention process flow.

1) Hamming
2) Hanning
3) Rectangular
4) Blackman
5) Blackman-Harris


any help would be welcome

--amitS
AmitS wrote:

> Hi, > I need help in order to convert a 512 sample FFT to dB values. > Here is the flow process of what I do. > > 1) Get 512 sample of data > 2) Apply A window function (Hanning | Backman_Harris) > 3) Do FFT > 4) Calculate power by re*re+img*img, note I'am not taking square root > as I have > to convert it to DB anyway > 5) I then use 10Log(power) to get the db. > > The problem is I'am not getting the right db values. I need to scale > them but I do not know the scaling factors. > > I need the scaling factors for the following windowing functions and > where to apply them in my above mention process flow. > > 1) Hamming > 2) Hanning > 3) Rectangular > 4) Blackman > 5) Blackman-Harris > > > any help would be welcome > > --amitS
dB is a measure of relative power. What do you mean by "the right db values"? You can do a lot of math -- like calculating the area under the curves -- to scale your windows to make them all come out the same (or the same as some other standard), but the easy way is to put a single frequency of known amplitude in to your FFT and calculate the output level. The calibration, of course, is an additive constant, different for each window. A frequency that puts a whole number of cycles into the FFT simplifies the calculation, but isn't needed for accuracy. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
chewbecca8051@yahoo.com (AmitS) wrote in message news:<bae8444e.0310272020.3622c350@posting.google.com>...
> Hi, > I need help in order to convert a 512 sample FFT to dB values. > Here is the flow process of what I do. > > 1) Get 512 sample of data > 2) Apply A window function (Hanning | Backman_Harris) > 3) Do FFT > 4) Calculate power by re*re+img*img, note I'am not taking square root > as I have > to convert it to DB anyway > 5) I then use 10Log(power) to get the db. > > The problem is I'am not getting the right db values. I need to scale > them but I do not know the scaling factors. > > I need the scaling factors for the following windowing functions and > where to apply them in my above mention process flow. > > 1) Hamming > 2) Hanning > 3) Rectangular > 4) Blackman > 5) Blackman-Harris > > > any help would be welcome > > --amitS
You're "not getting the right db values"... how do you know what the "right" db value should be? You could of course use Parseval's theorem which says that N-1 N-1 E = sum x(n)^2 = sum |X(k)|^2 n=0 k=0 where x(n) is the time series and X(k) is the power spectrum, and expect that the integral of the spectrum (in or out of db) should be related to the power of the original time series. In that case, you must make sure to scale the DFT of the signal properly. Many FFT implementations don't preserve power properly. If you use matlab you need to calculate the power spectrum bin P(k) P(k) = 1/sqrt(N)*X(k)*conj(X(k)); where X(k) is the k'th bin in the spectrum of your unwindowed time series. The next question is what db refernece level you use. Remeber, the dB scale is formally defined as P[dB | p0] = 10* log (P/p0) where p0 is some refernce level specified for the particular application. In my experience, failing to recognize this subtle point can cause a lot of inconvenience. Underwater acoustics (which I work with) and audio acoustics use two different reference levels, which means that the background noise under water is at ~80-100 dB | 1 uPa , which in turn makes people think that the underwater acoustic environment resembles the flight deck of an aircraft carrier. If you don't get the refernce level right, everything else goes caotic as well. Last, you would want to ask why you apply the windows when you do the power spectrum estimation. The reason windows are used, is that the variance of the periodogram is such that you really can't infer very much about the shape of the power spectrum. So by applying the right window, some of the variation is smoothed out, and hopefully it is possible to see more clearly what features are present in the spectrum. I don't think that preserving the norm is cruical in such applications, but assuming you have a signal x(n) with sample variance sigma^2, you would want to design a window w(n) such that 1 N-1 - sum (w(n)x(n))^2 = sigma^2. N n=0 where N is the frame length. If you do get the scaling as part of the window design, I think the db numbers pop out correctly at the end. Rune
Jerry Avins <jya@ieee.org> wrote in message news:<bnl0jp$gc9$1@bob.news.rcn.net>...
> dB is a measure of relative power. What do you mean by "the right db > values"? You can do a lot of math -- like calculating the area under the > curves -- to scale your windows to make them all come out the same (or > the same as some other standard), but the easy way is to put a single > frequency of known amplitude in to your FFT and calculate the output > level. The calibration, of course, is an additive constant, different > for each window. A frequency that puts a whole number of cycles into > the FFT simplifies the calculation, but isn't needed for accuracy. > > Jerry
What I mean by right db value is the following. I create a refrence file 1khz sine at 0db from adobe audition. Sample listed below SAMPLES: 1520 BITSPERSAMPLE: 16 CHANNELS: 1 SAMPLERATE: 8000 NORMALIZED: TRUE 3.05176e-005 0.707092 0.999969 0.707092 0 -0.707092 -0.999969 -0.707092 -3.05176e-005 0.707092 0.999969 0.707092 3.05176e-005 -0.707092 -0.999939 -0.707062 0 I then FFT it using my routine. I should expect to see a value of 0 in bin 64 but here what i see bin value 62 -21.643801 63 36.114788 64 42.160864 65 36.114776 66 -21.612909 The above result were obtained using a Hanning window. I now have to use some maths to get the correct results . I'am using Radix-2 FFT. I need scaling factors for diffrent windows so that I get corect results.... --amits
These numbers are in the famous Harris paper listed in the FAQ.  Have you 
looked there?  

Getting these numbers right is tricky.  There are two kinds of normalization, 
one where you make the amplitude right for a sine wave and one where you make 
the noise power right for input white noise.  You get to make the choice 
depending on what you need as an output.

One famous ASW program in the 80s had an engineer assigned full time to 
calculate these correction factors and provide the "correct" acoustic output 
power.

In article <bae8444e.0310282030.5dd8fdbf@posting.google.com>, 
chewbecca8051@yahoo.com (AmitS) wrote:
>I need scaling factors for diffrent windows so that I get corect >results.... > >--amits
nobody@nowhere.nothing wrote in message news:<DoPnb.3251$CZ5.2663@twister.socal.rr.com>...
> These numbers are in the famous Harris paper listed in the FAQ. Have you > looked there? > > Getting these numbers right is tricky. There are two kinds of normalization, > one where you make the amplitude right for a sine wave and one where you make > the noise power right for input white noise. You get to make the choice > depending on what you need as an output. > > One famous ASW program in the 80s had an engineer assigned full time to > calculate these correction factors and provide the "correct" acoustic output > power. > > In article <bae8444e.0310282030.5dd8fdbf@posting.google.com>, > chewbecca8051@yahoo.com (AmitS) wrote: > >I need scaling factors for diffrent windows so that I get corect > >results.... > > > >--amits
Where can I get hold of the Harris paper "On the use of windows for harmonic analysis with the discrete Fourier transform" ? --amits
The paper is in the Proceedings of the IEEE, January 1978.

Some, but not all, of the information you need is at

http://nic.biti.edu.
cn/china-pub/Science/Handbooks/Formulas_Tables_for_signal_proc/8579/8579ch07.
pdf

Sorry for the hashedup URL.

In article <bae8444e.0310292124.797e9a1a@posting.google.com>, 
chewbecca8051@yahoo.com (AmitS) wrote:
>nobody@nowhere.nothing wrote in message > news:<DoPnb.3251$CZ5.2663@twister.socal.rr.com>... >> These numbers are in the famous Harris paper listed in the FAQ. Have you >> looked there? >> >> Getting these numbers right is tricky. There are two kinds of normalization, > >> one where you make the amplitude right for a sine wave and one where you make > >> the noise power right for input white noise. You get to make the choice >> depending on what you need as an output. >> >> One famous ASW program in the 80s had an engineer assigned full time to >> calculate these correction factors and provide the "correct" acoustic output >> power. >> >> In article <bae8444e.0310282030.5dd8fdbf@posting.google.com>, >> chewbecca8051@yahoo.com (AmitS) wrote: >> >I need scaling factors for diffrent windows so that I get corect >> >results.... >> > >> >--amits > > >Where can I get hold of the Harris paper "On the use of windows for >harmonic analysis with the discrete Fourier transform" ? > >--amits
nobody@nowhere.nothing wrote in message news:<IU7ob.8876$Ub4.1111@twister.socal.rr.com>...
> The paper is in the Proceedings of the IEEE, January 1978. > > Some, but not all, of the information you need is at > > http://nic.biti.edu. > cn/china-pub/Science/Handbooks/Formulas_Tables_for_signal_proc/8579/8579ch07. > pdf > > Sorry for the hashedup URL. >
Cannot download it. Is there some other place I can download it from. If it is not big can < 2MB U mail me at chewbecca@sify.com --amits
AmitS wrote:

> Cannot download it. Is there some other place I can download it > from. If it is not big can < 2MB U mail me at chewbecca@sify.com
I have already mailed the paper to the address from your message header (chewbecca8051@yahoo.com) before the above reached me. Martin