Sometime you want to know the RMS of only some port of your signal or some part of your power spectral density.
In that case what you may is to start from the highest frequency bin, and add the power in each bin as you go. T his quantity is then the cumulative RMS of the spectrum. At each frequency point, f, the cumulative RMS is the RMS of the signal from the highest frequency to f.
def myrms(f, y_of_f):
df = np.diff(f)
df = np.append(df[0],df)
#print(y_of_f.shape)
y = df * (y_of_f)**2 #normalize the PSD
y = np.cumsum(np.flipud(y)) # integrate the PSD from high frequency down to low freq to get the mean-squared
rms = np.flipud(np.sqrt(y)) # flip it back to plot the RMS
return rms.flatten()