There are two bugs in the current periodogram() implementation, and here's a new version which fixes both. The first bug is that, when using one-sided spectra (the default behavior), only column vectors are supported for the input signal, x. Sending in row vectors causes a "vertical dimensions mismatch" error due to this one-sided conversion code:
Pxx = Pxx(1:nfft/2+1) + [0; Pxx(end:-1:(nfft/2+2)); 0];
To witness the bug, simply attempt:
pxx = periodogram( sin(1:10) )
The second also involves that one-sided conversion code. Namely, it is incorrect when nfft is odd, since it yields 1/2 the correct value at the upper-most (non-Nyquist) frequency.
To see this, note that the following returns ~0.0171 for the third component, when it should return ~0.0342:
pxx = periodogram( sin(1:5)', [], 5 )
The attached code fixes both issues (using similar one-sided conversion code to that found in the current pwelch() implementation), and also forces that the window (if non-empty) is a vector of the same length as the signal (which is the current MATLAB behavior).
Best,
Drew Abbot