0
$\begingroup$

I'd like to estimate the power spectral density of the signal attached here, the sampling rate is 100 Hz.

If I don't do windowing (i.e., use boxcar window), the result seems to be a simple $1/f^2$ noise:

import json
from scipy import signal
from pylab import *
x = json.load(open('x.json'))
f, p = signal.welch(x, fs=100, nperseg=256, window=signal.get_window('boxcar', 256))
plot(f[1:-1], log(p[1:-1])) 

boxcar window

However, if I apply, e.g., hanning window, there will be an unexpected additional peak at 25 Hz:

f, p = signal.welch(x, fs=100, nperseg=256, window=signal.get_window('hanning', 256))
plot(f[1:-1], log(p[1:-1]))

hanning window

Is this some artifact?

$\endgroup$

1 Answer 1

1
$\begingroup$

It is not any artifact. When you calculate the DFT of your signal you will get following magnitude spectra: enter image description here

So you can clearly see that around $25 \mathtt{Hz}$, and $50 \mathtt{Hz}$ there is some harmonic content present.

Reason why you don't see your harmonics on PSD in first case is that you are not using any windowing. Probably you are aware of side-lobes attenuation in characteristic of the window functions. For rectangular window it is approximately $13.3 \mathtt{dB} $ and for Hanning you get $31.5 \mathtt{dB} $. It is therefore possible that sidelobes will cover some harmonics of your signal.

Please take a look on your figures; for rectangular window lowest value of noise is approx. $-14$, whereas for Hanning you are getting around $-18$.

Below you can see frequency domain representation of these two windows.

enter image description here

For more info about windows, please refer to:

F. J. Harris - On the Use of Windows for Harmonic Analysis with the DFT

$\endgroup$
3
  • $\begingroup$ Thank you very much! The raw DFT result is convincing, and the Harris paper is very educational. My remaining question is that, why the faint 25 Hz harmonic is "swamped", rather than sits on top of, the side-lobes, after convolving the window spectrum? $\endgroup$
    – herrlich10
    Commented Jul 7, 2014 at 10:01
  • 1
    $\begingroup$ To answer your question in the easiest way for you, please take a look at this white paper: The fundamentals of FFT based signals analysis and measurement. Figure 9 on page 12 should give you total understanding. Also whole document is worth of reading. $\endgroup$
    – jojeck
    Commented Jul 7, 2014 at 14:20
  • $\begingroup$ I see. Just imagine two Gaussians (of different sizes) moving towards each other and fusing into a single peak. The result will always be linear superposition of two peaks, and the smaller one is just visually swamped. Staring at my first figure (no window), there seems to be an extremely flat yet barely discernible bump at 25 Hz. $\endgroup$
    – herrlich10
    Commented Jul 8, 2014 at 2:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.