The power spectral density (PSD) of the given input signal $x[n]$ is computed as follows:
close all;clear;clc n = 8; F = dftmtx(n); invF = 1/n*F'; rng default x = randn(100*n,1); xx = buffer(x,n,n-1); xx = xx(:, n:end); XX = fft(xx, n); phixx = mean(XX.*conj(XX),2)/n; phixx = phixx.';
phixx = 1.0837 1.1155 0.8099 0.9498 1.0470 0.9498 0.8099 1.1155
If the MATLAB built-in function
pwelch is used to compute the PSD, then the results are quite different from what is shown above:
pp = pwelch(x, ones(n,1), n-1, n)' 0.1725 0.3551 0.2578 0.3023 0.1666
As it is one side, so the length is only
n/2+1, but I expected the values to be identical to each other.
Was the way how
pwelch was used wrong?
Please let me know if there should be more detailed information.
I just found out that the results are identical except for a $\pi$ or $2\pi$ difference between them, i.e.,
(phixx(1:n/2+1)./pp)/pi ans = 2.0000 1.0000 1.0000 1.0000 2.0000
There seems a constant involved in computing
Then, I am wondering which one should be used.