To compute the power spectral density with Python use the Welch method as given by scipy.welch
. The function provided in all of these tools properly compensates for all the parameters (window used, fft length) to provide an accurate power spectral density.
With that I recommend that the OP compute the PSD for each dataset using Welch directly and then average those results. The number of samples returned by the Welch function is a parameter and can be set to be the same for each result. Another option is to concatenate the different sets and let Welch do the averaging, but this will then be affected by the discontinuities at each boundary (which can be countered with windowing, which would then modify the PSD result, etc so easier in my opinion to do my first suggestion).
The Welch method in simplest explanation provides a noise reduced estimate of the power spectral density by averaging the result of several overlapped shorter FFTs for a longer dataset. This results in significantly less noise in the estimate than one long FFT. The trade however is longer resolution bandwidth in the measurement since the resolution bandwidth is a reciprocal of the time duration of the signal in each FFT block. (This is what causes the noise floor in an FFT to go up and down; the resulting power from each bin represents the total power within the resolution bandwidth of the measurement). The Welch function provided by Python will accurately compensate for the resolution bandwidth and provide a result as a density in power/Hz units.
Because of that scaling compensation, the Welch method is not appropriate for computing the power of individual tones, or any signal that has an occupied bandwidth that is less than the resolution bandwidth of the measurement (as set by the window used and number of points in the FFT block).
I detail further how the Welch Method compares to a direct FFT spectrum in DSP.SE #79255 and the preferred accuracy of the FFT spectrum for the processing of single tones in DSP.SE #87723.
np.real(len(…))
? a length of a vector is always already a real number (an integer, to be specific, both in the mathematical as well as in the Python sense). $\endgroup$