I am trying to estimate the amplitude or power spectrum of a sinusoidal signal using Pwelch method. The following is the matlab code I use.
rng default
fs = 1000;
t = 0:1/fs:5-1/fs;
x = cos(2*pi*100*t) + 0*randn(size(t));
[pxx,f] = pwelch(x,fs,0,fs,fs,'onesided'); plot(f,10*log10(pxx))
And it gives the following result
By default, a Hamming window of length $f_s$ is used in the pwelch function. Since the frequency resolution is 1 Hz, the frequency of the sinusoid lies exactly in one of the discrete frequency bins of the FFT and no scalloping loss is involved. The question I have is that why the amplitude or power of the peak is -4.357dB instead of -3dB. I tried other windows with the same length. The rectangular window gives a peak of exactly -3 dB and the Hanning window, -4.78 dB. The power loss maybe related to the type of windows, I guess. But I cannot figure out why.
Can anyone explain this?
Thank you in advance.