The normalized factor for windowing, is it $(\sum w[n])^2$ or $\sum w^2[n]$?
I try to reproduce the pwelch function, if I set the normalized factor to $(\sum w[n])^2$, I get the same result as MATLAB built-in pwelch function but, if I set the normalized factor to the other one which is introduced in the papers, the result is different.
(The code is pasted in the bottom of the question)
Furthermore, if the factor $(\sum w[n])^2$ is correct, how to explain,
$P_{xx}[k]=\frac{1}{MU}\left|\sum_{n=0}^{M-1}x[n]w[n]e^{-j2\pi kn/M}\right|^2= \frac{1}{MU}\left|\sum_{n=0}^{M-1}w[n]\right|^2\cdot \left|\sum_{n=0}^{M-1}x[n]e^{-j2\pi kn/M}\right|^2$
Why the equition holds?
% Welch's method for estimating power spectrum.
% x -- Input signal, must be vector.
% window -- Window sequence.
% overlop -- Overlop size, must be less than the size of window.
% nfft -- FFT point.
% fs -- Sampling rate.
function varargout =dwelch(x,window,overlap,nfft,fs)
nargoutchk(0,2);
%calculating window sliding step for iteration
winsize = length(window);
step = winsize - overlap;
iter = 1 + (length(x) - winsize)/step;
%start and end index of first window/segment
istart = 1;
iend = istart + winsize - 1;
% resize ....
fft1 = zeros(nfft,iter);
%start calculating fft for each window
for i=1:iter
%apply window
x_win(istart:iend) = x(istart:iend).*window;
%calculate fft
fft1(:,i) = fft(x_win(istart:iend),nfft);
%move to next window segment
istart = istart + step;
iend = iend + step;
end
%obtain scale to create modified periodogram
scale = 1/sum(window)^2; %%%%% this line !!!
%averaging window result and apply the scaling
psd = zeros(nfft,size(fft1,2));
for i=1:iter
psd = psd + fft1(1:nfft,i).*conj(fft1(1:nfft,i));
end
psd = psd.*scale./iter;
pxx = psd;
f = (fs/nfft)*(0:1:nfft-1);
if nargout == 0
plot(f,fftshift(10*log10(pxx)));
title('Welch PSD estimation');
xlabel('Normalized frequency(\pi rad/sample)');
ylabel('Power(W/(rad/sample))');
elseif nargout == 1
varargout = {pxx};
elseif nargout == 2
varargout = {pxx,f};
end
end
The following is excerpted from MATLAB built-in function pwelch.
when applying for PSD, it's $\sum w^2[n]$, while applying for PS, it's $|\sum w[n]|^2$, how to explain it?



