# normalizing STFT output and calculating energy of signal

I have two questions regarding power spectra and energy of a signal:

1. For power spectra calculation I used STFT, and I saw that the value of STFT should be normalized before applying logarithmic function. The normalization is done by multiplying them by $2/\mbox{window length}$. What is the reason?

2. I also want to calculate the energy of the signal according to Parseval theorem and using STFT. Should I use the average of STFTs or the sum of them?

• because different FFT implementations sometimes have different scaling applied, it would be nice to know what you're using. is it MATLAB? what window function might you be using? Mar 17 '17 at 16:27
• Dear @robert . yeah, that is in MATLAB. The window is hamming and the code is [45197-short-time-fourier-transformation--stft--with-matlab-implementation]
– reo1
Mar 18 '17 at 18:39

The STFT yields complex values. Energy conservation (up to a scaling factor) should apply to the square of its magnitude, also called spectrogram. Depending on

1. the initial normalization of the FFT,
2. the window shape,
3. the lag (do you compute the FFT every $h$ sample, $h$ is called the hop, sometimes),

the scaling factor will differ, but will be the same for all signals.

1. $2$/window length is specific to a choice of the three parameters above. A scaling factor will only result in a $\log$-magnitude shift, which does not really matter for display or relative energy.

2. If you can compute the energy normalization based on the three parameters above, good. If not, take a randomly-picked signal (non zero), compute the ratio between the energy of the signal and that of the spectrogram, and you have your factor. Beware of the border effect, better take a centered signal with enough zeros (above the window support) on the right and the left.

• Dear @Laurent, what is the initial normalization of the FFT?I mean how can I apply that? my computations involve also some lag. so you mean that when I use this normalization, it is something depend on my data? and I didn't understand your second note about energy. should I use the average value of each time frame?or the only sum of them?my window is hamming and I didn't use any normalization on data. Could I ask you to give a reference for your second note?or these are something which is earned by experience.
– reo1
Mar 18 '17 at 18:50
• The normalization should not depend on data. Energy preservation should be valid for all signals Mar 18 '17 at 21:19