Correct PSD code so that it calculates average periodogram.