from Power Spectrum Estimation (non-parameteric methods) by payam masoumi
there is a simple demo for non parameteric spectral estimation methods

per(x,n1,n2)
function Px = per(x,n1,n2)

x = x(:);
if nargin == 1
    n1 = 1;  n2 = length(x);  end;
Px = abs(fft(x(n1:n2),1024)).^2/(n2-n1+1);
Px(1) = Px(2);

Contact us at files@mathworks.com