Rectangle 27 0

Why do I need to apply a window function to samples when building a power spectrum of an audio signal?

However, the math of the Fourier transform assumes that the signal being Fourier transformed is periodic over the time span in question.

Notice how the distribution of energy above the -60 dB line has changed significantly, and how the three distinct peaks have changed shape and height. This particular distribution of spectral energy contains fewer "spectral leakage" errors.

Notice the distribution of energy above the -60 dB line, and the three distinct peaks at roughly 440 Hz, 880 Hz, and 1320 Hz. This particular distribution of energy contains "spectral leakage" errors.

Now let's apply the Hann window to the guitar's audio data, and then FFT the resulting signal.

Real audio signal data, Hann window function, plots, FFT, and spectral analysis were done here:

The acoustic guitar's A4 note used for this analysis was sampled at 44.1 KHz with a high quality microphone under studio conditions, it contains essentially zero background noise, no other instruments or voices, and no post processing.

The plot below shows a closeup of the power spectrum of the same signal (an acoustic guitar playing the A4 note), but this time the signal was pre-multiplied by the Hann window function prior to the FFT.

The plot below shows the Hann window function in the time-domain. Notice how the tails of the function go smoothly to zero, while the center portion of the function tends smoothly towards the value 1.

These errors are called "spectral leakage", and generally manifest as a wrongful distribution of energy across the power spectrum of the signal.

This mismatch between the Fourier assumption of periodicity, and the real world fact that audio signals are generally non-periodic, leads to errors in the transform.

To somewhat mitigate the "spectral leakage" errors, you can pre-multiply the signal by a window function designed specifically for that purpose, like for example the Hann window function.

Rectangle 27 0

Why do I need to apply a window function to samples when building a power spectrum of an audio signal?

@Nuno: don't worry too much about the absolute dB values - 0 dB is just an arbitrary reference point anyway, unless you calibrate agains some known reference and use e.g. dBV or dBm. What's more important is that the peaks in your spectrum are at the right frequencies and that the magnitude of the peaks have a reasonable value relative to your noise floor.

As @cyco130 says, your samples are already windowed by a rectangular function. Since a Fourier Transform assumes periodicity, any discontinuity between the last sample and the repeated first sample will cause artefacts in the spectrum (e.g. "smearing" of the peaks). This is known as spectral leakage. To reduce the effect of this we apply a tapered window function such as a Hann window which smooths out any such discontinuity and thereby reduces artefacts in the spectrum.

after calculating the magnitues and the db i get values above 0db. is this normal. I know this is a lame question but I cant really understand when I should I get 0db. my input signal and the applied hann function is this: in[step] = 0.05fsin((2*M_PIstep*440)/44100) + 0.1fsin((2*M_PIstep*880)/44100) + 0.2fsin((2*M_PIstep*1760)/44100); in[step] = 0.5f * (1.0f- cos(float((2*M_PIstep)/float(NSAMPLES-1))));