You should not publish such scripts, this
is less than a q&d hack. Besides poor programming style it is simply incorrect.
b = length(a)/2
(1:b)
Sorry, this will fail for odd number of elements. Besides that, the PSD is not simply the square of abs(fft), see here
www.utexas.edu/math/Matlab/Manual/tec6.2.html