# Will using window in Welch's method introduce artificial peak in estimated PSD?

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 *
f, p = signal.welch(x, fs=100, nperseg=256, window=signal.get_window('boxcar', 256))
plot(f[1:-1], log(p[1:-1]))


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]))


Is this some artifact?

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

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.